Multichannel PWM with the Spresense SDK
-
Hi,
I have been working on a line following robot with the Spresense camera as the sensor. I have succesfully merged the two examples provided by Sony (DNNRT and the Camera example). Now I want to use PWM to control the motors so that I can configure it's speed. I have been looking into different solutions, but could not find any helpful resources on PWM with 2 channels.-
I have tried using the PWM example itself and get it to work first. Single channel works like a charm. Sadly I could not find any information about how to enable multi channel operation (there is no information on it on the documentation of the example). I need 2 PWM outputs for 2 motors. The multi channel code is locked behind a parameter called "CONFIG_PWM_MULTICHAN". I have looked at the menuconfig, Kconfig file, the pwm.h library, the config file which defines what to include. I can not find how to enable this option.
-
That is why I decided to delete all instances of this parameter "CONFIG_PWM_MULTICHAN" and all the single channel code with it to force the code to be multi channel. I now get errors every step of the code when I run it.
-
I also tried using the cxd56_pwm.h library and the cxd56_pwm.c file with the functions to create PWM objects (lower half) and use that object to control pwm with the given functions in cxd56_pwm.c such as pwm_setup, pwm_begin, etc.
I would appreciate it, if I could be pointed towards a way to get PWM working as easy as possible. What would be the best way to use PWM functions? Is there a dedicated library for it? Thanks in advance.
-
-
Hi @Berkay-Isik
Spresense has 4 PWM with 1 channel each:/dev/pwm0
- pin 6
/dev/pwm1
- pin 5
/dev/pwm2
- pin 9
/dev/pwm3
- pin 3If you want 2 PWM outputs, you need to open two devices (
open()
) and then callioctl()
on each of them.You can look at the PWM implementations in CircuitPython: https://github.com/adafruit/circuitpython/blob/main/ports/cxd56/common-hal/pwmio/PWMOut.c
I hope it will help. If anything is unclear please ask.