Skip to content

PWM random inversion #146

Closed
Closed
@stephenf7072

Description

@stephenf7072

Subject of the issue

Analog output pin PWM waveform sometimes comes out as inverted.

A hack fix is to call am_hal_ctimer_clear(timer,segment) before/inside analogWrite, works for a single pin, I have not tested on multiple pins. I looked at this in some detail and it's a little beyond me for now, but I gather it's got to do with the Ambiq SDK changing from 2.2 to 2.3+, and they have made some kind of fix for it.

As an addition, the PWM frequency (about 180Hz) is low enough to cause buzzing on my peripherals, an option to change it would be really awesome.

Some related stuff here:
https://forum.sparkfun.com/viewtopic.php?f=170&t=51506&p=212699&hilit=analogwrite#p212699

Your workbench

Arduino IDE 1.8.12 on Windows 10. Core 1.0.30 (latest as at 31/3/2020)

Steps to reproduce

set up PWM pin to drive an LED
set PWM in a while loop - no issue, apparently
set PWM once each loop - random inversion

Expected behaviour

Write 25% (ie. 64 of 255), LED is dim

Actual behaviour

LED is bright (ie. 75%)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions