Displaying ADC result with Atmega32

Thread Starter

botthe.

Joined Feb 7, 2013
7
I have interfaced my accelerometer, ADXL335 with my microcontroller. I am not able to determine what ADC output my microcontroller is giving corresponding to the accelerometer input, that is, I am not able to determine the result of the ADC register. How do I determine this?
 

t06afre

Joined May 11, 2009
5,934
You have read the datasheet found here http://www.atmel.com/Images/doc2503.pdf The data sheet is your best friend in such cases.
To solve your problem read the analog to digital converter section section. Note the formula on page 213. If we assume you are using the internal 2.56V reference and single ended conversion. If the ADC register holds the value 783. The input voltage will be equal to ADC*(Vref/(2^n))
Where n is equal to number of bits. Your ADC has ten bits, so the denominator in the latter equation is equal to 1024
 

THE_RB

Joined Feb 11, 2008
5,438
One good technique is to get the microcontroller to display the ADC value on a display etc. This is one of the first things I do when using ADC inputs on a project. It quickly rules out hardware issues and ADC pin setup issues.

If you don't have a display you can send an 8bit ADC value out the serial port as a byte, and display that on hyperterminal on your PC.

Otherwise if you just have a LED you can make the LED light up when the ADC value is greater than X. This is not as good for testing but can still show some idea of your ADC value if you don't mind reprogramming with a few different values of X.
 

Thread Starter

botthe.

Joined Feb 7, 2013
7
For the hyperterminal, how do I convert the data of the register in hex form so that it can be transmitted to a PC? I mean, is there any code available for the conversion?
 

t06afre

Joined May 11, 2009
5,934

spinnaker

Joined Oct 29, 2009
7,830
You also can view the raw value with your debugger. I would assume there is a debugger for the ADXL335?

Then once you see the raw value you can convert with your calculator as per the datasheet. Once you confirm that you are viewing what you expect and how to convert the value you can move on to convert it in your code.
 

THE_RB

Joined Feb 11, 2008
5,438
I often just send the data as a single byte, sending once a second or so.

Then the terminal program can display it as a decimal numeric value.

So if the ADC is reading about 1.23v the terminal shows the incoming bytes;
123
124
123
123 etc. No need to format data into ascii.
 

Thread Starter

botthe.

Joined Feb 7, 2013
7
There is no debugger for the accelerometer. I know what voltage value its giving out as I measured it using the multimeter but I don't know what is the corresponding ADC value.
 

Thread Starter

botthe.

Joined Feb 7, 2013
7
There is no difference in result of the ADC register if I connect or don't connect my accelerometer to the microcontroller. What might be the issue?
 

MrChips

Joined Oct 2, 2009
30,806
Before connecting the accelerometer you ought to connect an adjustable voltage source to the ADC input and observe the readings. A simple way to do this is to use a potentiometer connected between the minimum and maximum input voltages of the ADC, usually between GND and Vcc or Vref. Connect the center arm to the ADC input. A 10kΩ 10-turn pot will do the trick.
 

Thread Starter

botthe.

Joined Feb 7, 2013
7
Thanks guys. I got the transmitting issue resolved. It was a grounding problem. But I had transmitted the ADCH register of my Atmega32A microcontroller by left-adjusting the result. That is, the result was only 8 bits. Now, I want to transmit the entire 10-bit result. The transmission and the ADC conversion are working fine. This is a case of programming. Any suggestions?
 
Top