Displaying ADC result with Atmega32

Discussion in 'Embedded Systems and Microcontrollers' started by botthe., Dec 15, 2013.

  1. botthe.

    Thread Starter New Member

    Feb 7, 2013
    7
    0
    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?
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
    botthe. likes this.
  4. botthe.

    Thread Starter New Member

    Feb 7, 2013
    7
    0
    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?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You must convert the conversion result from hex to ASCII strings.
    https://www.google.com/search?q=ascii
    https://www.google.com/search?q=16+bit+hex+to+ascii
    It is a lot of code floating around on the net those who search will find, and the meek shall inherit the earth
     
    botthe. likes this.
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Google itoa()
     
    botthe. likes this.
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    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.
     
    botthe. likes this.
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
    botthe. likes this.
  9. botthe.

    Thread Starter New Member

    Feb 7, 2013
    7
    0
    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.
     
  10. botthe.

    Thread Starter New Member

    Feb 7, 2013
    7
    0
    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?
     
  11. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    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.
     
    botthe. likes this.
  12. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    It would also help if you show a schematic and tell us which Micro you are actually using! :)
     
    botthe. likes this.
  13. botthe.

    Thread Starter New Member

    Feb 7, 2013
    7
    0
    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?
     
Loading...