Home | Store | Showcase | Forums | Examples | Guides | Reviews | Support | Download | About Us

 

 

 

Using ADC to Read a Pot
Reading the value of a Pot connected to a Mega8 is very simple.  This sample circuit uses a DevBoard-M8 which has a Mega8L MCU running at 8mhz internal oscillator.  

AVCC is already connected to +5v through the board and AREF needs to be connected to +5v. You can easily use a jumper to connect AVCC and AREF.  

This is a very basic way of setting the reference for ADC.  For more precision and noise immunity, refer to the Mega8 datasheet for a detailed explanation.

Simple Circuit for Reading a Pot

Sample Code

'Example of reading a Pot using a Mega8L mcu
'Refer to http://www.wrighthobbies.net/examples/readingpot.htm for more information

Config Adc = Single , Prescaler = Auto              'Configure the ADC subsystem
Start Adc                                                            'Fire up the ADC
Dim Pot As Word , Channel As Byte   
                'Define Variables

Channel = 0                                                        'Set the channel we will sample
Do
    Pot = Getadc(channel)                                    'Poll the ADC channel and assign the value to Pot
    Print "ADC (" ; Channel ; ") = " ; Pot                'Print the value, Print sends the data to the serial port
    Wait 1                                                              'Wait one second
Loop
End

 

The pot value ranged from 18 to about 1011 as you can see in the output window.