Why is my 555-timer PWM duty cycle range so small? - Page 1
Forum section: electronics / projects

author: Cory Parsnipson
author_rank: Contributor
timestamp: July 20, 2023, 09:28:29 am
content: Hello, I made a 555-timer PWM circuit, like the one described onthis page:However, instead of using a normal 10kOhm pot, I am using aDS3502 I2C enabled digipot.When I use my circuit, I am expecting to be able to have a duty cycle between 4.8% and 100%, given that I'm using 500 Ohms for R_A and the pot is 10k Ohms. However, in real life, I'm seeing a much, much smaller range from 35% to 70% approximately at the extremes. Could anyone give advice as to why I might see such non-ideal performance? Basically I am trying to determine if the design I cobbled together simply sucks or if I made a design oversight such that something is screwing up the frequency and duty cycle performance.Here's my schematic:I'm using these schottky diodes:https://www.digikey.com/en/products/detail/micro-commercial-co/BAT43W-TP/717224. I'm mentioning this because the diode's forward voltage drop and recovery speed seems to have an impact on the calculations.I'm also using a 0.1uF capacitor, meaning I would expect about 1190 Hz frequency from the formula. But I am observing around 350 Hz if I use a 3.3V supply.I'd be happy to provide more information as needed. Thanks!

author: Alex Eisenhut
author_rank: Super Contributor
timestamp: July 20, 2023, 10:11:45 am
content: 3.3V is too low for a 555."Operation is specified for supplies of 5 V to 15 V."7555 might be better. In any case that's an awfully complex design for these days, if you already have I2C... use a microcontroller.

author: RoGeorge
author_rank: Super Contributor
timestamp: July 20, 2023, 02:02:19 pm
content: Also, the datasheethttps://www.analog.com/media/en/technical-documentation/data-sheets/DS3502.pdfsays wiper resistance can be up to 5k, from which I understand some resistance (up to 5k, considerably big) will appear in series with the wiper. By comparison, the series resistance for the wiper of a mechanical potentiometer is close to zero ohms.To check if this is the cause, disconnect the digital potentiometer from the circuit (pins RL, RW, RH) and use a fixed 10k resistor and a short circuit, then swap the places between the 10k and the short, to check the PWM range for the other extreme (as if the wiper will be first at its minimum value, then at its maximum).

author: TimFox
author_rank: Super Contributor
timestamp: July 20, 2023, 03:54:56 pm
content: Note the actual definitions of "potentiometer" and "rheostat".A potentiometer is defined in terms of a (three-terminal) voltage divider, while a rheostat is defined in terms of a variable (two-terminal) resistance.

author: Zero999
author_rank: Super Contributor
timestamp: July 20, 2023, 06:33:23 pm
content: Just one question: why? You must be using a microcontroller, so skip the 555 and just generate the PWM directly, from that.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 20, 2023, 06:52:43 pm
content: I assumed the TS was driving the mosfets (?) directly as the 555 can source at least 200 mA. However, I agree on the using a micro + gate driver as simpler and more easily controlled.

author: Cory Parsnipson
author_rank: Contributor
timestamp: July 20, 2023, 06:53:16 pm
content: Quote from: Zero999 on July 20, 2023, 06:33:23 pmI was previously working around an issue where I needed I2S audio from a Raspberry Pi and this was interfering with my ability to have it generate a hardware PWM signal. (I solved that by configuring pigpio, a python library, to not use the PCM clock when generating the wave).Still, I am designing an LCD screen driver, so all the electronics will be behind a single DSI cable, so having a smaller piece of dedicated hardware to generate the PWM signal makes sense to me. I'm considering using a dedicated PWM driver, like thePCA9632, since the designers most likely know way more about designing a proper circuit than me, but I am asking for info in this thread so I can at least know why my own attempt doesn't work...Quote from: Alex Eisenhut on July 20, 2023, 10:11:45 amSee above for microcontroller question. But yes, good point. I forgot that I switched over to theTLC555CDRbecause the datasheet appears to say it can operate at 3.3V.Quote from: TimFox on July 20, 2023, 03:54:56 pmOk? I'm using it as a potentiometer with the RH and RL hooked up to the two branches with the diodes and the wiper is connected to the capacitor.Quote from: RoGeorge on July 20, 2023, 02:02:19 pmAh, good catch, and great idea. I'll get around to doing this in the next few days when I get some lab time. Thanks!

author: jpanhalt
author_rank: Super Contributor
timestamp: July 20, 2023, 06:54:57 pm
content: Are you talking about driving the backlight? One pin and a single logic mosfet can do that.

