RP2040_PWM Library

Continue from


Releases v1.2.0

  1. Add efficient setPWM_manual() function to use in wafeform creation using PWM. Check Duty cycle as integer rather than float #6
  2. Add example PWM_Waveform to demonstrate how to use new setPWM_manual() function in wafeform creation
  3. Optimize library code and examples by using reference-passing instead of value-passing.

Releases v1.1.1

  1. Fix compiler warnings.
  2. Display informational warning when _PWM_LOGLEVEL_ > 3

Releases v1.1.0

  1. Permit PWM output for both channels of PWM slice. Check Request for Clarification on PWM Slices and A/B sides #5
  2. Use float instead of double for frequency and duty-cycle
  3. Add example PWM_MultiChannel to demonstrate how to use both channels of PWM slice.

Releases v1.0.5

  1. Permit changing dutyCycle and keep same frequency on-the-fly. Check Attempting to Alter the Duty Cycle w/o changing any other values #3
  2. Add example PWM_DynamicDutyCycle to demonstrate new feature
  3. Add support for more boards using arduino-pico core, such as ADAFRUIT_ITSYBITSY_RP2040, CYTRON_MAKER_NANO_RP2040, SPARKFUN_PROMICRO_RP2040, CHALLENGER_2040_WIFI_RP2040, ILABS_2040_RPICO32_RP2040, MELOPERO_SHAKE_RP2040, SOLDERPARTY_RP2040_STAMP, UPESY_RP2040_DEVKIT, WIZNET_5100S_EVB_PICO, etc.
  4. Display compiler informational warning messages only when _PWM_LOGLEVEL_ > 3

Releases v1.0.4

  1. Fix platform in library.json

Releases v1.0.3

  1. Not reprogram if same PWM frequency.
  2. Add PIO strict lib_compat_mode

Releases v1.3.0

  1. Add setPWM_manual(pin, level) function for efficiency in wafeform creation using PWM. Check Duty cycle as integer rather than float #6
  2. Add example PWM_Waveform_Fast to demonstrate how to use new setPWM_manual(pin, level) function.
  3. Add setPWM_Int() function for optional uint32_t dutycycle = real_dutycycle * 1000. Check Duty cycle as integer rather than float #6
  4. Add example PWM_DynamicDutyCycle_Int to demonstrate how to use new setPWM_Int() function.
  5. Rewrite many functions to take advantage of new features.
1 Like

I REALLY appreciate your library and examples. I'm a little new to this (Arduino coding) and I'm having some trouble integrating your examples into my needs.
I'm attempting to build a small robot car, 2 motors, motor controller encoders and PID. I'm in sore need to change the PWM freq as motors growl if not supplied with the correct frequencies. They like 1.6K.
I've had some experience with Adafruit products and their Motor shield. I can change the frequency in the code. But arduinos are slower and don't have the IO Pins this litttle jewel RP2040 has. I'm thinking your example concerning Dynamic Duty Cycle show be my focus because of the change in duty cycles this project needs.
I found no reference about changing the frquency in using the analogwrite() function in arduinos.
Could you give me some guidance?
Bo Moffett

Hi @bodat861

You can't use analogwrite() function to change frequency while using this library. Please have a look at the example PWM_DynamicFreq and you'll see how to change the frequency (from 7.5Hz up to 62.5MHz) by using the following function

bool setPWM(const uint8_t& pin, const float& frequency, const float& dutycycle, bool phaseCorrect = false)

Good Luck,

oh I see.
Thank you for the help!
Bo

Hi,
I need to use the Raspberry to measure frequencies. Does this library allow to use PWM input as a pulse counter or frequency measurement?

No.

It's better to use pin interrupt, or RPI_PICO_TimerInterrupt / MBED_RPI_PICO_TimerInterrupt library for that purpose.

Thanks for your reply.
I tried to use attachinterrupt and when I change state with one pin and read it with the other it works.
But when I connect an external signal (about 250kHz), at the moment of connection the program stops sending readings by serial communication. After disconnecting the external signal, communication comes back and the "overdue" pulses are read.

Please check if you have the same issue here (PULL_UP resistor)

This sounds really nice is it possible to phaseshift the pwms in relation to each other?
So I want pwm0 start at 0 turn off at 10 pwm1 start at 20 stop at 30 and so on.

Releases v1.4.0

  1. Fix glitch when dynamically changing dutycycle. Check Changing Duty Cycle Dynamically Creates Runt PWM pulse #10
  2. Adjust MIN_PWM_FREQUENCY and MAX_PWM_FREQUENCY dynamically according to actual F_CPU
  3. Update examples

Releases v1.3.1

  1. Add minimal example PWM_Basic. Check added minimal viable program to get the user up and running #9

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.