Current with atmega640 - figured it out but interesting

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

I hadn't seen this before, but once I got a qfp-100 atmega640 on a giant DIP adapter from protoadvantage (they finally added pin numbering, woo hoo!), I noticed that the current it was using was quite a bit higher than expected.  The datasheet said at 1MHz it should be around 4-5mA, it was 35mA+.  At 14.7456MHz it was 47mA+.  Empty program.  What was even more odd is that if I had it unplugged from the Atmel ICE and touched the back plate of the breadboard with my hand, it would drop down to very little.  If I plugged the ICE back in, it wouldn't drop when I touched the back plate, or it would do this odd thing where it would drop for a second, then come back up, the not repeat it.  If I made a small program to just put it in sleep mode, it would drop to practically nothing.  It finally occurred to me that with all those ports A-L that that is a large number of pins that if set to HiZ with no pullup, might be right on the edge or low/high so I set all of them to pullup-enabled and this solved the problem entirely.  I've never noticed this with other AVR's before, but I thought it was interesting.  I'm sure they do it, but perhaps the different in current wasn't enough to get my attention.

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

'tis the golden rule of low power design - never let your inputs float.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

+++ Brian :)

I once read a story about a low power design with lot's of failures in the field because of flat batteries.

It turned out that a few (mostly off) LED's driven by uC pins were switched to input when the led's were off.

This shaved of a few uA of the power supply current.

It turned out that the led's generated a voltage when subjected to strong light, and it was enough to put those inputs in the lineair region where both the North and South Fet's were partially conducting.

(Take some leds from your parts bin. Some will generate quite some voltage under strong light, other's don't.)

Never let your inputs float.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

So guys, does this always applied even in situations where other devices will sometimes drive the pins and sometimes not.  I've got a couple of examples.

 

I'm going to have 4 devices sharing SPI.  MISO will be driven when any of their 4 SS lines are pulled down, but undriven otherwise.  Should I have the MISO in "input with pullup" instead of "input no pullup"?

 

Secondly, my current project with this is that the AVR is an I/O processor to a Z80 microprocessor.  Is it a problem to have pullups enabled on all the address and data lines?  Sometimes they are undriven when the Z80 is in BUSREQ mode, but most of the time they will be driven...

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

With a nmos Z80 in the circuit, i doubt you’re worried about current consumption! Yes, there should be a pullup on miso. It shouldn’t be a problem having pullups on the addr/data lines - was very common in the olden days to have these.

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

Actually it is a CMOS Z80.  Thanks!

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

If you look at input specifications for different logic families then you will almost always find an "undefined" region in which anything can happen.

With AVR's I have found quite different results.

Made a project once in which I configured all AVR pins as input (Yep, a valid AVR program with no output pins !!!) and tied all the inputs together and sweeped them from 0V to Vcc with a simple potmeter. Chips were all in the same DIP housing and on a breadboard. From the old atmega8a to the 328p. Results varied a lot but unfortunately I did not make much notes. I think the mega8 consumed between 20 and 30mA in the "undefined" region and with other (more modern?) chips the difference was very small, maybe 1 to 3mA or so. (For all the pins combined).

 

You can also use schmitt-triggers to overcome this issue, or just ignore it if those few mA are not important.

My advise is to try to always pay attention to such details. I would enable the pullup resistor in the master, and document in the code why I enabled the pullup resistor.

I try to write robust code.

Others write ad-hoc code and spend who knows how many hours on debugging if some of their circuits sometimes have intermittent errors half a year later.

 

Ask Bruno (If you dare, he grumbles and bites):

The Case of the Crashing 68000

http://www.ganssle.com/articles/ajake.htm

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

On busses like SPI, you should always have at least one pin that defines the state each line of the bus. You need to be really careful so that you don't have bus contention with one output pin low and one high. Sometimes you may just have to let it float for a few clock cycles - you may have no choice. But, usually that sort of condition occurs when the bus is under active management. If the SPI has one master, then MOSI must be controlled by the master. But, in the case of MISO, you may need a high value pull-up or pull-down to hold it in the correct idle state when none of the slaves is active.

 

I do the same sort of thing on FTD-232R transmit. There are several cases of concern. One is when the device with the FTDI chip has been powered up, the USB cable has been plugged in, but the chip has not been initialized. The spec sheet tells you nothing about the state of the chip's transmit pin. So, I add a pull-down just to make sure it stays in the state the UART thinks is "idle" IF the FTD chip is undefined. 

 

So, there are a whole variety of conditions you need to pay attention to for the lowest power consumption.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Note that for short periods of floating, pin and wiring capacitance should hold the voltage at a “safe” level.

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

I'm going to use 4 devices on the SPI:

 

HT1632C LED Driver - has a pullup on CS per datasheet.

SDCARD - Web searching says it has a pullup on CS.  Some people even use it for card detection.  Someone posted the spec that showed it having a pullup on CS as well.

M41T93 RTC- Datasheet doesn't say anything about a pullup on CS and I can't detect one.  Logic probe not pushed positive or negative, voltage near 0.

MCP23S17 I/O expander - Datasheet doesn't say anything about a pullup on CS and I can't detect one.  Logic probe not pushed positive or negative, voltage near 0.

 

Now, once the AVR starts, all SS/CS pins will be driven output high and only one used at a time.  I did notice that both the two that lack the CS pullup say that you have to have a high to low transition or toggle the CS to enable the device.  Given that, do you think a pullup is actually necessary for the two that don't have it?  Again, I will always be driving them high.  The only time they won't be is during programming, and it sounds like they need a high to low transition to enable it.  One shows you having to sent a read command to even enable the SDO for output instead of high impedance.  I know it is only two resistors, but why have a part if you don't really need it....

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

Reset time is where the pins float - so if there is a possibility of contention, then add external pullups. You'll be glad you did. Other things to watch are enables for RS485 transceivers - a pulldown is used to ensure they don't accidentally enable transmit on reset. Mosfets - pulldowns to ensure they don't turn on and make a relay or whatever click on powerup/reset.

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

I once got bitten by packet loss on my RS485 network whenever I pushed the reset button or sometimes during programming of an AVR.

After  learned the cause I always include the pulldown resistor on the enable line.

After that ll schematics get carefully combed through for any pins where this might be an issue.

Lesson learned smiley

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com