Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Atmel ADC Help

Status
Not open for further replies.

fatburger92

New Member
I need some help (newbie) starting a program that continuously displays a value sampled from the A/D input terminal through a UART in hexadecimal. How would I start my code (using C for Atmega644) ?
 
Thanks! That's really helpful. So, if I don't want to include high/low LED's and just want to continuously display the value, will this work? (without the UART Part)

#include <avr/io.h>

int main (void)
{

ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
ADMUX |= (1 << REFS0);
ADCSRA |= (1 << ADFR);
ADMUX |= (1 << ADLAR);
ADCSRA |= (1 << ADEN);
ADCSRA |= (1 << ADSC);

}
 
fatburger92 said:
Thanks! That's really helpful. So, if I don't want to include high/low LED's and just want to continuously display the value, will this work? (without the UART Part)

Not really. There are missing codes needed.

#include <avr/io.h>

You should also tell the compiler which ATMega chip you are using. e.g. #include "iom644.h"

ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

The above setting depends on the MCU clock speed you are using and is good for 16MHz only. If you use a lower frequency crystal or MCU's internal oscillator, then you have to make adjustment to keep the ADC clock within 50~200KHz by choosing suitable divisor ratio.

One common mistake is there is an exit on the MAIN program which it shouldn't. Add an infinite loop statement so that it is the last code statement in the Main.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top