NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Understanding Registers
November 19, 2010 by Proton |
I have learnt to program in C. I have been able to connect USB to unit and write code to it. I have tested the provided tempsensor program with the kit. It works fine. I am now trying to learn and understand the program and the different parts of the MCU. Can someone explain what these registers do in simple terms, their purpose, what the individual bits in them do, and why we set them the way we do? Ex: How do we know to set bits in ADCSRA to 1? Why? ADMUX, ADCSRA, ADEN I understand that this is part of initializing the ADC, but I want some deeper knowledge, and the data sheet is too complex for me to understand. Regards, Proton |
---|---|
November 19, 2010 by bretm |
The datasheet is complex, but the sections describing the register bits are often the most straightforward. The ADC registers are a good example. Turn your data sheet to page 257 please. Section 23.8.2 has exactly what you need. ADCSRA is the ADC Control and Status Register A. ADEN is the ADC Enable bit. ADSC is the ADC Start Conversion bit. ADMUX is a different register described in the section just before that. It's the ADC Multiplexer Selection Register. See if those two or three pages make sense and ask again here if they don't. |
November 20, 2010 by Proton |
Thank you very much for your help. Any good link to explain how the ADC works? Pages 257 onwards were very helpful. Not exactly sure how I missed them =D |
November 20, 2010 by bretm |
The registers secrtion comes at the end of each chapter. The explanation of how the ADC works is earlier in the datasheet, on the preceding pages. Basically how it works is that it samples the input voltage for a few ticks of the ADC clock, charging a small internal capacitor to the same voltage. The for each of the next ten ticks it determines one bit of the digital result. It does this by setting each bit to 1 starting with the MSB, converting the binary value to a voltage using a DAC, and if this voltage is greater than the sample voltage the bit is cleared before moving on to the next bit. |
November 20, 2010 by Proton |
LM34 output is in mV and directly proportional to temp? attempting to understand, is this then provided as input to ADC, which converts it to binary 10-bit number? I understand each 10 mV change = 1 degree F as output from the temp sensor please explain why the +5V is divided by 1024 in sampleToFahrenheit(); |
November 20, 2010 by bretm |
A ten bit number ranges from 0 to 1023, or a total of 1024 increments. 0 corresponds to 0V and 1024 corresponds to AREF which in this case is 5V. So the input voltage is the ADC value times 5.0 and divided by 1024. |
November 21, 2010 by Proton |
thanks. that helps a lot. this site also helped a 13 year old understand ADC =D http://www.allaboutcircuits.com/vol_4/chpt_13/10.html another question is it possible to write the data from the ATmega168 tempsensor project to a file on the computer, instead of just being displayed on screen? If so, how is it done? |
November 21, 2010 by bretm |
That's a good article. A couple of points of clarification:
|
November 21, 2010 by bretm |
You can make it store the data on the computer. The program on the microcontroller already writes the temperature data to the serial port. You just need a program on the computer to read the values from the serial port and store them. You can do this manually by just saving the contents of the terminal window if you're using a terminal program. Otherwise you'll have to write a program for the computer. |
Please log in to post a reply.
Did you know that reading a double floating point variable with scanf requires "%lf" for "long float"? Learn more...
|