CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

6-bit resolution from a 10-bit ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
brood



Joined: 23 Jan 2007
Posts: 12

View user's profile Send private message

6-bit resolution from a 10-bit ADC
PostPosted: Mon Sep 24, 2007 9:02 am     Reply with quote

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







PostPosted: Mon Sep 24, 2007 9:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 24, 2007 9:17 am     Reply with quote

Thank you very much Wink that solved it
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group