External Vref of ATmega8

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

Please let me know that how to set and enable external

Vref for ADC(AREF) and how to compare external and

internal values.

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

Why do you want to use an external reference?
Why not just use AVCC or the internal 2.56v ref?

jc

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

Doesn't your datasheet have a section in the ADC chapter on ADMUX, with "• Bit 7:6 – REFS1:0: Reference Selection Bits" and a table?

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.

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

I want to compare Vref to input to ADC channel voltage

then how to program this.

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

jccordill wrote:
Why do you want to use an external reference?
Why not just use AVCC or the internal 2.56v ref?

jc

Designer knows that the external Vref is necessary for embedded projects.

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

Quote:
I want to compare Vref to input to ADC channel voltage

Yes, that is what the ADC does, but you have not said why you want to use an external vref, why not use vcc or the internal 2.56v ref?

JC

Take a look at all the ADC example programs, each will have a line setting ADMUX, two of the bits in the ADMUX register defines what reference voltage will be used by the ADC, set the bits to use external ref if that is what you want and connect the AREF pin to your external reference.

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

Because I need selectable reference.
I am making over-voltage protector device.

For example: If reference voltage 1V and ADC channel
voltage 0.5V then no action but when the
ADC channel voltage reaches 1V the bit
PD0-PD7 any should toggle.

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

Quote:

For example: If reference voltage 1V and ADC channel
voltage 0.5V then no action but when the
ADC channel voltage reaches 1V the bit
PD0-PD7 any should toggle.


Have you read the datasheet? What does it say about the voltage range of Vref?
"VREF Reference Voltage 2.0-AVCC V"

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.

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

I built this one but bit PB0 continuously on????

#include 
#include 

int main(void)
{
    

    DDRB  = 0x07;                      // Setup PB0, PB1 and PB2 as output
   
    
    ADMUX |= (1<<MUX2); 
	ADMUX &= ~((1<<REFS0)|(1<<REFS1));


	ADCSRA |= (1<<ADEN)|(1<<ADPS2)    // Enable ADC, set prescaler to 16
             |(1<<ADIE);              // Fadc=Fcpu/prescaler=1000000/16=62.5kHz
                                      // Fadc should be between 50kHz and 200kHz
                                      // Enable ADC conversion complete interrupt

    sei();                            // Set the I-bit in SREG

    ADCSRA |= (1<<ADSC);              // Start the first conversion
     
    while(1);

}


// Interrupt subroutine for ADC conversion complete interrupt
ISR(ADC_vect)	
{
                  
      	              
        PORTB |= 0x01;            // If larger, set PB0
               
        ADCSRA |= (1<<ADSC);          // Start the next conversion

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

Setting AREF to use VCC or internal 2.56v will easily be able to measure your 1v dc signal, no need to switch references.

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

Quote:

PORTB |= 0x01; // If larger, set PB0

What do you mean--"if larger"? PB0 will be turned on at every conversion complete. (And never turned off.)

Have you done any ADC work before? Have you looked at the Tutorials forum articles with ADC in the title?

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.

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

jccordill wrote:
Setting AREF to use VCC or internal 2.56v will easily be able to measure your 1v dc signal, no need to switch references.

I cannot set fixed because my design needs selectable reference.

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

Look at the block diagram of the ADC in the Mega8 spec sheet.

AREF is the one and only reference input to the ADC. You CANNOT use the internal reference if there is an external reference connected to AREF.

The common way to do this is to connect an external reference to one of the ADC inputs and read it with the ADC. Then, if you do your maths correctly, all other readings can be expressed as a ratio to the external reference.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Ok.

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

So what should I do for fulfill my purpose.

If voltage increase 5V then PB0 should be on and if voltage decrease 5V the PB0 should be off.And if set Vref to 3V then PB0 should work according to Vref.

How it is possible,can it by Analog Comparator?

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

If you make an equal resistor voltage divider from Vcc to ground, and connect the center of the divider to one of the comparator inputs and your test signal to the other comparator input, then you can test whether the voltage is above or below 2.5V.

But, you CANNOT use this to detect if AVCC is too low (just thinking that might be your goal).

Are you testing the AVCC of the MCU or are you testing some other voltage?

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

ka7ehk wrote:
If you make an equal resistor voltage divider from Vcc to ground, and connect the center of the divider to one of the comparator inputs and your test signal to the other comparator input, then you can test whether the voltage is above or below 2.5V.

But, you CANNOT use this to detect if AVCC is too low (just thinking that might be your goal).

Are you testing the AVCC of the MCU or are you testing some other voltage?

Jim

Dear ka7ehk,

I am not concern with AVCC because AVCC is only supply of ADC.Please go through scenario below.

If you have over-voltage protector relay connected to your refrigerator and you set its range to let say 230VAC,when voltage reaches 230VAC its operate and trip your refrigerator.Now you are go to increase its range by Variable Resistor to 245VAC because your refrigerator can sustain 245VAC.Now when voltage reaches 245VAC your refrigerator go to trip.

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

This is a very different matter.

First, I want to really caution you about connecting anything directly to the power line. Here is what I recommend.

1) Start with a transformer. It can be very small, like the "wall wart" kind. Choose one that steps 230VAC down to maybe 10-15VAC. the output voltage is somewhat arbitrary. The transformer provides TWO functions - line isolation and linear voltage step-down. That is,if the output is 10V when the input is 230V, the output will be 10.6V when the input is 245V. All voltages are RMS, of course.

2) Rectify the transformer output. With low current load, you can make the rectifier pretty good with ordinary diodes. The output voltage will be about 0.6V less than the PEAK transformer output. Peak is Vrms * 1.414 for sine.

3. Make a voltage divider to reduce the voltage to the level that your comparator can sense.

4. Use the MCU to control the relay. Alternatively, use the ADC to measure the divided rectifier output. Make the decision (to manage the relay) in software. In either case, the process is quite simple.

5. Be aware of the effect of relay current on the operation of the MCU and the ADC. This will depend on exactly HOW you construct the circuit.

I should add that there is absolutely NO reason to mess with the reference voltage in either scenario. You can use the internal one, just fine.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Thank you for description.

Your 1st point ans:I am using transformer step-down.

Your 2st point ans:Rectifier used.

Your 3st point ans:Voltage divider used for comparator

Your 4st point ans:How to use both comparator and ADC
combined.

Your 5st point ans:Flywheel diode used for relay or
recommended circuitry.