# Simulation of sensor in proteus using Atmega16

I have trouble reading data from sensors using ATmega16 in Proteus. We use either light sensors for which I use LDR in proteus, or LM35 temperature sensor for temperature reading. The problem is, doesn't matter which sensor I use, I get an "[AVR AD CONVERTER] Reference value = 0 " error when I run the Proteus simulation and a big reading on the display, I think it's the max value.

The problem is somewhere in reading the value from the ADC channel, namely CH0 or PA0 in my case. At least I think it is.

Here is the code for the temperature sensor:

#define F_CPU 7372800UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include "lcd.h"

lcd_clrscr();

}

uint16_t temp = ((ADC * 5.0/1024) - 0.5) * 1000/10;

writeLCD(temp);
}

int main(void) {
DDRD = 0xff;

TCCR1A = _BV(COM1B1) | _BV(WGM10);
TCCR1B = _BV(WGM12) | _BV(CS11);
OCR1B = 64;

lcd_init(LCD_DISP_ON);

sei();

while (1) {

_delay_ms(1000);
}
}


... and the proteus scheme:

Light sensor code:

#define F_CPU 7372800UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "lcd.h"

lcd_clrscr();

}

int main(void)
{
DDRD = 0xff;

TCCR1A = _BV(COM1B1) | _BV(WGM10);
TCCR1B = _BV(WGM12) | _BV(CS11);
OCR1B = 64;

lcd_init(LCD_DISP_ON);

while (1) {

_delay_ms(100);
}
}


Scheme:

Am not sure if I should change the ADMUX register or maybe add an external capacitor ? Because when we use the sensor irl we add a capacitor between the AREF and ground pins. Any suggestions are appreciated, thank you in advance.

P.S. The codes are a bit different cause we used different triggering mechanisms for data conversion but that is irrelevant here. Same error for both codes.