Cannot enable or set duty cycle on PWM channel

Hello,

I have a persisting issue with the Navio2 boards. I want to initialise 8 channels on the servo rail for using them as PWM outputs. I am setting the up in QtCreator. I cannot enable all the 8 channels, but maximum 2 of them (and even these 2 sometimes do not work). I have set the QtCreator to run the program in terminal, as the initialisation ALWAYS fails if I run the program normally.

I am using Raspberry Pi Model 3B with Emlid Raspbian from 2017, updated and upgraded to the latest version.

here are some messages from some commands in the terminal:

sudo vcdbg log msg 2>&1 | grep -C5 rcio

002214.833: dtparam: spi=on
002282.301: Loaded overlay ‘spi0-4cs’
002350.276: Loaded overlay ‘spi1-1cs’
002350.291: dtparam: cs0_pin=16
002351.094: dtparam: cs0_spidev=disabled
002420.252: Loaded overlay ‘rcio’
002456.346: Loaded overlay ‘navio-rgb’
002456.380: dtparam: i2c1=on
002466.668: dtparam: i2c1_baudrate=1000000
003506.431: Device tree loaded to 0x2effb200 (size 0x4d8c)
003512.008: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined

dmesg | grep rcio

[ 4.599884] rcio_core: loading out-of-tree module taints kernel.
[ 4.626700] rcio spi1.0: rcio_status: Firmware CRC: 0xb09979ae
[ 4.627780] rcio spi1.0: rcio_status: Board type: 0x0 (navio2)
[ 4.628697] rcio spi1.0: rcio_status: Git hash: dae830a
[ 4.629946] rcio spi1.0: rcio_pwm: Advanced frequency configuration is suppor ted on this firmware
[ 4.632632] rcio spi1.0: rcio_pwm: updated freq on grp 0 to 50
[ 4.633537] rcio spi1.0: rcio_pwm: updated freq on grp 1 to 50
[ 4.637355] rcio spi1.0: rcio_pwm: updated freq on grp 2 to 50
[ 4.638343] rcio spi1.0: rcio_pwm: updated freq on grp 3 to 50
[ 4.653493] rcio spi1.0: rcio_pwm: PWM probe success
[ 4.654721] rcio spi1.0: rcio_gpio: GPIO is supported on this firmware
[ 4.654773] rcio spi1.0: rcio_gpio: registered gpio module
[ 4.655323] rcio spi1.0: rcio_gpio: gpiochip added successfully under gpio500

ls /boot/overlays/rcio*

/boot/overlays/rcio.dtbo

lsmod

Module Size Used by
fuse 95787 3
bluetooth 528706 0
binfmt_misc 10972 1
rcio_spi 3185 0
rcio_core 28929 1 rcio_spi
spidev 8534 0
brcmfmac 290629 0
brcmutil 10583 1 brcmfmac
cfg80211 576971 1 brcmfmac
rfkill 20614 4 bluetooth,cfg80211
i2c_bcm2835 7231 0
spi_bcm2835aux 5655 0
spi_bcm2835 8118 0
bcm2835_gpiomem 3900 0
uio_pdrv_genirq 3885 0
fixed 3563 0
uio 10268 1 uio_pdrv_genirq
i2c_dev 8759 0
ip_tables 13314 0
x_tables 21300 1 ip_tables
ipv6 414219 32

uname -a

Linux Drive_Module 4.9.45-94f47ec-emlid-v7+ #4 SMP PREEMPT Wed Aug 30 18:17:43 M SK 2017 armv7l GNU/Linux
pi@remote:~ $ sudo vcdbg log msg 2>&1 | grep -C5 rcio
002350.291: dtparam: cs0_pin=16
002351.094: dtparam: cs0_spidev=disabled
002420.252: Loaded overlay ‘rcio’
002456.346: Loaded overlay ‘navio-rgb’
002456.380: dtparam: i2c1=on
002466.668: dtparam: i2c1_baudrate=1000000
003506.431: Device tree loaded to 0x2effb200 (size 0x4d8c)
003512.008: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
002214.833: dtparam: spi=on
002282.301: Loaded overlay ‘spi0-4cs’
002350.276: Loaded overlay ‘spi1-1cs’
002350.291: dtparam: cs0_pin=16
002351.094: dtparam: cs0_spidev=disabled
002420.252: Loaded overlay ‘rcio’
002456.346: Loaded overlay ‘navio-rgb’
002456.380: dtparam: i2c1=on
002466.668: dtparam: i2c1_baudrate=1000000
003506.431: Device tree loaded to 0x2effb200 (size 0x4d8c)
003512.008: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined

If you have any ideas of how I can solve this issue, please let me know.

Many thanks,
minu

by repeatedly checking dmesg I have noticed the following error occuring when the one PWM pin is not initialised:

[ 1028.524628] rcio spi1.0: rcio_pwm: Exporting error: you have some of PWM outputs running. Stop them to change pin configuration.

I have noticed that there is no way for closing and reopening the PWM channel in the libraries provided. Would that make sense?

Hi, Minu!
Thanks for reaching out! Could you please provide me with some details listed below so that I can understand your problem better?

  1. What exactly does your program to initialise PWMs?
  2. I assume that ardupilot is not running, but if it is so, stop ardupilot and try once more.

Hey Kirill,

  1. I basically create a RC_Navio2 object an run the following commands at initialisation:

if(_pwm->initialize(channel))
{
_pwm->set_frequency(channel,50);
_pwm->enable(channel);
_pwm->set_duty_cycle(channel,initialValue);
}

I managed to find a workaround by giving some seconds of delay in between the initialisation of the other PWM pins. I am not sure if it is ok or not.

  1. Unless ardupilot is launched at startup, I haven’t started it. I can’t see it when issuing top command

Did you try to initialize pwm manually via sysfs? What is the output of ls /sys/class/pwm/pwmchip0?

Hi,

Have you resolved the issue?

Did you try to initialize pwm manually via sysfs?

no I didn’t

What is the output of ls /sys/class/pwm/pwmchip0?

the output is:

device  npwm   pwm0  pwm2  pwm4  pwm6  subsystem  unexport
export  power  pwm1  pwm3  pwm5  pwm7  uevent

Hey there,

It’s more likely that you have this issue due to a safety feature. PWM values are set to 0 if there are no updates for 100 ms. So it’s necessary to write the same value to set_duty_cycle every 100 ms or less to make it works.

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