How to detect no interrupt? CNC router rpm PID control

Hi

I am developing a PID Rpm control for my 450w DC spindle to work with GRBL which outputs a 0-5V PWM signal corresponding to rpm requested by G code.

I have a working program but with many bugs.

The bug:

Using an interupt to detect incoming PWM signal then a loop to calculate duty cycle and translate that to desired rpm.

This works well until the 0 rpm is requested (which drops the incoming PWM signal back to 0 volts)

0 is not detected and the target rpm remains at the last positive value.

Im aware that using some kind of timing routine could be a solution to this but Im not sure how to accomplish it.

I have attached the ino file too.

ATTEMPT_3.ino (6.23 KB)

Im aware that using some kind of timing routine could be a solution to this but Im not sure how to accomplish it.

How would YOU detect that nobody (was going to) reply to your post? Would you assume that 10 years was a reasonable time to wait? 10 weeks? 10 days? 10 minutes? 10 seconds? 10 microseconds?

What is your minimum RPM? At line 117 you might try:

rpm = 60 * (frequency / pulserev);
if(rpm < MIN)
  rpm = 0;

Pffabrications:
Using an interupt to detect incoming PWM signal then a loop to calculate duty cycle and translate that to desired rpm.

This works well until the 0 rpm is requested (which drops the incoming PWM signal back to 0 volts)

0 is not detected and the target rpm remains at the last positive value.

If you note the time of each interrupt and if the interval between interrupts is too long you will know that the stream of pulses has stopped. I use that to detect when a small DC motor stalls.

You have not told us what computer is interpreting GRBL and producing the PWM signal? If you could modify the program so it just sends the number - such as 0 - 255 - it would make life much easier.

...R