Single 555 Timer with 2 discrete duty cycles? (Not continuously variable) - Page 1
Forum section: electronics / beginners

author: doublec4
author_rank: Regular Contributor
timestamp: June 26, 2019, 01:01:49 pm
content: Hi all,I am using the typical 555 timer circuit to produce a PWM signal (see attached circuit). I would like two discrete duty cycles as determined by different R1,R2 combinations with a common C1.I would like to switch between the duty cycles electronically (no mechanical switches but rather with a digital I/O from microcontroller). Originally I thought about creating a type of SPDT circuit using complementary MOSFETs (between R1 and Vcc) to switch between different R1,R2 combinations in the circuit, but I don't think it will work as the different values for R2 would still be in parallel and it would mess up the duty cycle.Any ideas how I could achieve this switching between duty cycles? I have seen the circuits with continuously variable duty cycles using potentiometer but this is not what I am looking to do.Any help would be great! Thank you so much!

author: GerryR
author_rank: Frequent Contributor
timestamp: June 26, 2019, 01:59:33 pm
content: A single miniature DPDT relay (5V, 12V ??) would do it. No current to speak of and in excess of 106cycles. Connect the junction of R1a and R2a to the NO of one set of contacts and the other side of R2a to the NO of the other set of contacts. Junction of R1b and R2b to the NC set of the contacts that the R1a and R2a set are connected to, with wiper to pin7 on the 555. Other side of R2b to the NC set that the other side of Ra is going to, with the wiper to the top of the Cap going to pins 2 and 6 of the 555.

author: doublec4
author_rank: Regular Contributor
timestamp: June 26, 2019, 02:42:29 pm
content: Quote from: GerryR on June 26, 2019, 01:59:33 pmInteresting, thanks! Makes sense and I can drive the coil with my I/O and transistor if the required voltage or current exceeds the capability of the I/O directly driving it. I tried looking up solid state DPDT relays on Digikey but it seems there are none.If anyone else has any other method of achieving this with mosfets or transistors or something I am definitely still interested in multiple solutions! Thank you

author: not1xor1
author_rank: Frequent Contributor
timestamp: June 26, 2019, 04:23:39 pm
content: Quote from: doublec4 on June 26, 2019, 02:42:29 pmimho it would be easier to use a different circuitstart from the 50% duty cycle schematic where the capacitor is charged/discharged by the output and then just change the CV pin voltage value to change the duty cycle accordinglyfor instance you can use a microcontroller I/O to connect CV pin via a 10k resistor to 5V or 0V or set the I/O open to leave the duty cycle at 50%

author: doublec4
author_rank: Regular Contributor
timestamp: June 26, 2019, 05:39:39 pm
content: Quote from: not1xor1 on June 26, 2019, 04:23:39 pmSounds good... however, in my typical astable circuit, I was achieving less than a 50% duty cycle by putting a diode in parallel with R2. It got me down to about %20 by my calculation. Using the voltage controlled option on pin 5 I would still be limited to 50% as my lowest duty cycle, no?

author: Zero999
author_rank: Super Contributor
timestamp: June 26, 2019, 06:05:59 pm
content: No, the voltage controlled option will work at lower duty cycles than 50%. I've used it before to get from close to 0 to 100% so 5% to 95% is reasonable.Another option is to use an analogue switch such as 74HC4066 to switch the diode an resistor element in to the circuit.https://assets.nexperia.com/documents/data-sheet/74HC_HCT4066.pdfJust one question: why not use the microcontroller to generate the PWM and do away with the 555 circuit altogether?

author: doublec4
author_rank: Regular Contributor
timestamp: June 26, 2019, 06:20:34 pm
content: Quote from: Zero999 on June 26, 2019, 06:05:59 pmI actually have two applications where in one of them is just a simple flashing light system and I had figured the extra step of programming the chip was going to be a pain... I was hoping to have a system where I could order the PCB and someone else could assemble the light system.The other application requires an Arduino to "talk" to a few other devices... so the uC is there to use, however I've read that changing the PWM frequency is more challenging with the Arduino (I need 200Hz... which also seems to be too low to find oscillators on Digikey?). So in the end I figured it would be easy to just use the circuit from the first application and use a digital I/O to control the duty cycle of the 555 timer instead of a mechanical switch.

author: GerryR
author_rank: Frequent Contributor
timestamp: June 26, 2019, 07:04:01 pm
content: Quote from: doublec4 on June 26, 2019, 02:42:29 pmThe relays are miniaturemechanicalrelays; NAIS DS2E-M-DC5V is one with 5 volt coil, also available in 12 volt, 24 volt. Magnecraft and Hamlin make them in DIP packages. Try Newark Element 14, Allied or Mouser as a source. Many instruments use them internally for range changes, etc. Have a great day.

author: doublec4
author_rank: Regular Contributor
timestamp: June 26, 2019, 11:59:16 pm
content: Quote from: GerryR on June 26, 2019, 07:04:01 pmYep! Should have been more clear, it was kind of an off tangent thought when I mentioned the solid state device. I found many mechanical relays

author: not1xor1
author_rank: Frequent Contributor
timestamp: June 27, 2019, 04:57:10 pm
content: Quote from: doublec4 on June 26, 2019, 05:39:39 pmHere is the circuit I'm referring to:here is what you get when you connect a 4.7kΩ resistor between CV and 0Vhere is what you get when you connect a 4.7kΩ resistor between CV and V supply

author: doublec4
author_rank: Regular Contributor
timestamp: June 27, 2019, 09:15:09 pm
content: Quote from: not1xor1 on June 27, 2019, 04:57:10 pmThanks! I'll give it a try on the bread board

author: brucehoult
author_rank: Super Contributor
timestamp: June 27, 2019, 10:38:09 pm
content: Quote from: doublec4 on June 26, 2019, 06:20:34 pmWhat on Earth have those things got to do with each other?If you want to output a 200 Hz PWM from an Arduino running at 16 MHz then you program it (whether using software or hardware) to toggle a digital output pin one way and then back again every 80000 clock cycles.The standard Arduino library "analogWrite()" function uses a 480 Hz frequency on most pins (960 Hz on a couple of them) on all the most common AVR boards including Uno, Mega, Nano, Mini but it you're programming the registers directly you can set any frequency (total cycles) you want.You could for example use Timer 2, set the prescale to 1024, set OCR2A to 77, and then set OCR2B to a value between 0 and 77 to set your duty cycle. (You need to use the B output in this case).This would give a 200.32 Hz signal, which is hopefully close enough. You won't do better with a 555 anyway!Seehttps://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWMDon't muck with Timer 0 if you want to use millis() or delay() in your code.

author: doublec4
author_rank: Regular Contributor
timestamp: June 28, 2019, 01:21:08 pm
content: Quote from: brucehoult on June 27, 2019, 10:38:09 pmThanks! Okay so for the application with the on board Arduino, I've read about changing the registers but have never tried it... I can look into thatRegardless, for the purpose of expanding my knowledge I still enjoy learning new ways to tackle this without resorting to using the PWM from Arduino. The advice from Zero999 introduced me to analog switches. Admittedly I didn't even know about their existence prior to this