author: Cory Parsnipson
author_rank: Contributor
timestamp: July 20, 2023, 07:00:33 pm
content: Quote from: jpanhalt on July 20, 2023, 06:54:57 pmYes... So more context, I have a backlight led driver chip (AP5726) and it takes a PWM signal to dim the LEDs. You can use other types of signals or transistors to dim the backlight, but I thought a PWM signal would be the most flexible.

author: Zero999
author_rank: Super Contributor
timestamp: July 20, 2023, 07:59:39 pm
content: Quote from: Cory Parsnipson on July 20, 2023, 06:53:16 pmUse another microcontroller to generate the PWM.

author: Cory Parsnipson
author_rank: Contributor
timestamp: July 20, 2023, 08:07:05 pm
content: Quote from: Zero999 on July 20, 2023, 07:59:39 pmNo <3

author: TimFox
author_rank: Super Contributor
timestamp: July 20, 2023, 08:46:16 pm
content: Potentiometer: look at my statement about the difference between a potentiometer and a rheostat, then look at RoGeorge's statement about the common resistance in the "wiper" lead of a digital potentiometer.Such a resistance does not destroy the voltage divider effect of the potentiometer, but gets in your way for the timing circuit.

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 04, 2023, 12:29:06 am
content: I got derailed a bit with some other stuff, but I finally got around to doing some debugging. I desoldered the digipot and tied a 10k resistor to set the "wiper" in min and max configurations.For the min duty cycle, I get a high pulse of 50us with a total cycle period of 910 us. This gives me approximately a 5.47% duty cycle, which is very close to what I was expecting. If I tie RW to RL with the resistor, I get almost 100% duty cycle, also as expected. Also if I redo the frequency calculation for low duty cycle accounting for a 5k Ohm resistance in series with R_A, I get a minimum duty cycle in the vicinity of, like, 32% or something. Which is what I was seeing from the digipot.So bottom line, looks like the unusually high wiper resistance was screwing things up. But even if there was no wiper resistance, the circuit's maximum range wouldn't work for me, because I'd like the ability to turn the backlight off and 5.47% duty cycle is still pretty bright.For complete-ness, if one were to continue down this path of making a custom hardware circuit to generate a PWM signal, here are some interesting things I found:1. This alternative digipot:https://www.digikey.com/en/products/detail/microchip-technology/MCP4561T-103E-MS/2061346The part number I quoted above supposedly has all the same features as the DS3502 I was using, but instead of 127 steps, it has 257, which I suppose is a good thing here. Who wouldn't want twice the resolution? More importantly, the datasheet claims that this part only has 75 ohms wiper resistance, which I am assuming will make a big difference in duty cycle range.2. Negative ResistanceFrom this question:https://electronics.stackexchange.com/questions/159212/very-low-wiper-resistance-digital-pots-anyone-know-of-any, apparently you could compensate for the large wiper resistance by constructing another circuit using an op amp that effectively acts as a negative resistance.https://www.electronicdesign.com/technologies/components/article/21758411/negative-resistance-nulls-potentiometers-wiper-resistance<-- this is an article linked by the answer that provides more information. Adimittedly, it sounds like more trouble than it's worth. But in another application where the digipot was an indispensable part of the design, I can see this being a life-saver.I'm thinking the 555-timer route is the wrong route for my application unless I were willing to implement 1 + 2. There are other ways of generating a PWM signal:3. For the curious, howdomicrocontrollers generate a PWM signal?https://www.allaboutcircuits.com/technical-articles/introduction-to-microcontroller-timers-pwm-timers/Essentially, you generate a discretized sawtooth, or use a counter to increment values and wrap around when the period is over. Then using a comparator, generate a signal that goes high when the sawtooth/counter is below the comparator value, and goes low otherwise.4. Just use a microcontroller.Maybe something in the ATtiny family would let me stick it to the back of an LCD screen without sacrificing too much physical space. I could select the ATtiny24 or ATtiny25 to get both PWM output and I2C handling in one package.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 04, 2023, 02:57:11 am
content: You could do something like this with a dual Op-Amp which would give you 0-100% range:

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 04, 2023, 04:40:52 am
content: Quote from: Cory Parsnipson on July 20, 2023, 06:53:16 pmDigi-pots are quite costly solutions in 2023.If you can find/fit a LED i2c controller with PWM, that will likely be the least-engineering solution. Limmisil/ISSI have a few i2c to LED parts too.If you cannot find one that fits what you need, then a small MCU could do the task.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: August 04, 2023, 08:18:04 am
content: What OP is designing is available in a small single SOT23 like form factor - i2C in, LED current out. Just a parametric search away on your fav distributor site - should it be DigiKey or 😱LCSC

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 04, 2023, 08:43:30 am
content: Quote from: Kim Christensen on August 04, 2023, 02:57:11 amWow this is cool. I'm doing a search on op amp multivibrator/pwm and seeing a lot of variations on this design.Quote from: PCB.Wiz on August 04, 2023, 04:40:52 amIndeed... The DS3502 digipot I'm using was $1.82...Quote from: dobsonr741 on August 04, 2023, 08:18:04 amYes, I found many. PCA9685, PCA9632, LP5562... These are pwm led drivers. I couldn't find any that were programmable with non-volatile memory. The problem is that they all require you to use I2C commands to configure the PWM signal enable and frequency on every power up. This is an issue for me because I'm trying to add this to a Raspberry Pi with a battery pack. Seeing the screen with no backlight for the entirety of boot, or just having a "dead" screen if something goes wrong with the script is unacceptable for my use-case.I've also noticed that there are several different types of IC for this kind of thing. I'm actually using a DC-DC boost converter led driver (AP5726) because the screens have many LEDs in series, so I needed 18-30V while also having constant current. The 3 ICs I mentioned in the previous paragraph do not boost the voltage, so I can't just use those to power the LEDs directly.ATTiny might be the most practical solution at this point. I think I'm gonna look up some more op amp designs and then read the ATTiny25 manual and see which one is simpler.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 04, 2023, 03:32:32 pm
content: How much control do you need ?You could use a 4051 or 4017 as a 8/10 resistor set points, and you choose the default drive.Host can later pick values either side of that.Even a simple 4528 monostable can give you a pre/post boot up signal, watchdog like.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 04, 2023, 03:45:39 pm
content: Quote from: Cory Parsnipson on August 04, 2023, 08:43:30 amExcept for the Raspberry Pi code:The ATtiny will be the simplest hardware wise. Most of the work is in the coding.OpAmp with digipot is all hardware.Depends on what's easiest for you.

