Solved: reading PWM signal: the "noInterrupts()" function crashes my code!

panther3001:

  1. On a side note, is the way that I am reading in the PWM pulses a smart way of doing things, or would you recommend another approach?

I'd like to see your new code. I wouldn't be turning interrupts off like that.

  1. Also, even though this may be a silly way of doing it, how precise (& accurate) can you get simply by calling the digitalRead command as fast as possible in a loop while looking for a change in the value, as a way to detect rising & falling edges?
    --I haven't tried this yet, but I suppose I could try it just to see what happens.

If you are doing nothing else, a tight loop can be faster than interrupts. However you would have to turn off timer interrupts, in which case you wouldn't know the time between pulses.

  1. Lastly, how does attachInterrupt detect a rising or falling edge on a pin? I understand this is somehow "done in the hardware," but I have no idea what that means. It seems there is some hysteresis in the sampling anyway, slightly skewing the time an edge is detected.

attachInterrupt doesn't detect edges, it turns on the interrupt hardware. Once the programmed edge arrives (eg. rising, falling or both) then the interrupt is noted for processing when possible. When that is depends on what else the processor is doing (eg. if interrupts happen to be off right now because it is handling a timer interrupt).

You can use the timers hardware to detect exact distances between edges, see:

However a bit depends on how precise it needs to be. Surely the RC system doesn't operate at the nanosecond level?