AnalogWrite suggestion.

Im looking at the wiring_analog.c file and I noticed that if val == 0 it outputs LOW as a digital signal and if val == 255 the output is digital HIGH. I see that if val is not 0 or 255, it goes to the timer. Usually we need to map the input signal to 0 and 255 because you get weird data if the input is less than or greater than 0 and 255.

I believe this was the result of a patch several years ago to the original analogWrite function where if you did a analogWrite(pin#,0); instead of a pure 0% duty cycle you actually got a duty cycle that had one timer bit time of HIGH. This could easily be seen with a scope on the output pin, so they decided to just patch the function to digitalWrite a hard LOW if a 0 duty cycle value was sent to the function. Not sure why the clamp for the 100% value also but I'm sure it's related to the hardware timer behaviour.

Lefty