0

I designed what I thought should be a very simple badge using the Attiny85 SU, schematic below: Tiny with leds on each gpio pin

The problem is the tiny doesn't seem to be sinking current properly. For testing I switched to a 20 PU on the breadboard and 100 ohm load resistors. At 3v supply this should give approximately 30 mA per pin, well under the rated 40 mA per pin and 200 mA total. However with the loads connected only pin 6 sinks any significant current, and appears to be higher impedance than it should be (1.6v across the resistor for 16 mA). The other pins seem to be very high impedance, they drop to ~7 mV (70 microamps) when the loads are connected. With the load resistors disconnected they function normally (digitalWrite HIGH = supply voltage - junction drop).

I'm using pinMode [this was a problem] (OUTPUT, N) [/this was a problem, should be (N, OUTPUT)] to set up pin N, and digital writes for on/off. I've been able to drive transistors before using an exactly similar setup, although admittedly these have much lower current requirements.

Anybody know what's going on here?

EDIT: Turns out I had accidentally swapped the order of OUTPUT and N in the pin mode command. Not sure why the compiler had no problems with this, but I am at least getting useful outputs now.

I'm gonna leave this up out of curiosity/etc, because I'm still getting higher impedance than I'd have expected on the outputs. With the 100 ohm load resistor, I'm only getting about 16 mA (expect closer to 25). Supply voltage from the CR2032 is ~2.48v under load.

Based on the graph on the datasheet (figure 22-19, PG 182), at 25 c ambient (currently 20) I should expect a voltage drop from VCC to output somewhere on the lower end between 400 and 600 mV when supplying 15 mA, but my readings at 16 mA above represent a voltage drop of almost 900 mV across the Tiny. Additionally the LEDs drop 2v at 10 mA, for which you'd expect approximately 300 mV drop across the tiny according to the graph, but mine is dropping almost 500 mV. I'm not sure if this is something in my setup or if the characteristic curves on the datasheet simply aren't that accurate for production models.

  • Note that output pins on most AVR-based Arduinos are supposed to source/sink a max of 20mA, with an ABSOLUTE max of 40mA. 40mA the current level at which you are likely to burn out the output. For normal use you should stick to a 20mA/pin limit (and also watch the total current limit of 200mA as you mentioned.) – Duncan C Dec 5 '19 at 21:32
3

You already found your problem. I am answering only to provide some insight on why you were experiencing the symptoms you had.

pinMode() takes two integer arguments (two uint8_t to be precise). The names INPUT, OUTPUT and INPUT_PULLUP are just macros for 0, 1 and 2 respectively. This is why the compiler accepts your code with the arguments swapped.

On the AVR microcontrollers, setting a pin's output register to HIGH on a pin that is configured as input has the effect of turning on the internal pullup. Thus

digitalWrite(pin, HIGH);

has the same effect as

pinMode(pin, INPUT_PULLUP);

on an input pin. When you do this, the pin will source (not sink) a very small current. The pullup resistance is typically of the order of 30 kΩ, and this is why you get such a small current.

| improve this answer | |
  • Ok, that makes sense. I was wondering why it worked at all. Well reasoned as to why reversing the parameters created a high-impedance output. (Voted) – Duncan C Dec 5 '19 at 21:34
  • Awesome explanation, it also explains why PB1 (pin 6) was functioning normally since it would have been getting pinMode(1, 1) with the macro – user86728 Dec 5 '19 at 22:54
2

The answer to the main problem was that I had used pinMode(mode, number) where the actual syntax is pinMode(number, mode). Presumably modes can be selected by number and the compiler though I wanted to set an undefined pin to mode number.

TL;DR the correct syntax is pinMode(4, OUTPUT) to set PB4 (pin 3) to output.

The problem of higher than expected output impedance remains, though the outputs are now quite usable. As detailed in the edit, I'm still experiencing voltage drops across the microcontroller nearly 2x higher than I'd expect from the graph on the datasheet for a given current.

| improve this answer | |
  • Thanks for taking the time to post a self-answer after finding the cause of your problem. Not many people do that. (Voted) – Duncan C Dec 5 '19 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.