Commit Graph

6 Commits

Author SHA1 Message Date
Paul Grayson
f0f5c6568d rp2/machine_pwm: Fix overflows with freq > 268 MHz.
There were several places where 32-bit integer could overflow with
frequencies of 2^28 Hz or above (~268 MHz).  This fixes those overflows and
also introduces rounding for more accurate duty_ns computations.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
2023-01-12 16:28:12 +11:00
Paul Grayson
b5823604a0 rp2/machine_pwm: Use more accurate formulas for freq and duty_u16.
This changes the freq() and duty_u16() functions to use more simpler, more
accurate formulas, in particular increasing the frequency accuracy from a
few percent to a fraction of a percent in many cases.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
2023-01-12 16:28:00 +11:00
robert-hh
01d9b7adde rp2/machine_pwm: Keep duty value when changing the frequency.
The duty is saved and set whenever the frequency is changed, unless the
duty rate was not set yet.
2022-01-06 13:52:45 +11:00
robert-hh
9e56e630ca rp2/machine_pwm: Fix PWM frequency setting.
The top value was off by 1: in order to count n ticks it has to be set to
n-1.

Fixes issue #8122.
2022-01-06 13:51:19 +11:00
Damien George
af64c2ddbd extmod/machine_pwm: Factor out machine.PWM bindings to common code.
This commit refactors machine.PWM and creates extmod/machine_pwm.c.  The
esp8266, esp32 and rp2 ports all use this and provide implementations of
the required PWM functionality.  This helps to reduce code duplication and
keep the same Python API across ports.

This commit does not make any functional changes.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-04 16:31:17 +10:00
Damien George
469345e728 rp2: Add new port to Raspberry Pi RP2 microcontroller.
This commit adds a new port "rp2" which targets the new Raspberry Pi RP2040
microcontroller.

The build system uses pure cmake (with a small Makefile wrapper for
convenience).  The USB driver is TinyUSB, and there is a machine module
with most of the standard classes implemented.  Some examples are provided
in the examples/rp2/ directory.

Work done in collaboration with Graham Sanderson.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00