arduino / arduino/ArduinoCore-mbed

analogWrite does not work well with Arduino RP2040 board

Open
#1,079 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Hi!

I wanted to do something really simple. Having several LEDs controlled by PWM.
Everything was working very weird with analogWrite so I tried several boards and reduced the setup to the minimal.
It is really easy to reproduce, just put one LED on D8 and one another on D12 with appropriate pull-down resistors.
Use this simple two lines of code into the setup function which only use analogWrite to lit up the LEDs to independant values.
`analogWrite(8, 255);`
`analogWrite(12, 0);`
and
`analogWrite(8, 0);`
`analogWrite(12, 255);`

When applying those PWM, the last one is always taken for both LEDs.
It behaves exactly like there was an overwrite of the first one by the second one.
Using only digitalWrite works well to lit up one LED and not the other one and vice versa but if one analogWrite have been used digitalWrite does not work anymore.
I checked the schematics several times, there is no reason why it would do that in hardware.
I believe this is a software bug, but I was not able to find where. I am running with the last board package 4.3.1.
It seems there is the same bug with D17, D18 & D19 while those last ones have pull-ups because they are used by I²C this may explain the link between D18 & D19 but not D17!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the report on an Arduino RP2040 board with the minimal setup using analogWrite on D8 and D12, then compare the behavior with digitalWrite and the reported D17–D19 cases. Trace the ArduinoCore-mbed analogWrite implementation and board pin mappings; done means independent PWM values work on the tested pins and digitalWrite still functions afterward.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.