| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| brood 
 
 
 Joined: 23 Jan 2007
 Posts: 12
 
 
 
			    
 
 | 
			
				| 6-bit resolution from a 10-bit ADC |  
				|  Posted: Mon Sep 24, 2007 9:02 am |   |  
				| 
 |  
				| Hi, 
 What would be the best way to go about obtaining a 6-bit resolution from a 10-bit adc? Would bit shifting be the best? and if so how would i go about it?
 
 My code is as follows at the moment reading the ADC:
 
 
  	  | Code: |  	  | 
 int red_duty;
 
 set_adc_channel(5);    // sets adc channel 5
 red_duty = read_adc();   //reads adc and sets red dutycycle
 delay_us(10);
 
 
 | 
 
 Thank you in advance
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Mon Sep 24, 2007 9:11 am |   |  
				| 
 |  
				| If you use 'ADC=8' in the device setup, you will only be dealing with an 8bit value. Reduces the work both in reading the ADC, and converting the value. In fact as shown, your code would not work, since with a 10bit ADC value, you would need a 16bit value to hold it.
 With the 8bit value: simply:
 
  	  | Code: |  	  | int red_duty;
 
 set_adc_channel(5);    // sets adc channel 5
 red_duty = (read_adc())<<2;   //reads adc and sets red dutycycle
 delay_us(10);
 
 | 
 The other alternative, is if you need to linearse, or apply a 'ihting' to the value, then a 256 element look up table (using the 8bit value) is fast, and simple.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| brood 
 
 
 Joined: 23 Jan 2007
 Posts: 12
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Sep 24, 2007 9:17 am |   |  
				| 
 |  
				| Thank you very much  that solved it |  | 
	
		|  | 
	
		|  |