555 timer - setting frequency and pulse width? - Page 1
Forum section: electronics / beginners

author: ChiroZi
author_rank: Newbie
timestamp: May 01, 2023, 12:28:31 am
content: Hi all.I really confused. I'm playing with a 555 timer and i want to create a fixed frequency of 10HZ, with a pulse width of 500 micro seconds.no matter what combination of resistors and capacitor value i use i can't seem to get what i need. I feel like this should be easy but i'm clearly confused.where am i going wrong?many thanks

author: John B
author_rank: Frequent Contributor
timestamp: May 01, 2023, 12:38:22 am
content: If you want to use a 555, perhaps use a dual package version or 2x 555s. One would be an astable configuration to give you a 10Hz signal which triggers the second one in a monostable configuration giving you the set 500us pulse.

author: tautech
author_rank: Super Contributor
timestamp: May 01, 2023, 12:51:02 am
content: Quote from: ChiroZi on May 01, 2023, 12:28:31 amWelcome to the forum.Use one of the many online component calculators, just one:https://www.digikey.co.nz/en/resources/conversion-calculators/conversion-calculator-555-timer

author: WattsThat
author_rank: Frequent Contributor
timestamp: May 01, 2023, 12:53:34 am
content: Don’t think you can do it with just a 555, the output will be the inverse of what you’re looking to create.10uf, 14.3K, 75 ohm will give you about 99.5 ms on, 500us off then invert with an NPN transistor.

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 01:11:51 am
content: Quote from: ChiroZi on May 01, 2023, 12:28:31 amUsing a 555 in 2023 :-)Ok, if it's just for fun, sure.But there's nothing you can do with a 555 that you can't do with a microcontroller in an 8 pin package, and a 20 line program running on it.And that includes things where you read analogue inputs from a couple of the pins.The ATTiny85 has long been my go-to chip for this. It's cheaper than a 555 too. You can use them with zero external components if you want to.But now I'd go for the CH32V003, $5 for 50 of the 8 pin version. Or you can buy the 20 pin version (lots of IOs) on a board for $1.50.Back to the 555, you can make an asymmetric oscillator with a single 555, but 99.5 ms / 0.5 ms i.e. 0.5% duty cycle is outside the reasonable range. You can get to maybe a 5% duty cycle.So you need two of them as others have mentioned: one as a 10 Hz oscillator and one as a 0.5 ms one-shot.Or: get that ATTiny85 chip and a standard Uno board to use to program it, install the Arduino IDE, and download the following program to the ATTiny85:Code:#define PIN 1void setup() {pinMode(PIN, OUTPUT);}void loop() {digitalWrite(PIN, HIGH);delayMicroseconds(500);digitalWrite(PIN, LOW);delay(99); // ms}

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2023, 01:25:01 am
content: Quote from: tautech on May 01, 2023, 12:51:02 amThat or any similar calculator is not going to help. The standard NE555 astable configuration has a discharge resistor between the timing capacitor and the discharge pin, to set the discharge (output low) time and/or limit the discharge current, and a pullup resistor to the discharge pin, which is in series with the discharge resistor when the timing capacitor is charging and the total of the two sets the charging (output high) time. It is therefore impossible for that circuit to output less than 50% duty cycle, as the charging time constant can never be less than the discharge time constant.Its possible to relax the 50% minimum duty cycle constraint by adding a diode across the discharge resistor, cathode towards the capacitor, so the discharge resistor is bypassed during the charging phase of the cycle, but as diodes are non-ideal, that degrades timing accuracy, introducing sensitivity to supply voltage and temperature. Also it doesn't perform well at very low duty cycles.Our O.P. wants a 0.5ms on time in a 100ms cycle time. That's 0.5% duty cycle, well outside the range the classic astable circuit, modified with the additional diode, is good for.Its possible a CMOS '555' with two steering diodes and the charge and discharge timing resistors connected to Output (rather than Discharge) could do the job, but if you only have bipolar NE555 or equivalents, John B's suggestion above, to use a second 555 monostable just to get the required 0.5ms on time, is the best option.If you don't need a push-pull output, WattsThat's suggestion of inverting a 99.5% duty cycle output waveform with a transistor is also a good one, cheaper and more compact than using a second 555. His suggestion to use a NPN (emitter to ground) gives a single ended inverted output that drives low. If you need an single ended inverted output that drives high, use a PNP transistor, emitter to Vcc. Both need a series base resistor, typically chosen to give a base current of 10% of the expected load current.

