I am trying to make a digital voltmeter with atmega16. I wanted to use ADC differential mode that ADC0 pin works as positive input and ADC1 pin as negative input(ADMUX4:0=10000) and port D , portB.0 and portB.1 are used as 10 digits binary output.
referring to datasheet whenever difference between two input pins is between -5 and 5 volts it should give out a binary number from -511 to 512 (minus sign for showing that negative input is higher than positive one and is showed by making 10th digit one) but it doesn't work properly. when positive input is higher it gives out a binary number between 0 to 1023 (varies by changing the input voltages) and when negative input is lower it just shows zero.
I am using Proteus for simulating the circuit
here is my code:
#include <mega16.h> #include <Delay.h> interrupt [15] void assd(void) { PORTD = ADCW ; PORTB = (ADCW>>8) ; delay_ms (250) ; ADCSRA = 0b11001010 ; } void main() { PORTA = 0x00 ; DDRA = 0X00 ; PORTD = 0x00 ; DDRD =0xFF ; PORTB = 0X00 ; DDRB = 0xff ; ACSR = 0X80 ; ADMUX = 0b01010000 ; ADCSRA = 0b10001010 ; #asm ("sei") ADCSRA = 0b11001010 ; while (1) ; }
and this is my circuit diagram: