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.

Atmega32 ADC problem

Status
Not open for further replies.

rahulshah

New Member
We are facing d problem with our ADC code. The code is used to switch ON the PORTC leds on detecting certain voltage level into channel 1 of ADC(PORTA), but when we run the program on hardware and test it, The LED glows when the analog input is switched off, rather than switch on. (It does not glow on switching on the ADC supply but glows when we switch off the supply)
Below is our code

#include "atmega32.h"

void set_adc()
{
ADMUX = 0x40;
ADCSRA = 0x82;
}

float get_value(unsigned int channel)
{
int a,b;
float fa;

ADMUX = channel;

ADCSRA |= 0x40; //start

while(!(ADCSRA & 0x10));
ADCSRA |= 0x10;

a = ADCL;
b = ADCH;
a = a | (b<<8);

//fa =(float) (a*5) /1023;
return a;

}
float get_value(unsigned int);
void main()
{
//unsigned int i;
int d;
DDRA = 0x00;
PORTA = 0x00;
PINA = 0x00;
DDRC = 0xff ;
PORTC = 0x00;
PINC = 0x00;


set_adc();

//PORTC = get_value();
//PINC = get_value();
d = get_value(1);
while (d<512);

PORTC = 0xFF;
PINC = 0x00;
DDRA = 0xff;
//PORTA = 0x00;
//PINA = 0x00;
//ADCSRA = 0x00;
//set_adc();
//d=get_value(2);
}


Thanks in advance
 
Please learn to use the
Code:
 tags so that your formatting is preserved. Also which compiler?
 
Some things I generally do not do:
I generally do not use floating point on 10-bit ADC values.
I don't usually try to write to PIN, the input ports.
 
hey hi... didi u solve ur problem.... ???

how to make t current value which s the output from a float switch.. which has 3 wires for 3 levels in a tank
to b connected to atmega32 board??.. please help meee.....
 
Status
Not open for further replies.

Latest threads

Back
Top