ATTiny85 IR Repeater: Infrared LED Driving Issue - Page 1
Forum section: electronics / projects

author: Schorsch
author_rank: Newbie
timestamp: January 25, 2022, 01:59:57 pm
content: HiI have to come out of lurk mode for once, because a small project that was supposed to take a few hours got somewhat out of hand and I would be delighted if someone could shed some light on my situation...The ProjectIt was supposed to be simple: A circuit that receives 38kHz modulated infrared commands from a remote control and relays them via another infrared LED, a repeater.Because I don't have a huge selection of parts available and I'm more at home with digital circuits than with analog ones, I decided to put an ATTiny85 at the core, the code for which I had already written in the past and allowing me to tune the signal timing in software.Current SchematcThe ProblemWhile building the circuit and testing the software, I was using a blue LED at the output (LED1) which ended up working very well.When replacing the blue LED with an IR LED though everything goes to hell, and so far I've been unable to explain why...Raw signal from remote control:MOSFET drive signal with blue LED in circuit (same with no LED):MOSFET drive signal with IR LED in circuit:Data, Tests and Troubleshooting AttemptsDuring testing my 5V source is a USB powered Arduino Leonardo board I use to program the ATTinyIR LED is rated for 100mA continuous at 1.35V (it is also brand new)To test a worst case scenario for the power supply, I ran the IR LED with R2 continuously (ILED1measured at roughly 80mA) microcontroller function remained uninhibited and switching signal looked good, no supply voltage dropCircuit behaves the same running on 5V as it does on 3.3V (R2 adjusted for higher voltage)Circuit behaves the same with an NPN BJT (BC337) as switching transistor (pull down resistor R1 removed, base resistor added)IR LED sometimes gets stuck on even when input IR signal gets removedI'm using a USB oscilloscope which during testing has a common ground with the DUT therefore I can't measure the voltage across the LED directly, however measurments with a simple IR photodiode confirm, that the IR LED is driven in accordance with the switching signalMicrocontroller Code, just in case...:Code:#include <Arduino.h>#include <avr/sleep.h>const int receiver = PB2;void sendpulse();// define values for 38kHz PWM frequency and 25% duty cycle// values determined by trial and error#define TOP 214#define DUTY 100void setup(){// setup pin change interruptGIMSK = 0b00100000; // turn on pin change interruptsPCMSK = (1 << PCINT2); // turn on interrupt on button pinsSREG |= 0b10000000; // enable global interrupts// disable unused peripherals and set sleep mode to save powerADCSRA = 0b00000000; // disable ADCACSR = 0b10000000; // disable analog comperatorPRR = 0b00000001; // shut down ADCset_sleep_mode(SLEEP_MODE_PWR_DOWN); // set sleep mode to power downsleep_enable();// set timer0 to toggle IR pin at 38 kHzTCCR0A = 0b00100011; // PWM on OC0B (PB1)TCCR0B = 0b00001001; // no prescalerOCR0A = TOP; // 38 kHz PWM frequencyOCR0B = DUTY;pinMode(receiver, INPUT_PULLUP);attachInterrupt(digitalPinToInterrupt(receiver), sendpulse, CHANGE);}void loop(){sleep_mode();delay(1);}void sendpulse(){DDRB |= (1 << DDB1); // PB1 as output = IR at OC0B (38 kHz)while(!(PINB & (1 << PINB2))); // keep sending as long as input signal is thereDDRB &= (0 << DDB1); // PB1 as input = LED offPORTB &= (0 << PORTB1); // Prevent IR LED getting stuck on (use questionable, but doesn't seem to hurt)}TL;DR:Blue LED: Circuit goodIR LED: (exact same) Cicuit bad...Why?Any and all information, tips and tricks greatly appreciated!Inb4 I missed something completely obvious...

author: Ian.M
author_rank: Super Contributor
timestamp: January 25, 2022, 02:26:53 pm
content: The difference is of course the pulsed load on the 3.3V regulator. The blue LED most likely has a Vf up around 3V so probably draws current pulses of the order of 10mA or so. OTOH the IR LED will draw pulses of over 100mA. As the LM1086 datasheet recommends an aluminum Electrolytic or Tantalum output capacitor to provide a minimum ESR for stability, I doubt its terribly happy with an undersized ceramic + being 'kicked' hard at a frequency two decades higher than the corner of its frequency response.The easy fix would be to feed the LED from +5V via a 39 ohm resistor, but I'd still advise plenty of local decoupling between the top end of the feed resistor and the MOSFET source to keep that pulsed current loop small and local.

author: Zero999
author_rank: Super Contributor
timestamp: January 25, 2022, 03:07:02 pm
content: If space and cost are not major concerns, use three IR LEDs in series, powered from 5V, to get triple the IR, for the same current.

author: Siwastaja
author_rank: Super Contributor
timestamp: January 25, 2022, 03:23:53 pm
content: Failure to follow the datasheet of the voltage regulator, most likely.In particular, use of ancient LDO with strict requirements about the output capacitor. Modern day LDO regulators provide actually low dropout, and are stable with zero ESR, so no need to use tantalums or explicit series resistors, but satisfying minimum capacitance is enough.But that regulator is usable with the correct type and amount of output capacitance, and the massive dropout of 1.5V is just barely OK for 5V to 3.3V application; so add a 10uF tantalum and see what happens. Failing to have a 10uF tantalum, put any random 100µF electrolytic cap and try your luck.

