> -----Original Message-----
> From: Bob Paddock [mailto:[email protected]] 
> Sent: Thursday, February 12, 2009 2:43 PM
> To: Weddington, Eric
> Cc: [email protected]
> Subject: Re: [avr-libc-dev] [RFC] Sleeping BOD API
> 
> Issues of inline assembly/macros et.al. aside, does this
> instruction sequence in fact work at all?
> 
> As I need to do this currently, before you patch is ready.  
> This is what
> I'm doing in my Tiny88 project:
> 
>   SMCR   = (_BV(SM1)|_BV(SE));     /* Sleep in Power-Down mode */
>   MCUCR |= (_BV(BODS)|_BV(BODSE)); /* Must set both bits to turn off
> the Brown Out Detector, */
>   //  MCUCR &= (uint8_t) ~_BV(BODSE);  /* while in Sleep, with this
> instruction sequence. */
>   MCUCR &= (uint8_t) ~_BV(BODS);  /* while in Sleep, with this
> instruction sequence. */
>   __interrupt_enable();
>   sleep_cpu();          /* Sleep must be done within three
> instructions of BODS */
> 
> If I do not turn the BOD fuse on, my circuit 'off' current does not
> even move my meter.
> With the BOD fuse enabled I measure 17 uA.
> 
> I've tried variations (BODS vs BODSE as above; lacking faith in the
> datasheet) that I could think of that would fall within what the
> datasheet says for timing, to get the current back down in sleep.  The
> current remains at 17 uA, with any variation, even the one that should
> exactly match the datasheet.
> 
> ?
> 
> The cycle timing for SEI is special, is there any consequence to that
> verses the BOD
> three cycle timing (hardware race)?


I've had confirmation that the sequence that I outlined in the new 
documentation does work, in the sense that it correctly disables the BOD while 
sleeping:

      set_sleep_mode(<mode>);
      cli();
      if (some_condition)
      {
        sleep_enable();
        sleep_bod_disable();
        sei();
        sleep_cpu();
        sleep_disable();
      }
      sei();


I'm concerned that because you're doing this in C, the compiler won't generate 
efficient enough code (especially with optimizations turned off) for it to work 
properly. Have you looked at the resulting assembly code?

Also, I don't understand why you are having to clear BODS before enabling 
interrupts? That should be unnecesary.

And, why are you using __interrupt_enable() instead of sei()? Are you trying to 
have this work under AVR GCC and IAR too?


_______________________________________________
AVR-libc-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to