arduino / arduino/ArduinoCore-renesas

analogWrite on R4 boards generates spikes

Open
#460 2 comments 0 reactions 0 assignees View on GitHub
topic: code type: imperfection
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.

![Arduino UNO R4 Minima DAC 8bit 127 value repeatedly set](https://github.com/user-attachments/assets/ddcd2b53-8a31-4a8d-8571-d2d4e9180fb8)

![Arduino UNO R4 Minima DAC 12bit sine wave](https://github.com/user-attachments/assets/b7521053-8d47-4436-82bf-6bff03ebd5d5)

A more advanced oscilloscope shows this for a sine wave.

![Image](https://github.com/user-attachments/assets/1b45cca3-5508-48ec-9991-659407bd5818)

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.