high-frequency PWM

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
rgcoldeman
Posts: 14
Joined: Sat Jan 30, 2021 11:18 pm

high-frequency PWM

Post by rgcoldeman » Sat Jan 30, 2021 11:21 pm

There seems to be a minor bug in ports/rp2/machine_pwm.c which gets the frequency wrong. The offending line is "uint32_t div16_top = 16 * source_hz / freq;", where a "-1" should be added.
It does not matter much at low frequencies, where the value of 'TOP' is high so 1 more or less doesn't matter much. But in the MHz range the value of TOP is small and 1 more or less changes everything. To get 62.5 MHz, I need to ask for 125MHz. To get 41.67MHz, ask for 62.5MHz, to get 31.25MHz, ask for 41.67MHz, to get 25MHz, ask for 31.25MHz.

Post Reply