Society of Robots - Robot Forum
Software => Software => Topic started by: galannthegreat on January 29, 2009, 07:22:37 PM
-
On this MCU the ADC port is 10bit, i want to work with 8bit values so do i have to set this in software, or is it 8bit from the start and then it has to be set to 10bit?
-
To work with 8 bits you simply make the ADC result "left align" and only read from the ADRESH register. I don't think there's a way to make the MCU actually convert only 8 bits, it allways converts 10 bits. The details are in the datasheet, there's an whole chapter on ADC operation.
-
thanks,
so simply said it would be easier to work with 10bit ADC vs the 8bit way
-
10bit ADC allows for finer detection anyway which is always good :) Why do you prefer the 8bit to the 10bit? Just curious
As cosmin suggested, try reading the datasheet. They contain some good info for ADC
-
I do prefer to work with 8bit numbers but like you said the best option, i guess, would be 10bit, like you said for the better precision.
I am also wondering how would i set up the clock configuration for a 20MHz HS crystal, should i use #use delay(20000000) ? or is there a #fuse setting that needs to be used?
-
Using only 8 bits out of the total 10 bits available makes sense for many application, it still gives you about 255 different "levels" and it directly maps to the MCU's data size (8 bit). Since the MCU itself can't operate on more then 8 bits / 1 byte at a time, every time you use in your C compiler something that's bigger then 8 bits (say an 16 bits "int" that can record the full 10 bit ADC result) the compiler will generate code to use two distinct bytes and will use discrete operations on the two distinct bytes: the result is that anything you do with that artificial 16 bits value will be 4 times slower (or more). In other words: stick with 8 bits unless absolutely required to switch.