Bug in sleep.h for ATtiny2313

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

I would like someone to check that I have found what I think I have found, an avr-gcc bug.

I have had a problem with a remote-control based on an ATtiny2313 that 'eats' batteries, although the micro should be in powerdown sleep mode.
It seems there is a bug in the AVR compilers code. It returns incorrect values for SLEEP_MODE_PWR_DOWN and SLEEP_MODE_STANDBY for the ATtiny2313. I have tried the code with the ‘wrong’ option and it immediately reduced current from 90+uA to around 15 (hard to say, it’s the meters lowest digit and there is a noise figure too).

Here’s the code excerpts from the WinAVR library header (I added the // comments) :-
...
if !defined(SM) && defined(SM0) && defined(SM1) && !defined(SM2)
#define _SLEEP_TYPE 2
#define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1))
...
#if _SLEEP_TYPE == 2
...
#define SLEEP_MODE_PWR_DOWN _BV(SM1) // 1 0
#if defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny26__)
/* tiny2313 and tiny26 have standby rather than powersave */
# define SLEEP_MODE_STANDBY (_BV(SM0) | _BV(SM1)) // 1 1
...

And here’s a bit of the manual, where it shows that 10 is Standby and 11 is Powerdown –

Table 13. Sleep Mode Select
SM1 SM0 Sleep Mode
0 0 Idle
0 1 Power-down
1 1 Power-down
1 0 Standby

As I said, using the 'SLEEP_MODE_STANDBY' option greatly reduces power consumption, so I'm pretty sure is broken.

Thanks, Paul

I have coded for about 2 dozen architectures, and they all have their place.
Don't get too religious about them (but AVR is excellent!)

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

> I have found, an avr-gcc bug.

Rather an avr-libc one if it turns out to be true.

Weird. You are looking at an older version of the datasheet, the
current version looks like:

Table 13. Sleep Mode Select
    SM1          SM0       Sleep Mode
      0           0        Idle
      0           1        Power-down
      1           0        Power-down
      1           1        Standby

The interesting thing here is... When I've been cleaning up
about a year ago, I noticed the ATtiny2313 datasheet has
been inconsistent in their sleep mode bits with all other AVRs,
including its brethren ATtiny13 and ATtiny26. I thus assumed this was
a typo (also triggered by the table being mis-ordered with respect to
the numerical order of SM0/SM1), and asked Atmel Norway about my
suspicion. They eventually confirmed, and as you can see, the current
datasheet is fixed (so it matches my assumptions once made).

You can see that in the datasheet changelog of the current revision:

Changes from Rev.
2514H-02/05 to Rev.
2514I-04/06

...
6. Updated "Power Management and Sleep Modes" on page 33

Now it's probably time to try that myself. Sigh, measuring sleep
currents is virtually impossible inside an STK500 (there are too many
bypasses consuming power from the Vtarget line), so I have to setup a
different board for it.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

It would be real nice if the Atmel boys could add a version letter or something to the manual filename.
I looked at the current manual on the atmel site - http://www.atmel.com/dyn/resourc... - saw it still said 'Preliminary' on the front page and assumed it was still the same old document. When do you think it might actually be considered a released product? So, I have now downloaded the surreptitiously updated version.

Anyway, now I'm confused too since in this case maybe two wrongs should make a right, but I can't argue with the actual microamps reading. Fortunately I have a programming jig with an ISP header, Chip socket and a pair of terminals for power and ground so I can test changes relatively easily. It actually has a 68 Ohm resistor in the +5V lead and a 4.7V zener across the chip to protect it from me mis-connecting it so that is probably the source of the remaining 15uA. The micro should be well below that.

When these remotes were using 3 Volts, the load on AA cells was not really noticeable but now the design uses 9 Volts for more range, the transistor battery is less capable of supporting the small but steady drain. 'Lucky' I discovered the problem, I suppose :(

I have coded for about 2 dozen architectures, and they all have their place.
Don't get too religious about them (but AVR is excellent!)

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

> When do you think it might actually be considered a released product?

I think there's only two attributes they apply to datasheets: "preliminary"
and "mature"...

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

The new 'I' revision of the manual with the table 13 as you indicated still says that for SM1/SM0, Power-Down is 0/1 or 1/1 and Standby is 1/0 in the individual paragraphs.
I'm wondering if they took your word for it that the table was wrong and didn't check the actual details.
I'd cut and paste the relevant sentences but they've 'improved' the new PDF so you can't paste useful hard to remember bits in your source-files for future handy reference :(

I have coded for about 2 dozen architectures, and they all have their place.
Don't get too religious about them (but AVR is excellent!)

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

Yes, I can see the text didn't change, only the table.

> I'm wondering if they took your word for it that the
> table was wrong and didn't check the actual details.

Who knows... :) You might open a trouble ticket with them
yourself.

> ... PDF so you can't paste ...

That's been discussed at length in the general AVR forum. Seems their
lawyers want to demonstrate they are important, so they explicitly
demand all published documents being copy protected.

The outcome of that thread was you need a PDF viewer other than the
Adobe one that doesn't care about the copy protection.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

I can confirm your observation: the I revision of the datasheet
was wrong. SM0 alone, or SM0|SM1 select power-down mode, SM1
alone selects standby mode.

I flashed a minimal application that was just entering sleep
mode, nothing else. Idle mode current consumption (at 1 MHz
and 5 V) was 200 µA, standby mode 40 µA, power-down mode << 1 µA
(the last digit of my current meter, probably around 200 nA).

I fixed that in avr-libc, and also reported it back to Atmel.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.