Using Arduino:
Three analog temperature Sensors are connected to channels 0, 1, and 2 of ATMEG328P. Write an AVR C program that continuously reads the temperature values from the three sensors connected to channels 0, 1 and 2 (ADC0, ADC1, ADC2). The program will turn on an LED connected to PORTD pin 3 if the values of the three sensors are not equal. Use the following ADC configuration.
Single-ended mode operation
. Select manual trigger mode.
Disable ADC interrupt.
Select AVCC as the reference voltage.
ADC result is right justified.
Select the ADC Prescaler 64.
Expert Answer
ANSWER:
GIVEN THAT:
int temp_sensor()
{
ADCSRAbits.ADEN=1; //ADC ENABLE
ADMUXbits.REFS1=0; //AVcc IS REFERENCE
ADMUXbits.REFS0=1;
ADMUXbits.ADLAR=0; //RIGHT JUSTIFIED
ADCSRAbits.ADATE=0; //MANUAL TRIGGER
ADCSRAbits.ADIE=0; //interrupt disabled
ADCSRAbits.ADPS2=1; //PRESCALAR 64
ADCSRAbits.ADPS1=1;
ADCSRAbits.ADPS0=0;
ADMUXbits.MUX0=0; //ADC0 CHANNEL
ADCSRAbits.ADSC=1; //START CONVERSION
#if (ADCSRAbits.ADIF ==1)
PORTB=ADCL; //storing value to port B data register
ADCSRAbits.ADSC=0; //STOP CONVERSION
#endif
ADMUXbits.MUX0=1; //ADC1 CHANNEL
ADCSRAbits.ADSC=1; //START CONVERSION
#if (ADCSRAbits.ADIF ==1)
PORTC=ADCL; //storing value to port C data register
ADCSRAbits.ADSC=0; //STOP CONVERSION
#endif
ADMUXbits.MUX2=1; //ADC2 CHANNEL
ADCSRAbits.ADSC=1; //START CONVERSION
#if (ADCSRAbits.ADIF ==1)
PORTD=ADCL; //storing value to port D data register
ADCSRAbits.ADSC=0; //STOP CONVERSION
#endif
#if(PORTB != PORT C && PORT C != PORT D && PORTD
!= PORT B)
PINDbits.PIND3=1;
#endif
return 0;
}
* only ADCL is used because result will be right justified and for precision not more than 8 bit ,ADCL register value is enough as a result for ADC conversion.
* if ADCSRAbits.ADIF is set it means ADC conversion is over. Thus, it is used as a parameter for checking conversion completion.
Using Arduino: Three analog temperature Sensors are connected to channels 0, 1, and 2 of ATMEG328P....
An Arduino Uno is configured with the voltage divider connected to Analog input pin AO as shown, and the code shown below is uploaded. What happens? testCodeA Arduino 1.8.11 Hourly Build 2019/10/29 11:12 Arduino Uno testCodeA #define LED 13 to sv 13o 5ke & void setup() { pinMode(LED, OUTPUT); to A 10KZ Ž ŞR void loop() { int voltage-analogRead(AO); if (voltage > 1024/2) digitalWrite(LED, HIGH); else digitalWrite(LED, LOW); GND GND Done compiling Sketch uses 778 bytes (2%) of program storage...
An Arduino Uno is configured with the voltage divider connected to Analog input pin AO as shown, and the code shown below is uploaded. What happens? testCodeA Arduino 1.8.11 Hourly Build 2019/10/29 11:12 Arduino testCodeA Uno #define LED 13 to SV 130 5ks § void setup() { pinMode(LED, OUTPUT); B toap ŹR 10 Kaş void loop 1 int voltage analogRead(AO); if (voltage > 1024/2) digitalWrite(LED, HIGH); else digitalWrite(LED, LOW); HOGNO Gong Done compiling Sketch uses 778 bytes (2%) of program...