Very Low Frequencies with PWM Frequency Library

Hello,

I am trying to get an Arduino to pulse a pin at different frequencies. I installed the PWM Frequency Library, and it works well for all frequencies above 1Hz, but I really need frequencies below 1Hz, to about 0.05Hz, or even 0.01Hz.

I would just manually pulse the pin using a loop, however there will be other code running in the background while the pulse is gound on, as well as PWM on a normal frequency on another pin, and therefore I need this to be able to run in the background.

One thing to note, is that the duty cycle of the pulse is not important. I am currently using a 50% duty cycle with the PWM Frequency Library, but anything from about 20% to 80% should work. The maximum frequency required is 300Hz.

Does anyone know of a way of changing getting low frequencies with the PWM Frequency Library, or another way I can achieve this?

Thank you,
Andrew

That would be a job for good ole BlinkNoDelay.

Hi,

The issue with BlinkNoDelay is that my sketch will be running another loop whilst the pulse is occuring, and the delay in that loop will be almost impossible to synchronise with the delay required between the pulses. This means that the timing of the pulses would be dependant of the timing of the delay in the other loop, and this would cause very irregular pulses.

Any other ideas?

Thanks,
Andrew

You can get closer, using microseconds(), instead of millis().
But you will of course loose time acoording to code that runs, before the lapse timer is traversed.

Why not build yourself an interrupt service, that runs off the system counter ?
That way you get it as accurate you can, especially if you execute the interrupt code at once, letting other code suffer in time domain.
The interrupt service would occur at 300HZ rate max and have very little code anyway.

andrewferguson:
Hi,

The issue with BlinkNoDelay is that my sketch will be running another loop whilst the pulse is occuring, and the delay in that loop will be almost impossible to synchronise with the delay required between the pulses. This means that the timing of the pulses would be dependant of the timing of the delay in the other loop, and this would cause very irregular pulses.

Any other ideas?

Thanks,
Andrew

I rather doubt that it's impossible. I can see no reason why a standard millis() approach can not drive different frequencies. Synchronization in such a scheme is as simple as assigning time variables from one task to the other.

however there will be other code running in the background

A PC can have foreground and background processes because it has more than one processor. An Arduino does NOT. So, talk of “running in the background” is silly.

I guess you can't run Unix on a PDP-11, then... :wink:

No you cant, but you can actually talk to a Digital PDP-11 controlled machine using an optocoupler current loop interface port, a few hundred meters of cabling and an 86 based standard PC with a 10mB HD.

That was my first project, using Modula-2 language & compiler, back in 1985.

A PC can have foreground and background processes because it has more than one processor.

Rarely, I have to disagree with you. Lots of PC's have only one processor, and they manage to have foreground and background processes, just fine.

You can run Unix on a PDP-11. The first machine I ever saw running Unix was a PDP-11.

michinyon:
You can run Unix on a PDP-11. The first machine I ever saw running Unix was a PDP-11.

Sure it wasnt a PDP-11 based VAX ?