arduino / arduino/ArduinoCore-renesas
analogWrite on R4 boards generates spikes
- Dominant language
- C
- Stars
- 193
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
An arduino program trying to use `analogWrite()` to accurately generate a waveform suffers from a lot of brief spikes. I noticed these when trying to make a low frequency triangle wave. A recent [Playduino YouTube video](https://www.youtube.com/watch?v=kRP8cxKv6lk) (by @olivereybel) shows these although it's possible they aren't shown in full by the oscilloscope. Even setting the midpoint value repeatedly can do this.


A more advanced oscilloscope shows this for a sine wave.

Perhaps the issue discussed in [the "Hairy output on R4 DAC" forum topic](https://forum.arduino.cc/t/hairy-output-on-r4-dac/1159716) was never fixed? @TriodeGirl provided some code to deal with this in https://github.com/TriodeGirl/Arduino-UNO-R4-code-DAC-ADC-Ints-Fast_Pins/
Arduino Forum discussion: [Spikes on UNO R4 DAC output using analogWrite()](https://forum.arduino.cc/t/spikes-on-uno-r4-dac-output-using-analogwrite/1368611)
---
Other analogWrite issues:
- https://github.com/arduino/ArduinoCore-renesas/issues/388
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the analogWrite() implementation for UNO R4 DAC output and reproduce the reported spikes with the waveform and repeated midpoint writes described here. Compare the behavior with the linked Hairy output on R4 DAC forum discussion and TriodeGirl's referenced code; done means confirming the cause and eliminating the brief spikes without breaking analogWrite output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100