[En-Nut-Discussion] WinAVR-20080512 -- same error as 20080411

Ole Reinhardt ole.reinhardt at embedded-it.de
Wed May 21 00:02:58 CEST 2008


Little addendum:

> > Couldn't we just use avrlibc's sleep functions instead?
> 
> Shure :) Sometimes the solution is even more simple :)

We just use the set sleep_mode function. But what we would need is a
function re retreve the current sleep mode and restore it later after
the completed conversion. So we need to know the sleep mode. Indeed
that's not a problem, as we know our registers. And at least we could
simply substitude the _SLEEP_MODE_MASK constant by 

(~(_BV(SM0) | _BV(SM1) | _BV(SM2)))

The next three lines work around a bug in avrlibc < 1.2 triggered with
atcan128. If we define avrlibc < 1.2 as deprecated then we could modify
the function like this:


void ADCStartLowNoiseConversion()
{
    ADCSetMode(SINGLE_CONVERSION);

#if defined(__GNUC__) && defined(__AVR_ENHANCED__)
    {
        u_char old_sleep_mode = AVR_SLEEP_CTRL_REG & (~(_BV(SM0) |
_BV(SM1) | _BV(SM2)));
        set_sleep_mode(adc_sleep_mode);
	sleep_mode();
        set_sleep_mode(old_sleep_mode);
    }
#else
    sbi(ADCSR, ADSC);
#endif    
}

Regards,

Ole Reinhardt

-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT          Hard- und Softwarelösungen             |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|                      UstID / VAT:       DE198944716         |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list