arduino / ArduinoCore-renesas

MIT License
113 stars 79 forks source link

AnalogWrite creates a PWM when value is 255 #388

Open jpcornil-git opened 4 weeks ago

jpcornil-git commented 4 weeks ago

On legacy arduino platforms, when analogWrite value is 255, you get a DC/HIGH output (aliased to digitalWrite HIGH), see:

https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring_analog.c#L110

While on UNO R4/renesas platform, 255 is converted to 255/256 and you get a PWM signal, see: https://github.com/arduino/ArduinoCore-renesas/blob/main/cores/arduino/analog.cpp#L819

To match behavior, value should either be normalized to 255 ((1 << _writeResolution) - 1) or aliased to a digitalWrite as well

jpcornil-git commented 4 weeks ago

Workaround for this one is to use digitalWrite(pin, HIGH) (following a pinMode(pin, OUTPUT) to address #58) but it is not very clean