author: Buriedcode
author_rank: Super Contributor
timestamp: August 04, 2023, 07:17:06 pm
content: You asked how micro's generate PWM? Almost all modern microcontrollers will have built in timers and hardware dedicated to generating PWM.For a backlight you don't need good resolution, but you do need relatively high frequency - this is fine as there is trade-off between the two, that is, higher frequency, means lower resolution.You mentioned 2kHz, which is easily generated by msot micros with 8-bit resolution (8 bit counter, *2kHz = 512kHz counter clock). Even 8 bit resolution is probably overkill for setting the backlight level, you need, what.. 16 levels?Honestly, it sounds like you're grossly over complicating things - I assumed because you were planning on using an I2C digital pot to control a 555-based PWM that you have a micro - and I'm willing to bet that micro has the facility to generate PWM in hardware without regular software intervention.Even without that there are I2C PWM generator chips out there. Lots of ways to do it, but it seems you initially chose one of the more complicated, part intensive ways.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: August 05, 2023, 05:06:14 am
content: The more parts - the more potential time wasted on issues. Even for a single board buildout. I treat each components as a line of code - one more piece ownership, one more potential for having a bug. IMO it’s better for me to buy it as a tested and guaranteed functionality, according to the data sheet, and to use my free time it opens up to do other things I also value, beside my electronics hobby.

author: Ian.M
author_rank: Super Contributor
timestamp: August 05, 2023, 06:29:48 am
content: Ditch the 555 and take another look at your AP5726 datasheet: Figure 3. Dimming Control Using a DC Voltage. The dimming control voltage input goes to a 100K resistor, so the wiper resistance of your digipot would be small compared to the input resistance so could probably be connected direct. The fig. 3 circuit is designed for 0 to 20mA dimming range for a 2V to 0V control voltage. Increase the 100K to 160K and it would accept a 3.2V to 0V control voltage range, though you might want to increase it a bit more so the digipot can never turn the backlight completely off.

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 05, 2023, 07:28:00 am
content: Wow, this is interesting. I'll give it a try, thanks!

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 06, 2023, 06:16:14 am
content: Quote from: Ian.M on August 05, 2023, 06:29:48 amAh, I was taking a look at this today and I couldn't figure out how to get a relationship between input DC voltage and led current. Could you help me figure out how changes in value to the DC voltage affects the LED current? Basically I'm curious how you know that a change from 100k to 160k would be sufficient for a 3.2V source, etc.I tried calculating a relationship using a voltage divider equation, but I don't think that's right because I'm not getting answers that make sense.

