ADC in differential mode

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Give a few sets of numbers.  Tell the voltage at the PA0 and PA1 pins, and the resulting ADC counts.  Tell what you expect.

 

Didja ever think that perhaps Proteus doesn't know how to do differential properly?  Do you get identical results on the real chip?  Have you asked Proteus support?

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sat. Oct 3, 2015 - 04:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't help with the code, but a question or two about your setup, especially if you plan on doing this with real hardware:

 

Why did you tie ARef to Vcc?

It is generally safer to configure the ADC to use Vcc as the reference, rather than directly connect the ARef pin to Vcc.

If you mis-program the set up, and it is configured for Vref - 2.56 V, while being tied to the Vcc rail, it may well damage the chip.

When you build the real device, connect a cap from ARef to ground, (0.1 uF).

 

Why do you have 1 M ohm resistor dividers on your inputs?

If you have an AC coupled input signal, then the resistor divider would center the signal at Vcc/2.

But you are feeding in a DC voltage, not an AC, capacitively coupled signal.

 

One might, on occasion, tie external resistors to a pot input incase in the real world, with old fashioned wire wound pots, the wiper jumped around and the input was noisy.

That certainly isn't the case with a simulated pot, and really probably doesn't even apply to what you are doing, making a voltmeter.

 

For your real world design, assuming you actually make the circuit, you will also want to put a small cap from the ADC input to ground to filter the input signal a bit.

 

One of the nice features of the differential input is that it gives you optional internal gain, helpful for measuring very low amplitude signals.

If you aren't going to use this feature, then  for many simple voltmeters, the "negative" side of the differential input would just be tied to ground, so you might consider just using the single ended input mode.

 

JC