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