I want to use three ADC channels on Atmega32 (ADC0,ADC1,ADC2) these three channels will receive variable inputs and depending upon the conditions will output a 1 on PB0 lighting a LED(in actual conditions a relay will be there.)
assuming 10 bit accuracy ( 5V =1024 adc counts) follwing are the conditions I am unable to understand how to write code.
1) A>4V(811) & B>4.6V(947) & C=4V(819) then PB0=1
2) A>4V(811) & B<4.6V(947) & C=4V(819) then PB0=1
3) A<4V(811) & B>4.6V(947) & C=4V(819) then PB0=0
4) A>4V(811) & B>4.6V(947) & C=0(0) then PB0=0
5) A>4V(811) & B>4.9V(1005) & C=4V(819) then PB0=0
If none of the above conditions are true then PB0=1
So far I have written the following code, please guide and correct me
assuming 10 bit accuracy ( 5V =1024 adc counts) follwing are the conditions I am unable to understand how to write code.
1) A>4V(811) & B>4.6V(947) & C=4V(819) then PB0=1
2) A>4V(811) & B<4.6V(947) & C=4V(819) then PB0=1
3) A<4V(811) & B>4.6V(947) & C=4V(819) then PB0=0
4) A>4V(811) & B>4.6V(947) & C=0(0) then PB0=0
5) A>4V(811) & B>4.9V(1005) & C=4V(819) then PB0=0
If none of the above conditions are true then PB0=1
So far I have written the following code, please guide and correct me
Rich (BB code):
#include <avr/interrupt.h>
#include <util/delay.h>
int main(void)
{
DDRB |= (1 << 0); //Data direction Register portB PB0 output LED To this pin
ADCSRA |= (1 << ADPS2); // sETTING cLOCK PRESCALER TO 16
ADMUX |= (1 << REFS0); // AREF VOLTAGE IS SET TO VCC
ADCSRA |= (1<< ADEN); // ENABLE ADC
ADCSRA |= (1 << ADIE); //ENABLE ADC'S OWN ADC ISR
sei(); // GLOBAL INTERRUPTS ENABLE
ADCSRA |= (1<<ADSC); // START A2D CONVERSION
while(1) // Loop Forever
{
}
}
ISR(ADC_vect)
{
//WHAT CODE SHOULD BE WRITTEN HERE CAN i USE SWITCH STATEMENT HERE, IF YES THEN HOW TO WRITE CODE ,SATISFYING MY CONDITIONS
}
Last edited by a moderator: