[RP2040] How to Adjust PWM Frquency on a Certain Pin?


Hi, I’m trying to control a servo motor with uLisp on an RPi Pico. The motor expects the PWM frequency to be 50Hz. Directly using analogwrite makes it rotate erratically, and I wonder if it is because the frequency is wrong.

In MicroPython you can set the PWM frequency on a pin:

from machine import Pin, PWM
servo = PWM(Pin(16))
servo.freq(50)  # 50Hz, pulses every 20ms

How do I adjust the PWM frequency like this in uLisp? Thanks!


uLisp doesn’t currently implement a function to allow you to change the PWM frequency, but you could add your own calls to the Arduino core as described here:

Adding your own functions

I’ve had a look at the reference for the RP2040 Arduino core, and it seems that there is the function you need:

void analogWriteFreq(uint32_t freq)

However, the lowest frequency it supports is 100Hz.

A better bet might be to implement uLisp functions to give access to the Servo library:

Servo library

I’d be happy to give some help if you get stuck.


Thanks for letting me know. Will definitely learn more and look into this!