author: themadhippy
author_rank: Super Contributor
timestamp: May 01, 2023, 01:30:35 am
content: Quoteyea right £1.45 at farnell compared to 41p for the 555,then of course your gonna need some way to get your code from the pc into the micro.Why is it the stock answer these days to any design question " use a micro" . Dont bother learning about electronics,just learn to code.

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2023, 01:47:37 am
content: Quote from: themadhippy on May 01, 2023, 01:30:35 amAlso there's the operating voltage range to contend with. A NE555 or compatible works from 4.5V to abs. max 18V. This usefully covers the normal voltage range of a 12V Lead acid battery in automotive use*, and many other common low voltage applications for which 5V is not sufficient. OTOH if you use a MCU, you are stuck with its supply and output voltage limitations, and MCUs that can handle over 5.5V are rare like chicken's teeth#and mostly long obsolete. By the time you've added a regulator circuit to power the MCU and a level shifter to get the output back up to the voltage you need, any benefits of simplicity over a NE555 are long gone.* You'll still need to prevent the extreme transients common in automotive '12V' systems from reaching the 555 Vcc.# The only one I am aware of that's still in production with an on-chip regulator and HV I/Os good up to 15V is thePIC16HV540, but its Microchip's baseline core, OTP, and requires a 'legacy' programmer that supports Microchip's PIC16C EPROM program memory devices, so its a PITA to develop for that I wouldn't wish on anyone!

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2023, 02:11:09 am
content: @ChiroZi,The NE555 discharge pin has to sink the discharge current + the timing pullup resistor current. Most 555 datasheets don't specify the maximum current the Discharge pin can sink, but a fair assumption is that its no more than the Output can sink. A 75 ohm timing resistor with a 9V supply is pushing your luck and even if it works reliably, will result in a rather high supply current. If you must: increase both R7 and R3, and decrease C3, all by a factor of 10, to get the same time constants with much less stress on the chip and less supply current.D1 is not needed - short it out.

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 02:14:43 am
content: Quote from: themadhippy on May 01, 2023, 01:30:35 amOn Mouser I'm seeing (NZ$) $0.877 for NE555P, $1.52 for a CMOS TLC555CDR.Last time I bought ATTiny85 I got 10 for $15.85. Admittedly that was pre-pandemic.Ok, maybe not cheaper, but pretty close to the same. Especially when you bear in mind you're not going to need those external resistors and capacitor and maybe diodes.The CH32V003 is definitely cheaper: 10c a pop. As well as having twice the program space, four times the RAM, 32 bit vs 8 bit, 48 MHz vs 16-20 MHz.QuoteSure. A $15 Uno clone which you can use forever for programming as many bare chops as you want, and also many other prototyping tasks.QuoteIf the exercise is "learn electronics" then sure, get some 555s, 741s, some PNP and NPN transistors and knock yourself out. It's all valuable skills.If the exercise is to make something useful with minimum effort and maximum features and performance then, yes, "use a micro".You think this guy doesn't know electronics?

author: EPAIII
author_rank: Super Contributor
timestamp: May 01, 2023, 02:33:18 am
content: The digital answer makes a lot of sense if you are talking about a "one off" build for just today. It is cheaper, if you already have the means for programming it. It will take up less board space and that can be important.But, I would bet dollars to donuts that the 555 will still be around for MANY decades after his ATTiny85 or any other microprocessor based chip you may select has gone to dust. The digital geeks just LOVE making things obsolete and replacing them with "better" digital things which are not compatible. So if you are building anything to last for a long period of time and/or be repairable for that long time frame, the better bet is the 555, HANDS DOWN.And YES, you will learn more electronics with the 555 approach.Quote from: themadhippy on May 01, 2023, 01:30:35 am

