Analysis of a RGB LED string and recreating its functionality
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
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 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.
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.
As a first test, I connected an additional power line to VCC of the ATtiny10 to ensure that the software works.
This is a simple approach how to emulate the behavior of the LEDs with a microcontroller.
Data is sent by pulling VLED to GND for a few µs. While VLED is at GND, the diode is in revese direction and the remaining charge from the capacitor will power the microcontroller. The capacitor is recharged after VLED is pulled to positive voltage again.
The Sense input on PB0 can directly sense the signal from VLED. In case there are concerns because of V(PB)>VCC, another diode may be inserted. But the voltage differential is only ~0.6V, which should still be acceptable.
The LED is driven by PB2. When VLED is pulled to GND it will turn off. A resistor for current limiting should be added as well.
If you are very adventerous, you could also omit the diode. In that case, the MCU will be powered by the ESD diode on PB0, which should also charge the capacitor via the VCC pin.
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More