[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] buggy variable naming with underscores

From: Jamie Morken
Subject: RE: [avr-gcc-list] buggy variable naming with underscores
Date: Tue, 15 Mar 2005 09:54:19 -0800


----- Original Message -----
From: Dave Hansen <address@hidden>
Date: Tuesday, March 15, 2005 8:41 am
Subject: Re: RE: RE: [avr-gcc-list] buggy variable naming with underscores

> You've selected an auto trigger mode for the ADC, but have 
> modified SFIOR, 
> so you're in free-running mode (I'm looking at a mega16 datasheet, 
> but they 
> should be similar).  Thus, by the time your ADC ISR runs, the next 
> conversion has already started.  Your updated MUX value won't take 
> effect 
> until that conversion is complete.  So you've shifted the values 
> yourself.

Thank you very much for your help!

> Simplest solution would be to disable free-running mode (ADCSRA = 
> 0xCF), and 
> start each conversion in the ISR _after_ you've written the mux 
> (ADMUX = 
> nNextAdc; ADCSRA |= _BV(ADSC);).  This will slow you down 
> slightly, but not 
> much.

Ok, that works fine now!

> If you just gotta gotta gotta have free-running mode, keep two 
> channel 
> variables, current and next.  In your ADC init routine, set 
> current and the 
> mux to zero, start the conversion, then set next and the mux to 1. 
> In your 
> ISR, save the result in array[current], set current to next, 
> increment next 
> modulo 8, and set the mux to next.

This code worked properly for free running mode,
I just added +1 to ADMUX:


SIGNAL(SIG_ADC)         //free running mode, 13clks/conversion
        u08 lt; 
        u08 ht; 
        lt = ADCL; 
        ht = ADCH & 0x03; 


        if (nNextAdc==8) nNextAdc=0; 

        if(nNextAdc == 7)
                ADMUX = 0;
                ADMUX = nNextAdc+1;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]