author: John B
author_rank: Frequent Contributor
timestamp: May 01, 2023, 02:43:17 am
content: The choice should be made based on design requirements surely.What's the purpose of this signal? What kind of accuracy and temperature stability do you need? Do you need to adjust either frequency or pulse width later on?

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 02:50:18 am
content: Quote from: EPAIII on May 01, 2023, 02:33:18 amAre you claiming the physical chips are less durable? Seem unlikely.You can still today buy brand new 6502, z80, 6809, 6800-series, 8086, 68000, or if you want single-chip microcontrollers you can still get an updated but compatible flash instead of EPROM version of the 1993 PIC16C84. And of course many variations on the 8051 from 1980.

author: EPAIII
author_rank: Super Contributor
timestamp: May 01, 2023, 02:51:46 am
content: Looking at your code I find it interesting that it shares a characteristic with a single 555 circuit: both have an interaction between the overall pulse frequency and the pulse width. In the 555 circuit that is a given, even with steering diodes. The values of the components will need to be adjusted to achieve whatever level of accuracy it needed for those two parameters.In your code, you have a loop where there are three times involved: the 500 us delay, the 99 ms delay, and the execution time of the loop itself. While the pulse width will be determined by the 500 us delay, the frequency will depend on all three of these parameters. Oh, and of course the oscillator frequency of the processor is the basis for all of the above.If great accuracy is needed, then, in both cases, some tweaking will be needed.Quote from: brucehoult on May 01, 2023, 01:11:51 am

author: ChiroZi
author_rank: Newbie
timestamp: May 01, 2023, 03:30:02 am
content: just want to say i've figured it out now, there were a few things i read here that made a lot of sense and made me realise a few things, really helped my understanding. What an great forum!It is difficult to reply to everyone, but thank you all that helped!

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 04:32:58 am
content: Quote from: EPAIII on May 01, 2023, 02:51:46 amThe CPU frequency is is abstracted out by the Arduino system. As long as you compile your code for the right board you don't have to worry about it.If you don't mind adding a couple of lines of code insetup()then you can decouple the frequency from the pulse width by using a subtraction to calculate the LO time ascycle_time - pulse_width. You perhaps might want to calculate this as microseconds.Unfortunately the Arduino librarydelayMicroseconds()call has a maximum argument of 16383 i.e. a little over 16 ms. So you might want to generalise each of the two delays into a ms delay plus a µs delay using /1000 and %1000 on the desired delay.ThedelayMicroseconds()call is documented as being inaccurate for times less than 3 µs (on a 16 MHz AVR), so this can be taken as the overhead of the call -- which is in fact compensated for inside the function by subtracting 3 µs (presumably) from the requested delay.digitalWrite() is also in the 2-3 µs range.I expect returning fromloop()tomain()and having it callloop()again is under 1 µs.So I estimate around 10 µs overhead from the program code itself -- 0.01% on a 10 Hz waveform.You're not going to get anything like that kind of accuracy from the 555.Code:#define PIN 1#define US 1L#define MS 1000L#define PERIOD (100*MS)#define PULSE (500*US)#define OVERHEAD (10*US)#define LOTIME (PERIOD-PULSE-OVERHEAD)void setup() {pinMode(PIN, OUTPUT);}void loop() {digitalWrite(PIN, HIGH);delayMicroseconds(PULSE);digitalWrite(PIN, LOW);delay(LOTIME/1000); // msdelayMicroseconds(LOTIME%1000);}It's only one more line of actual executable code ... the second call todelayMicroseconds().QuoteSure, but we're already way ahead of anything you're going to get from a 555 with 1% tolerance resistors and capacitor, if the micro's clock is run from a crystal. If you're using an ATTiny85's internal RC oscillator then you generally get about 1% accuracy at 5V and 25C. You can calibrate your particular chip using internal registers if it will be operating in known conditions, but otherwise temperature and voltage differences can again give about a 1% variation. Use a crystal if you really care.

author: John B
author_rank: Frequent Contributor
timestamp: May 01, 2023, 05:16:02 am
content: Just noting that for a 16MHz clock:500us out of each 100ms equates to 8000 clock cycles per 1.6 million. From memory there's a few arduino libraries out there that can do low level clock generation, so you could certainly achieve some good accuracy.

author: EPAIII
author_rank: Super Contributor
timestamp: May 01, 2023, 07:53:04 am
content: Are you just cherry picking processor chips that you know are available, or saying that all previous processor chips are still available? I don't know. Just asking.Quote from: brucehoult on May 01, 2023, 02:50:18 am

