Hi!
I'm using pin 9 from Timer 1 on an Arduino Uno to generate a pwm (Fast_PWM) signal. I could use Pin 10 also.
But I need a way to count some x pwm pulses (or the elapsed time from that number of pulses) from that pin and then disable that pwm output, and then re-enable it after some more pulses or after some elapsed time again, in order to to have some skipped pulses in the pwm output.
I need to be able to get what's in the picture below, taken from a motor driver I have, that I'm trying to emulate.
I saw some posts about counting PWM pulses, but they are not really adapted to my case...
How could this pwm skipped pulses be done?
Do I have to connect the pwm output pin to another digital pin so this other pin can read the pulses? Or from the Timer1 itself it can be done without the need of an extra digital pin?
Another idea I had, that I could implement in hardware is the following, to generate this adjustable PWM pulse skipping idea:
-
Connecting my pwm output pin (Pin 9) to an Arduino digital INPUT pin, let's say, pin 5, for counting the pwm signals
-
Connect the same pwm output pin (Pin 9) to the source pin of a P-Mosfet, and the drain of the mosfet to the motor driver pwm INPUT.
-
The gate of this mosfet would be pulled high (so it's turned off) and connected to an OUTPUT Arduino digital Pin, let's say pin 6.
-
Then, pin 5 would continuously read and count the pwm pulses from the pwm output Pin 9
-
And pin 6 would turn off the gate of the P-Mosfet (that "transfers" the pwm signal to the motor driver) as soon as x number of pulses are read from pin 5.
-
Pin 5 would still be reading the pwm pulses being generated from Pin 9. After more x number of pulses, it would then turn on again the gate of the P-mosfet and allow the pwm signal to keep going to the motor driver...
Is it a correct idea? Feasible? Or the first one, using timers (which I have no experiece at all) is a simpler way?
Anyone could help me implement it in code? I'm not into direct registers/interrupts coding...
Thanks!