author: Peabody
author_rank: Super Contributor
timestamp: January 25, 2022, 03:43:04 pm
content: +1 on Zero999's suggestion. As is, you are dissipating 59% of your 3.3V power as heat in R2, plus what you're dropping as heat in the regulator. Why not convert that to IR power? The 5V supply, with a capacitor, is probably a more capable power source for the IR LED. So with three LEDs in series, you could get more IR output than now, using less input power. That's not even supposed to be possible this side of Dave's debunking videos. :-)

author: Siwastaja
author_rank: Super Contributor
timestamp: January 25, 2022, 03:52:26 pm
content: Optimizing the design for better efficiency is always a good idea, except that when you suggest doing that as a response to trying to find a problem, you give false impression that this suggestion has anything to do with the problem.Solve the problem first. Doing unrelated changes have the risk of hiding the problem again, like it happened with the blue LED. Following Zero999's advice likely "makes it works" again, but it's still not fixed. This is a recipe for marginal design which fails when you least expect it.

author: hexreader
author_rank: Frequent Contributor
timestamp: January 25, 2022, 04:01:46 pm
content: Is the receiver isolated (in space) from the transmitter?.... or is the transmitted signal interfering with the original IR signal?I seem to remember that commercial IR repeaters used to simply amplify the original signal without de-modulating, and thus with no significant delays.Your setup seems to de-modulate 38kHz original signal, then re-modulate and send. This causes a delay that in turn would cause interfering feedback, should the receiver see the re-tranmitted, delayed signals.If receiver is fully isolated from transmitter (perhaps in a different room), then none of the above applies

author: Schorsch
author_rank: Newbie
timestamp: January 25, 2022, 06:22:00 pm
content: Quote from: Ian.M on January 25, 2022, 02:26:53 pmI figured that might be the case, I was hung up on the 3.3V because I eventually wanted the thing to be battery powered. As for the regulator, I looked at the datasheet, but lacking any of the recommended capacitors I had to take my chances. During testing I however repeatedly bypassed it to no avail.FWIW for future testing I will probably stick to your recommendation of 39R and 5V.I also made a critical error in my original post where I mentioned the "IR LED gets stuck on", when in fact it kept pulsing, leading me to suspect the microcontroller has some part in the fault(s).In order to reduce the amount of "antennas" in my test setup I now rebuilt the circuit on a scrap bit of perf board and completely removed the regulator until further notice, instead powering the thing from my - semi decent - bench PSU; probably also something I should have done sooner.Quote from: Zero999 on January 25, 2022, 03:07:02 pmThanks for the suggestion! Though currently I'm more concerned with getting the circuit to run at allQuote from: Siwastaja on January 25, 2022, 03:23:53 pmNoted! I did what I could with the parts I had and hoped I could get away with it, as I figured the circuit is not particularly demanding... Though at this stage, I could have just gone out and get the proper components.Quote from: hexreader on January 25, 2022, 04:01:46 pmOh man, you sure know how to scare someone, I wish I could tell you I considered that. Luckily the parts were facing opposite directions and with my current "overhaul" I further isolated the parts.However there is definitely something funky going on that is infrared related:Ok, at this point I'm pretty serously spooked.More info:I'm using a TSSP4P38 to receive and demodulate my IR signal.My current test setup uses the same components as before, except for the voltage regulator and it's all somewhat consolidated on perf board instead of breadboard. R2 has been switched out for 39R and I'm driving the whole thing at 5V from my bench PSU.With no LED - so no chance of feedback - my scope indicates that the quality and repeatability of the signal going to the transistor gate varies with the distance of the remote control to the receiverAt about 10cm the signal looks terrible:At 100cm not always perfect but pretty dang good:And at 300cm worse again:Note that in the lumped together "signal blocks" the signal is still oscillating at 38kHz, so it looks like for some reason the controller isn't turning off the output.Measuring the output of the IR receiver shows why: Except for at about 1m distance, the decoded signal is simply not representative of what the remote sends and happens to correspond exactly with what the micro outputs.So is the receiver busted?Measuring its output out of circuit doesn't suggest so at all. No matter the distance of the remote the signal, the receiver output was consistent and, as far as I can tell, correct.I also measured the signal the controller outputs to the MOSFET gate without having the transistor attached:Now, distance again does not seem to make a difference. The slow signal decays after some of the pulse blocks are most likely from the somewhat hacky way the output gets turned off and occurs when the output is deactivated while the 38kHz pulse is high.This however is normally taken care of by the pull-down resistor R1:Thanks for all the suggestions so far! I'll probably put the project to rest for the day, gotta clear my head...

author: Siwastaja
author_rank: Super Contributor
timestamp: January 25, 2022, 06:44:11 pm
content: Quote from: Schorsch on January 25, 2022, 06:22:00 pmStart by fixing the PSU. These thingsreallyoscillate with wrong type or size of output capacitor, BTDT. And they may oscillate A LOT, or produce completely wrong output voltage, and behave really funny. Weird MCU problems are the expected result. Start by fixing that before doing anything else.If you don't have proper parts at your disposal, tear down some random 47 to 470 uF elcap from any random junk PCB. It probably tames the regulator fine.I'm not saying this is the only possible problem, but this is one of the most probable and biggest issues, also easy to fix.

author: Zero999
author_rank: Super Contributor
timestamp: January 25, 2022, 07:41:42 pm
content: Try this. If it works, consider keeping R2 18R and using three LEDs in series. It will use half the current, but be 1.5 times as powerful.

author: ledtester
author_rank: Super Contributor
timestamp: January 25, 2022, 07:53:16 pm
content: Quote from: Schorsch on January 25, 2022, 06:22:00 pmWhat battery supply were you thinking of? If it's less than 5V you won't need the regulator.