Go Down

Topic: Adjustable Duty Cycle PWM signal at low Hz (Read 1 time) previous topic - next topic

nitrolx

Hi all,
just working on a project and was wondering if anyone knew of a library or had some working code to manually creat a PWM-style output signal but at low frequencies.

I need to pulse solenoids to control flow, but the onboard PWM is way too fast for the solenoids to react.

I need to create a signal around the 10Hz - 20Hz range with an adjustable duty cycle.

Ideally I want to be able to ramp the flow up and down over a time period. . eg start at 25% flow and then after 2 seconds the flow has linearly ramped ot 100%.
The frequency needs to be adjustable to suit different style solenoids but would only be a setting it wouldn't need to be dynamic like the duty cycle.

I've had a search and seen ideas where the internal timers are changed to slow down the onboard PWM frequency, but this also affects millis() and other timing functions which are in use in the project.

Cheers for any help.

PeterH

At that sort of frequency, you could just use the techniques demonstrated in 'blink without delay' to switch the outputs at the desired times.
I only provide help via the forum - please do not contact me for private consultancy.

nitrolx


At that sort of frequency, you could just use the techniques demonstrated in 'blink without delay' to switch the outputs at the desired times.

I thought that. . and I think I can work out how to get, say a 10Hz squarewave (working out the ms periods of a 10Hz signal etc) but it would always only be at a 50% duty cycle (on for half the period, off for half the period).

I need to work out how to change the duty cycle. .

Nick Gammon

You could probably do it with Timer 1, which can go that low a frequency, but I'm inclined to agree with PeterH.

You just need two intervals, timeOn and timeOf.

So, working in mS, to get a cycle of 10 Hz you would want 50 mS on then 50 mS off (total of 100 which is 1/10 of a second).

To vary the duty cycle you have, say 30 mS on and 70 mS off.

Go Up