author: EPAIII
author_rank: Super Contributor
timestamp: May 01, 2023, 07:57:55 am
content: Any oscillator, every oscillator has a tolerance range. The frequency CAN vary. And so can the time of the delays and of the execution of the loop.Just because you write something in code does not make it so.

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 09:07:15 am
content: Quote from: EPAIII on May 01, 2023, 07:53:04 amI know they are available. Hell, I had a couple of 6809's arrive the other day. Se pic.Obviously it is entirely possible to choose to rely on some microprocessor or microcontroller that proves to be commercially unsuccessful, the manufacturer goes out of business, starts charging outrageous amounts etc.But everything I mentioned was looking like a pretty safe bet for longevity by ... 1983 or so? The 68000 the least so I guess, but it had been out since 1979, Sun and others were shipping Unix workstations using it, the Apple Lisa was out and they were known to be working on the Macintosh.That's 40 years ago.Good luck getting a Z8000 or NS32032 now. But then ... I don't think they were easily available even then. Some university friends and I designed and made a wire-wrapped computer in 1983. We seriously considered the 68000 and the 8086/8088, but went for the 6809 because one of our main applications in mind was a music synthesiser. The 8086 takes 80-100 clock cycles for an 8x8->8 multiply, 125-150 for 16x16->16. The 68000 takes 40-70 cycles for a 16x16->32 multiply. And the 6809 does an 8x8->16 multiply in 11 cycles .. which is perfect for lo-fi audio.

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 09:21:51 am
content: Quote from: EPAIII on May 01, 2023, 07:57:55 amOf course. I already SAID if you want high precision then you need a crystal -- an option which simply isn't available with a 555. To achieve similar precision without a micro you're going to need a 32768 Hz crystal, a couple of inverters from a 7404 to make it oscillate, a 12 bit counter, a bunch of logic to detect when to reset the counter ...If a 555 is good enough for the job then so is the RC oscillator inside a micro.QuoteOnce you have suitable clock accuracy, the execution time of all simple microcontrollers is absolutely deterministic.But even if they didn't they also have 16 bit counters with pre-scalers, and compare registers to generate an interrupt when a set count is reached.

author: iMo
author_rank: Super Contributor
timestamp: May 01, 2023, 10:45:44 am
content: Hey, I built my first counter with 556 (2x555, 7490, 7442, 7seg leds), as well as my first digi voltmeter (the counter + U/f converter).. No need to mess with MCUsHere is the pulse generator with 2x 555 (or 1x 556)..

author: brucehoult
author_rank: Super Contributor
timestamp: May 01, 2023, 10:56:03 am
content: Quote from: iMo on May 01, 2023, 10:45:44 amOf course you can do it. It's a learning experience. Most of us have been there.Doesn't mean it's the most practical way to do it today.Btw, I think you mean 7448 not 7442.

author: iMo
author_rank: Super Contributor
timestamp: May 01, 2023, 10:59:03 am
content: Yep 7447

author: Zero999
author_rank: Super Contributor
timestamp: May 01, 2023, 11:02:17 am
content: The 555 with a diode should do the job. Use a Schottky because it has a lower voltage drop.As with any RC oscillator, the tolerances will be poor.

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2023, 11:14:42 am
content: OTOH Schottky diodes are known for higher reverse leakage at elevated temperatures. In this case, that would be equivalent to reducing R2, which would increase the frequency. A silicon diode (of similar ratings) will typically have much lower reverse leakage, but its higher Vf will affect the on time so R1 may need trimming, and the on time will be less stable with respect to supply voltage and temperature.If its only got to work at room temperature or below, a Schottky would be a good choice, but if its got to work at elevated temperature, check you are happy with what happens if the diode is heated up a bit!

author: iMo
author_rank: Super Contributor
timestamp: May 01, 2023, 11:37:41 am
content: Also the 17.5mA flowing most of the time through the R1=680ohm is rather the wasting energy todayI would go the colder way and use two 555s..

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2023, 11:47:30 am
content: It gets worse:https://www.eevblog.com/forum/beginners/741-op-amp-for-attenuation/