PDA

View Full Version : Discussion mega8 comparator puzzle


rich smith
Oct 23, 2008, 12:45 PM
I've written hundreds of AVR programs but apparently not as smart as I thought I was. IMO the comparator program below should change PD5 at 2.56v which is internal reference but instead it switches at 1.25v. Exactly half. I have never had trouble with ADC or comparator before but never actually checked comparator threshold voltage. Only 9 lines of code. Can anyone help? :confused:

-Rich

.include "m8def.inc" ;fuseh=c0 fusel=e4
ldi r23,0b00001000 ;ac mpx en
out SFIOR,r23 ;- - - ADHSM ACME PUD PSR2 PSR10
ldi r23,0b01000000 ;2.56v band gap en
out ACSR,r23 ;ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0
ldi r23,0b11000000 ;input=adc0=c0 ref=2.56v
out ADMUX,r23 ;REFS1 REFS0 ADLAR - MUX3 MUX2 MUX1 MUX0
l1: in r23,ACSR ;d5=aco
out PORTD,r23 ;pd5=led to gnd (pu=on=5v, no pu=off=0v)
rjmp l1

shoutchen
Oct 23, 2008, 10:16 PM
Rich,

according to the mega 8 data sheet (page 42 in the version i have)
, the bandgap reference is around 1.3 v, or half the ADC reference.


setting bit 6 of the acsr chooses the bandgap reference for the comparator input, not the adc reference...

hope this helps,

steveH

rich smith
Oct 23, 2008, 10:38 PM
Thank you Steve,

The datasheet I have is over 10yrs old and makes no mention of 1/2 vref for that bit. Only says comparator bandgap enable. Downloading new sheet now. Never noticed this even though I used comparator on many projects ( audio, modem, rf, etc.). Thanks again.

-Rich


Rich,

according to the mega 8 data sheet ) page 42 in the version i have)
, the bandgap reference is around 1.3 v, or half the ADC reference.


setting bit 6 of the acsr chhodrd the bandgap referecne for the input, not the adc refercne...

hope this hekps,

steveH

rich smith
Oct 23, 2008, 10:48 PM
I read the new sheet and see that table 16 lists reference as 1.3v and above that says ADC 2.56v is derived from it. My old docs did not make this clear. Thanks.