NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » tempsensor project

June 03, 2010
by kgb
kgb's Avatar

In the tempsensor project, inside the reading the ADC register "ADCL" and "ADCH" when ADLAR=0. Shouldn't we shift "ADCH" 6 bits to the left, and not 8 bits to the left, before adding it to "ADCL"? Thank You,,, KGB

June 03, 2010
by kgb
kgb's Avatar

By the way, you can look at page 257 from the datasheet online.

June 04, 2010
by bretm
bretm's Avatar

8 bits is correct. ADCL is an 8-bit register and all 8 bits are significant. You need to shift the bits of ADCH to the left to put them after the bits of ADCL.

0 0 0 0 0 0 0 0 x x x x x x x x  ADCL
0 0 0 0 0 0 0 0 0 0 0 0 0 0 y y  ADCH unshifted
0 0 0 0 0 0 y y 0 0 0 0 0 0 0 0  ADCH shifted 8 bits
0 0 0 0 0 0 y y x x x x x x x x  ADC total, which is what you want
0 0 0 0 0 0 0 0 z z x x x x x x  where z=x+y, what you'd get if you only shifted 6
June 05, 2010
by kgb
kgb's Avatar

I see. I understand that we need the two MSBs (8 and 9). But ADCH is an 8 bit register. So, if we shifted it by more than 7 to the left we will get a value of zero. isn't this correct?

June 06, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi kgb,

You're right that if it was simply shifting inside an 8-bit register, you'd end up with nothing left after shifting by 8 bits or more.

However, the C compiler is interpreting the code to mean that you want to first copy that 8-bit value into a 16-bit region of memory to work on (starting with zeros in the upper byte), and then do the shift within that 16-bit field.

Excellent question, and in fact it's one thing that it's easy to confuse the compiler about, which is why sometimes it's useful to explicitly copy things to a uint16_t variable and/or explicitly cast them before doing many operations.


June 09, 2010
by Steve35897
Steve35897's Avatar

The contains code for the uart that says it is for later use. So where is that section? I want to be able to read the temperature output from the computer. The NerdKits guide seemed to indicate that there was a section in the tutorials. But the tutorial I found about printf and scanf seemed to be what they were talking about and it was about the subject but didn't directly tell you how to setup the computer for the transfer. I thought I read something before about hyper terminal, but when I found and clicked on the hyper terminal icon it was asking for phone numbers making it sound like some sort of dial up connection.

June 09, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Steve35897,

Communicating over the serial port to the computer is covered in our Servo Squirter tutorial. Down in the Serial Port communications. I suggest you use Putty, I find it much easier to use than Hyperterminal; although we do have directions on how to setup Hyperterminal too.


June 10, 2010
by Ralphxyz
Ralphxyz's Avatar

Word of warning about using Putty with Windows 7.

I tried using Putty and got the blue screen of death with Windows 7.

My Windows 7 computer was never the same since, it has now died a unrelated death.

I have no idea what happened with Putty so all I can say is be careful and follow the instructions exactly.

There probable was something I did to cause the problem or possible Putty is incompatible with a x64 multi core processor.


Post a Reply

Please log in to post a reply.

Did you know that inductors try to keep their current constant over short periods of time? Learn more...