The ADC (Analog to Digital Converter) converts an analog voltage between a range of voltages and provides an 8 to 10 bit number in proportion to the voltage sensed by the ADC.
In this video, the ADC automatically notifies of it's conversion complete using an interrupt. A potentiometer is used as a voltage divider to provide variable voltages to the ADC pin.
The LCD is used in this example to show the converted output from the ADC in a number from 0 to 255 (8-bit).
#include <avr/io.h>
#include <avr/interrupt.h>
#include "MrLCD.h"
int main(void)
{
InitializeMrLCD();
//Configure the ADC
ADCSRA |= 1 < <ADPS2;
ADMUX |= 1 < <ADLAR;
ADMUX |= 1 < <REFS0;
ADCSRA |= 1 < <ADIE;
ADCSRA |= 1 < <ADEN;
sei();
ADCSRA |= 1 < <ADSC;
while (1)
{
}
}
ISR(ADC_vect)
{
char adcResult[4]
itoa(ADCH, adcResult, 10);
GotoMrLCDsLocation(1, 1);
Send_A_String(adcResult);
ADCSRA |= 1 < <ADSC;
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.