Close

Nasty Hack: A Powerline Controlled LED with an ATtiny10

A project log for Powerline Controlled LED Strings

Analysis of a RGB LED string and recreating its functionality

timTim 01/30/2022 at 21:252 Comments

After outlining an idea how to implement powerline control with an ATtiny10 in the previous log, I did of course have to try it. Especially since a rather nasty hack is involved.

The Hardware

The objective is to create a two terminal device with an LED that receives both power and control information via a single line.

My test setup is shown above. The top is a breakout board with an ATMega328P and USB to serial converter (Sometime also known as "Arduino Nano Clone"). The bottom breadboard contains the target circuit with an ATtiny10, a capacitor, LED and series resistor.

Note that there are only two connections to the lower board: VLED (connected to PB0/D8 of the ATMega328) and GND.

The full circuit of the lower board is shown above. Notice the mistake? There is no connection to the power input pin VCC!

Well, of course this is the "Nasty Hack". The ATtiny10 has an internal diode connecting PB2 to VCC (shown in red). The purpose of this diode is to short ESD pulses to the power rail. It is also the reason why you are not supposed to apply voltages higher than VCC+0.5V to any input pin. Operating the MCU like this can have nasty side effects, and I am pretty certain that Atmel Microchip will not endorse it at all.

When VLED is larger than VCC plus the diode voltage, it will charge the parallel capacitor. When VLED is pulled low, the diode will be in reverse direction and the microcontroller can be supplied from the capacitor.

Apart from abusing PB2 to power the MCU, it will also be used to sense the logic level of VLED. PB1 is used as output to control the LED. Note that the LED is supplied from VLED and not the capacitor and hence will only light up when VLED is high.

The Software

To keep things simple we will limit the functionality to only turning the LED on and off. During normal operation, VLED will be "High", pulling it down for a short time shall toggle the LED.

/*
 * Attiny10 Powerline LED
 * Created: 30.01.2022 18:49:11
 * Author : tim
 */ 

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{    
    DDRB |= _BV(PB1);  // Set PB1 as output. LED is connected to PB1
    
    EICRA |= _BV(ISC00) | _BV(ISC01); // Activate INT0 on rising edge
    EIMSK |= _BV(INT0); // Enable INT0 in mask register
    
    sei();
        
    while (1) 
    {
    }
}

ISR(INT0_vect, ISR_NAKED)
{
    PINB |=_BV(PB1);    // Toggle LED on PB1
    reti();
}

The ATtiny10 firmware is shown above. I am using INT0 to detect a rising edge on PB2 (which INT0 is connected to) and call the interrupt handler. The interrupt handler uses the pin toggle function of the ATtiny10 to turn the LED on or off. Note that I did not change the clock setting at all, meaning that the ATtiny10 is clocked at its default 1 Mhz.

Firmware for ATMega328 (controller board on top):

// Generate pulses on PB0/ D8

#include <avr/io.h>
#include <util/delay.h>

void sendpulse(void);

int main(void) {
    DDRB |= _BV(PB0);
    
    while (1) 
    {
    sendpulse();
    _delay_ms(1);
    }
}

#define basetime_us 10
                                    
void sendpulse(void) {
        PORTB &= ~_BV(PB0);
        _delay_us(basetime_us);
        PORTB |= _BV(PB0);
        _delay_us(basetime_us);    
}

The ATMega328p firmware simply sends low pulses with a duration of 10µS to PB0, where VLED is connected.

Testing the Contraption

As a first test, I connected an additional power line to VCC of the ATtiny10 to ensure that the software works.

The yellow trace ("vsig") on top corresponds to VLED. We can see that it is mostly in Hi state with short low pulses. Every pulse toggles the state of the LED, as intended. The voltage at VCC is 4.6V - apparently there is some voltage drop in the ATMega328 board and/or the USB port that is used to power it.
Repeating the same experiment without the connection to VCC releals exactly the same behavior. The ATtiny10 is powered only by the parasitic supply through PB2 and the capacitor now. Yay, it works!

The voltage on VDD dropped to 3.8V now, corresponding to a ~0.8V voltage drop in the ESD circuit, the internal diode.


Zooming a bit further in, we can see that the voltage on VCC is dropping when VLED is low, because the MCU is only supplied from the capacitor. It is quickly recharged after VLED returns to high level. There is a short delay between the rising edge of VLED and toggling of the LED due to interrupt latency.

The voltage drop on the 100nF capacitor is around ~75mV for the entire 10µS pulse.

Since Ivcc = (C * DeltaV) / t we get 100 nF * 75 mV / 10 µS= Ivcc = 0.75 mA. This is reasonably close to the datasheet value for the current consumption of the ATtiny10, which is 0.6mA for 5V. It may be advisable to reduce the clock speed of the ATtiny10 further to minimize current draw from the capacitor.

If the control signal consists of pulse trains with equal High and Low timing, then the capactior should be recharged faster than it is discharged. Right now, recharging takes around 25µs, which is still too long.

Trying the same without external capacitor failed. We can see that VCC quickly drops down to approximately 1V, where the ATtiny 10 stops operation. Understandibly, the remaining parasitic capacitance in the micrcontroller is not able to supply a current of 0.75mA for very long. The MCU may be able to operate without external capacitor when reducing the current draw, by lowering clock speed, and reducing the maximum allowable pulse time to the minimum. The minimum pulse time still needs to be longer than one IO clock cycle, as otherwise the interrupt logic will not be able to latch the rising edge, though.

Conclusions

Seems that the Hack works and we can abuse an ATtiny10 as a powerline LED controller with minimal external components. This is obviously just a proof of concept. As a next step it would be of interest to implement a more elaborate communication protocol that allows connecting multiple devices.

Of course, we could also use an external Schottky-Diode, so we don't have to abuse the ESD device. The benefit would be that the MCU is stressed less and the capacitor is recharged faster. But where is the fun in that?

Discussions

Sam Ettinger wrote 01/31/2022 at 01:03 point

What a fun hack! Do you think the advantages outweigh the drawbacks, using the internal protection diode instead of an additional external component?

  Are you sure? yes | no

Tim wrote 01/31/2022 at 07:20 point

For some experiments it appears to work. But there could be some side effects on larger scale, like latch-up and ESD issues.

I also noticed that the power consumption of the MCU is still too high during the "low" periods, because it is not possible to recharge the capacitor in less than 10µs. Maybe the MCU should be put to idle state and the rising edge should wake it up. The timing is getting a bit critical, though.

Alternatively, an external diode should recarhge the capacitor quicker.

  Are you sure? yes | no