Create PWM signal at 20Hz base frequency

Is it possible to implement a PWM signal with the base frequency at 20Hz with an arduino Mega? I understand that the PWM pin frequency can be changed by using the timers to create different frequencies, but only in discrete steps that don't include 20Hz. Is there another approach for this?

My sketch uses serial communication to extract a variable from a packet with a delay between reads, and uses the PID Library with a delay between successive control outputs.

I also thought about using an external board that accepts a 0-5v signal and provides 12v, 20hz PWM output, but I haven't been able to find such a board (I've seen products that have manual settings for frequency (which is fine) and duty cycle, but none that have terminals for an external duty cycle signal.

Is there a good reason not to choose the closest step?

Yes, the lower the frequency, generally the higher the possible resolution. At 20Hz your actual frequency resolution is governed more by the accuracy of the MCU clock circuit, than timer hardware.

The clock circuit on a Mega is usually a resonator, which is a horribly inaccurate time base.

What is your frequency accuracy specification target?

20 Hz freq is so low, that you simply can generate PWM without timers, just with millis in the code.

Almost. micros().

What will be the source of this signal? Mega does not know how to create a 0-5v signal because it does not have DAC. It only can produce PWM, so the external board should be analyze it first for converting to 12v 20 Hz PWM...

In fact, using a 16 bit timer on the Mega, it is possible to create 20.0000 Hz PWM, with accuracy specified by the tolerance of the MCU clock crystal.

You can try to use my AVR_Slow_PWM library, designed for very low ( < 500Hz) PWM frequencies to see if OK for you.

Is there a good reason not to choose the closest step?

I think so... I know that the device I'm controlling will work at that frequency.

I am only guessing, but I think 1-2% would be OK.

I don't understand this comment; all the timing examples I've seen use millis in the code.

Then they are amateurs. micros() will be almost 100 times more accurate. A good reason to use millis() instead of micros() is that the maximum time interval is 1000 times longer. But it's not needed to time 50ms.

The worst case resonator deviation is more than that. It can run 3%.

Thank you; I did not know that. I suppose a board that accepted a serial value for duty cycle would work if there were such a board.

The solutions are falling around the target. Now we really need to know the details of your project so we don't spin our wheels. What is this thing, why do you need this function, how does it work?

Arduino is such a board...

Well, here we go....
The project is to control an electric-viscous fan clutch for a vehicle. I will read the coolant temperature from a serial output packet provided by the fuel injection ECM, create a controller output using the PID library, and then (somehow) send a 12V, 20Hz PWM duty cycle signal to the clutch. A commercial version is available that takes a 'fan on' signal from the ECM and outputs a PWM signal based on manual settings of frequency and duty cycle. That signal is passed to a mosfet driver board that provides power to the solenoid in the electric-viscous clutch.

Thank you; I will look at that.

What does the fan clutch data sheet say about the required accuracy of the 20 Hz PWM frequency?

Great! Can you point me to more info?