Seeed-Studio / ArduinoCore-samd

49 stars 27 forks source link

TCx PWM not working correctly #52

Closed josephduchesne closed 3 weeks ago

josephduchesne commented 3 years ago

I'm trying to use pwm() on TC4 (D6 on the Seeduino Xiao), but the duty cycle is being calculated incorrectly in wiring_pwm.cpp line 271:

duty = mapResolution(duty, 10, 16);

For samd51 TCx and TCCx, as well as SAMD21 TCCx, it's using:

duty = map(duty, 0, (1<<PWM_API_RESOLUTION), 0, period);

The result is that the counter (in my case duty period = 2000) is being incorrectly.

I've changed the line to match the others and it works fine for my single use case.

@deanm1278 since this was in your original PR, any idea why TCx is treated differently?

sdkks commented 3 years ago

I was looking at this https://github.com/Seeed-Studio/ArduinoCore-samd/pull/23, then saw this issue as well. I was intending to use the PWM to control motor but I noticed that on oscilloscope that duty cycles are inaccurate. Same device, Xiao (SAMD21)

Lesords commented 1 month ago

Hello,

I'm very sorry to have kept you waiting so long.

Do you still have this problem now?

Lesords commented 3 weeks ago

Hello,

I\'m going to close this issue, feel free to re-open it if you have any other questions.

[Autocommentary]