What happens when the MCU hangs, does PWM continue to pulse?

What happens when the MCU hangs, does PWM continue to pulse?

I'm taking care of a worse case scenario where I have a pwm output that I would want to continue in case the mcu hangs

before you reply, I've used:

  1. Watchdog timer (bootloader change on the nano)
  2. Hardware watchdog

But I just want to know if anyone knows for sure what happens if the MCU hangs while pwm is on.

What happens when the MCU hangs, does PWM continue to pulse?


You presume that there is one type of "hang" - why do you presume that that's the case?

If the hang is due to a bug in the code that causes it to, say, end up in a loop that it doesn't escape from - sure the PWM will keep going. If you write out of bounds of an array, and it ends up hung instead of resetting - probably, unless it happens to scribble over the timer registers (which are in the same address space as the RAM) before it ends up hung... Though writing outside an array usually ends up resetting the processor, rather than hanging.

If the hang is caused by hardware causes (ex, a glitch on the power rails, electromagnetic interference, etc), the chip is in a non-functioning state, and all bets are off. I think in many cases it would continue, but this isn't guaranteed.

You cannot guarantee PWM will continue when hung; you should fix your design so that it doesn't hang. A properly designed system will run for months or years without any sort of hang (I have several AVRs that have been running.... since the last time there was a power outage, I guess... without issue)

Agreed. A properly designed system would allow for it to run for eternity.
But I've seen code in a STD arduino libraries that i had to change myself to prevent hanging (this is with I2C device comms, would hang if encountered static or EMI or some sort of noise on the line). So I've concluded that there are still bugs somewhere and the system would probably hang, eventually.