Pages: [1]   Go Down
Author Topic: Adjustable Duty Cycle PWM signal at low Hz  (Read 1175 times)
0 Members and 1 Guest are viewing this topic.
Newcastle, NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Just a mechanic
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I only provide help via the forum - please do not contact me for private consultancy.

Newcastle, NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Just a mechanic
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. .
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19331
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: [1]   Go Up
Jump to: