How to monitor a PWM cycle

I have an Arduino Nano with a PWM connected to A0 or (pin 19) and an L.E.D. connected to pin2/D2.
The PWM has a 90% conduction angle or duty cycle. This condition is normally constant and preferred.
However, when this condition gets interrupted and/or stops for over 5 seconds (for example)
I would like to output a signal from another pin to turn on an L.E.D. thus indicating that the
PWM has been interupted and/or stopped. The stopped PWM will either stop on a logic HIGH or 1,
or a logic LOW or 0 either way.

It surely seems that I am not the first to do this, but browsing the internet all indications are this is something unusual
or at the least not widely done. This does not appear to be one of the standard Arduino EXAMPLES. Too bad.
I am normally able to solve my Arduino problems by doing a wide internet search but apparently not this time.

I have just signed up/registered on the Arduino website for just this problem.
I have tried looking at the if statement, for loop, pulseIn(), attachInterrupt() and others.
Does anybody here know of anyone who has done something like this?
If not could you please tell me this is not normally done, or you have never heard of anyone doing something like this.


This is essentially what I am trying to do:
using pinMode INPUT
if( sensor_1 constantly reads logic 0 || sensor_1 constantly reads logic 1)
then using using pinMode OUTPUT turn LED_A on.

How many Arduinos? If you only have one then the program only does what you tell it to do: PWM can't stop by itself.

If you are using one Arduino to monitor the PWM output of another, then you have a project.

pulseIn() would be my first choice. It's not greatly useful in a large program because it can just lock up your code for a whole second but as a monitor that's not doing anything else, it's perfect.

There a certainly times when you don't want pwm to fail, for instance if you are overdriving a multiplexed display but, as has been pointed out, an Arduino cannot really be trusted to monitor itself.
The nearest you get is the watchdog timer.
Maybe if you say exactly what you are doing, you get some other suggestions.

Maybe if you say exactly what you are doing, you get some other suggestions.

What is the frequency of the pwm signal applied to A0?
Is the Arduino doing any thing other than monitoring this signal?
Where are the pwm pulses coming from?

If it is an external PWM you are reading with the Nano, you also have the option of using code similar to the snippet below (not optimised):

loop() {
   . . .
   if ( pwm_pin_status_change_detected ) {
      if ( pwm_pin is HIGH ) highAtMs = millis() ; 
      else lowAtMs = millis() ;
   } 

   if ( millis() - highAtMs > maxInterval || millis() - lowAtMs > maxInterval ) AlarmLedPin = HIGH ;
   else AlarmLedPin = LOW ;
   . . .
}

you also have the option of using code similar to the snippet below

Will millis() provide the necessary granularity? Or, will micros() be required?

PaulS:
Will millis() provide the necessary granularity? Or, will micros() be required?

Good point. I thought of that, but since he gave an example of 5 seconds failure condition before an alarm signal in this case millis() should be enough. Depending on the "maximum failure condition tolerance time" he could optimise the code snippet by doing the expiry test only periodically instead of every loop iteration.