author: Ian.M
author_rank: Super Contributor
timestamp: August 06, 2023, 09:15:41 am
content: The feedback (FB) pin internal difference amplifier's reference voltage is 0.31V (nom.). That means the current regulation loop acts to keep FB close to that voltage swinging above and below it slightly with every cycle of the internal switch. The datasheet tells up the formula for the average LED current (no dimming) is If=0.31V/Rset.By injecting current at the FB pin, you can fool the control loop that the LED current is higher than it actually is, thus reducing the LED current. However its at an inconveniently low impedance, requiring a control current equal to the max. LED current, so R2 is added so the control current is reduced by a factor of 1+ R2/Rset. Thus to fully extinguish the LEDs, Ictl_max=0.31V/(R2+Rset), and R3 scales that to the desired upper limit of the control voltage input range.However I think there may be an error in the datasheet's maths(and thus the R3 resistor value I proposed earlier, which I scaled from theirs)! It states that "For VDCrange from 0V to 2V, the selection of resistors in Figure 3 gives dimming control of LED current from 0mA to 20mA." which is patently absurd as Max. VDCgives min. Ifand visa versa. Also the potential divider R3:(R2+Rset) is wrong - we know it must develop 0.31V at FB when If=0. Neglecting Rset as its three orders of magnitude smaller than the potential divider resistance, the fig 3 resistors give VFB=VDC/21 which is a max. control voltage of ~6.1V.

author: ArdWar
author_rank: Frequent Contributor
timestamp: August 06, 2023, 09:31:34 am
content: It should work as a summing amplifier.I don't think that particular circuit values are correct however. Ithinkthey're just copying AP5724 circuit (which is correct within reason), correctly scaling the sense resistor for 20mA full scale load current, but forgot to scale control voltage injection resistor (R3, and/or R2) to 0-2V control voltage.

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 07, 2023, 05:07:44 am
content: Quote from: ArdWar on August 06, 2023, 09:31:34 amThanks! This helped me figure out how to analyze the circuit. Now if I can only remember my fundamentals...Quote from: Ian.M on August 06, 2023, 09:15:41 amSorry, I think I'm doing something really stupid. So you said that to fully extinguish the LEDs:So if I plug in 5k for R2and 15 ohms for Rset, then the max control current is 6.18 * 10^-5 Amps? Is this supposed to be the same as the max LED current (20 mAmps)? I don't think I'm doing it right.I'm also confused about how exactly R3scales the current...==================In the meantime, I tried to find a relationship between VDCand ISETby solving the op amp and surrounding circuit. I'm getting lost in the middle and not sure if this is the right direction...Labeling the diagram like so:I can try and do the node voltage calculation for VN, like this guys does:https://electronics.stackexchange.com/questions/156719/opamp-inverting-amplifier-the-case-of-non-inverting-input-not-being-connected-tI assume VNis equal to VREF. I get the same answer by solving for VSET:This is where I'm stuck. I think I need to figure out the relationship between VDCand ISET, and I have this hunch that ISETis ILED+ ICTL... And that I'm missing an equation or two to figure out the relationship between ILEDand ICTL.AndthenI guess plug in numbers for VDCand ICTLto decide which values to use for R2/R3?

author: Ian.M
author_rank: Super Contributor
timestamp: August 07, 2023, 05:56:54 am
content: No, the control current is not the LED current. Its the current through R2 and R3 (neglecting the tiny FB input current), and thus R3 scales it into a voltage, as the control loop acts to keep FB at the reference voltage as long as the LED current is greater than zero.

author: Cory Parsnipson
author_rank: Contributor
timestamp: August 07, 2023, 06:38:28 am
content: Quote from: Ian.M on August 07, 2023, 05:56:54 amRight, the LED current is different from the control current, but you mentioned before that to fully turn off the LEDs, the control current needs to be equal to the max LED current?Quote from: Ian.M on August 06, 2023, 09:15:41 amSo, then:ICTL_MAX= 0.02 = 0.31 / (R2+ 15) => R2= 0...I'm still confused...

author: b_force
author_rank: Super Contributor
timestamp: August 07, 2023, 12:25:37 pm
content: Quote from: Zero999 on July 20, 2023, 06:33:23 pmOr just use a NAND or schmitt inverter instead.When doing this right you have control over frequency which is (relatively) more constant as well as duty cycle for the same package as a 555.