You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Petro Karashchenko <pe...@gmail.com> on 2022/05/16 16:36:24 UTC

Anyone using SAMv7 PWM?

Hello,

Recently I've tried to use PWM on SAMe70 based board. I tried to execute
PWM example from apps. The PWM on SAMv7 seems to be not functional, at
least I observe only that pin goes high when PWM start is executed and the
goes to low when PWM stop is executed.

Is anyone using PWM with SAMv7 based board? Maybe I'm missing something?

Best regards,
Petro

Re: Anyone using SAMv7 PWM?

Posted by Petro Karashchenko <pe...@gmail.com>.
Hello team,

Me and Michal are having a discussion in comments to
https://github.com/apache/incubator-nuttx/pull/6298

The point of discussion is a PWM multi-channel mode. For PWM multi-channel
mode we are having CONFIG_PWM_NCHANNELS that is a "Number of Output
Channels Per Timer" and "struct pwm_info_s" is equipped with
CONFIG_PWM_NCHANNELS number of
struct pwm_chan_s
{
  ub16_t duty;
  int8_t channel;
};

But unfortunately we both fail to find a description of "struct pwm_chan_s"
channel values. The usage in code is not the same for different
implementations.

Per my understanding the "struct pwm_info_s" is an interface structure
between application and the driver, so the application should not have any
idea about the HW specifics of implementation (HW channels that are used)
and is carrying the "virtual" PWM channels from 1 to 16.
On the other hand, the PWM driver should map those "virtual" channels to HW
channels. For example CONFIG_PWM_NCHANNELS is 2 and the board has pins of
HW channels 5 and 6 routed to the connector. So there are 2 HW channels
that are 5 and 6 and an application update of 1 and 2 virtual channels will
lead to an update of HW channels 5 and 6.

Is my understanding correct? Maybe somebody can point me to the description
of PWM multi-channel mode?

Best regards,
Petro


чт, 19 трав. 2022 р. о 01:56 Petro Karashchenko <
petro.karashchenko@gmail.com> пише:

> Hello Michal,
>
> Please participate in the review of
> https://github.com/apache/incubator-nuttx/pull/6298
> I would appreciate it if you can try if changes work for you.
>
> Looking forward receiving feedback from you.
>
> Best regards,
> Petro
>
> ср, 18 трав. 2022 р. о 16:33 Petro Karashchenko <
> petro.karashchenko@gmail.com> пише:
>
>> Hi,
>>
>> I was able to resolve the issue. Will push patch soon.
>>
>> Best regards,
>> Petro
>>
>> ср, 18 трав. 2022 р. о 16:24 Michal Lenc <mi...@seznam.cz> пише:
>>
>>> Hello
>>>
>>>
>>> > CONFIG_EXAMPLES_PWM=y
>>>
>>> > CONFIG_PWM=y
>>>
>>> > CONFIG_SAMV7_PWM0=y
>>> > CONFIG_SAMV7_PWM0_CH2=y
>>>
>>>
>>>
>>>
>>> I used your configuration options and there indeed seems to be a
>>> problem. I
>>> also wasn´t able to get any PWM output if the driver was configured as a
>>> single channel with CONFIG_PWM_MULTICHAN disabled. The PWM works
>>> if CONFIG_
>>> PWM_MULTICHAN is selected and CONFIG_PWM_NCHANNELS is set as 2 or more.
>>> So
>>> far I am not sure what causes this, my initial debugging did not reveal
>>> any
>>> issues: correct functions are called, correct pin is configured, value
>>> is
>>> written to correct registers etc. Or at least it seems to be correct. I
>>> will
>>> need to take a further look into this during a weekend.
>>>
>>>
>>>
>>>
>>> So far a quick workaround is to enable multiple channel support and set
>>> two
>>> or more channels. The additional channel does not need to have an actual
>>> output, if you set the channel number to 0 it will be skipped. I will
>>> let
>>> you know when I discover what causes this. The driver is mostly a
>>> derivate
>>> from imxRT PWM driver and single PWM worked fine there if I recall
>>> correctly.
>>>
>>> Best regards,
>>> Michal Lenc" "
>>
>>

Re: Anyone using SAMv7 PWM?

Posted by Petro Karashchenko <pe...@gmail.com>.
Hello Michal,

Please participate in the review of
https://github.com/apache/incubator-nuttx/pull/6298
I would appreciate it if you can try if changes work for you.

Looking forward receiving feedback from you.

Best regards,
Petro

ср, 18 трав. 2022 р. о 16:33 Petro Karashchenko <
petro.karashchenko@gmail.com> пише:

> Hi,
>
> I was able to resolve the issue. Will push patch soon.
>
> Best regards,
> Petro
>
> ср, 18 трав. 2022 р. о 16:24 Michal Lenc <mi...@seznam.cz> пише:
>
>> Hello
>>
>>
>> > CONFIG_EXAMPLES_PWM=y
>>
>> > CONFIG_PWM=y
>>
>> > CONFIG_SAMV7_PWM0=y
>> > CONFIG_SAMV7_PWM0_CH2=y
>>
>>
>>
>>
>> I used your configuration options and there indeed seems to be a problem.
>> I
>> also wasn´t able to get any PWM output if the driver was configured as a
>> single channel with CONFIG_PWM_MULTICHAN disabled. The PWM works
>> if CONFIG_
>> PWM_MULTICHAN is selected and CONFIG_PWM_NCHANNELS is set as 2 or more.
>> So
>> far I am not sure what causes this, my initial debugging did not reveal
>> any
>> issues: correct functions are called, correct pin is configured, value is
>> written to correct registers etc. Or at least it seems to be correct. I
>> will
>> need to take a further look into this during a weekend.
>>
>>
>>
>>
>> So far a quick workaround is to enable multiple channel support and set
>> two
>> or more channels. The additional channel does not need to have an actual
>> output, if you set the channel number to 0 it will be skipped. I will let
>> you know when I discover what causes this. The driver is mostly a
>> derivate
>> from imxRT PWM driver and single PWM worked fine there if I recall
>> correctly.
>>
>> Best regards,
>> Michal Lenc" "
>
>

Re: Anyone using SAMv7 PWM?

Posted by Petro Karashchenko <pe...@gmail.com>.
Hi,

I was able to resolve the issue. Will push patch soon.

Best regards,
Petro

ср, 18 трав. 2022 р. о 16:24 Michal Lenc <mi...@seznam.cz> пише:

> Hello
>
>
> > CONFIG_EXAMPLES_PWM=y
>
> > CONFIG_PWM=y
>
> > CONFIG_SAMV7_PWM0=y
> > CONFIG_SAMV7_PWM0_CH2=y
>
>
>
>
> I used your configuration options and there indeed seems to be a problem.
> I
> also wasn´t able to get any PWM output if the driver was configured as a
> single channel with CONFIG_PWM_MULTICHAN disabled. The PWM works if CONFIG_
> PWM_MULTICHAN is selected and CONFIG_PWM_NCHANNELS is set as 2 or more. So
> far I am not sure what causes this, my initial debugging did not reveal
> any
> issues: correct functions are called, correct pin is configured, value is
> written to correct registers etc. Or at least it seems to be correct. I
> will
> need to take a further look into this during a weekend.
>
>
>
>
> So far a quick workaround is to enable multiple channel support and set
> two
> or more channels. The additional channel does not need to have an actual
> output, if you set the channel number to 0 it will be skipped. I will let
> you know when I discover what causes this. The driver is mostly a derivate
> from imxRT PWM driver and single PWM worked fine there if I recall
> correctly.
>
> Best regards,
> Michal Lenc" "

Re: Anyone using SAMv7 PWM?

Posted by Michal Lenc <mi...@seznam.cz>.
Hello


> CONFIG_EXAMPLES_PWM=y

> CONFIG_PWM=y

> CONFIG_SAMV7_PWM0=y
> CONFIG_SAMV7_PWM0_CH2=y




I used your configuration options and there indeed seems to be a problem. I 
also wasn´t able to get any PWM output if the driver was configured as a 
single channel with CONFIG_PWM_MULTICHAN disabled. The PWM works if CONFIG_
PWM_MULTICHAN is selected and CONFIG_PWM_NCHANNELS is set as 2 or more. So 
far I am not sure what causes this, my initial debugging did not reveal any 
issues: correct functions are called, correct pin is configured, value is 
written to correct registers etc. Or at least it seems to be correct. I will
need to take a further look into this during a weekend.




So far a quick workaround is to enable multiple channel support and set two 
or more channels. The additional channel does not need to have an actual 
output, if you set the channel number to 0 it will be skipped. I will let 
you know when I discover what causes this. The driver is mostly a derivate 
from imxRT PWM driver and single PWM worked fine there if I recall 
correctly.

Best regards,
Michal Lenc" "

Re: Anyone using SAMv7 PWM?

Posted by Petro Karashchenko <pe...@gmail.com>.
Hi,

I'm using SAME70-QMTECH board. defconfig file is attached.

In general additionally to standard NSH config I have added:
CONFIG_EXAMPLES_PWM=y
CONFIG_PWM=y
CONFIG_SAMV7_PWM0=y
CONFIG_SAMV7_PWM0_CH2=y

and added to my board.h:
#define GPIO_PWMC0_H2         GPIO_PWMC0_H2_1   /* PD_22 */

The sam_pwm.c is copied from same70-xplained.

I have a logic analyzer connected to GND + PIOD PIN22.
When I run "pwm -t 1" I observe that the signal goes from low to high then
stays high approximately for 1 second and goes back to low.

Best regards,
Petro

пн, 16 трав. 2022 р. о 19:49 Michal Lenc <mi...@seznam.cz> пише:

> Hello,
>
>
>
>
> > Recently I've tried to use PWM on SAMe70 based board. I tried to execute
>
> > PWM example from apps. The PWM on SAMv7 seems to be not functional, at
>
> > least I observe only that pin goes high when PWM start is executed and
> the
>
> > goes to low when PWM stop is executed.
>
>
>
>
>
> what king of configuration have you tried? I tested the configuration
> same70
> -xplained:pysim on a real time control of RC
>
> plant <https://gitlab.fel.cvut.cz/otrees/nuttx-demos/-/tree/master/
> platforms/same70/rc-control
> <https://gitlab.fel.cvut.cz/otrees/nuttx-demos/-/tree/master/platforms/same70/rc-control>
> >
>
> with SAM E70 Xplained board few days ago. You should be able to run a PWM
> example app in this config too.
>
>
>
>
> The pins setup in board level section can be found here:
>
> <
> https://github.com/apache/incubator-nuttx/blob/master/boards/arm/samv7/same
> 70-xplained/include/board.h#L345
> <https://github.com/apache/incubator-nuttx/blob/master/boards/arm/samv7/same70-xplained/include/board.h#L345>
> >
>
>
>
>
> I will double check tomorrow if the configuration does not work for you.
>
>
>
>
> Best regards,
> Michal Lenc
>
> ---------- Původní e-mail ----------
> Od: Petro Karashchenko <pe...@gmail.com>
> Komu: dev@nuttx.apache.org
> Datum: 16. 5. 2022 18:36:49
> Předmět: Anyone using SAMv7 PWM?
> "Hello,
>
> Recently I've tried to use PWM on SAMe70 based board. I tried to execute
> PWM example from apps. The PWM on SAMv7 seems to be not functional, at
> least I observe only that pin goes high when PWM start is executed and the
> goes to low when PWM stop is executed.
>
> Is anyone using PWM with SAMv7 based board? Maybe I'm missing something?
>
> Best regards,
> Petro
> "

Re: Anyone using SAMv7 PWM?

Posted by Michal Lenc <mi...@seznam.cz>.
Hello,




> Recently I've tried to use PWM on SAMe70 based board. I tried to execute

> PWM example from apps. The PWM on SAMv7 seems to be not functional, at

> least I observe only that pin goes high when PWM start is executed and the

> goes to low when PWM stop is executed.





what king of configuration have you tried? I tested the configuration same70
-xplained:pysim on a real time control of RC

plant <https://gitlab.fel.cvut.cz/otrees/nuttx-demos/-/tree/master/
platforms/same70/rc-control>

with SAM E70 Xplained board few days ago. You should be able to run a PWM 
example app in this config too.




The pins setup in board level section can be found here:

<https://github.com/apache/incubator-nuttx/blob/master/boards/arm/samv7/same
70-xplained/include/board.h#L345>




I will double check tomorrow if the configuration does not work for you.




Best regards,
Michal Lenc

---------- Původní e-mail ----------
Od: Petro Karashchenko <pe...@gmail.com>
Komu: dev@nuttx.apache.org
Datum: 16. 5. 2022 18:36:49
Předmět: Anyone using SAMv7 PWM? 
"Hello, 

Recently I've tried to use PWM on SAMe70 based board. I tried to execute 
PWM example from apps. The PWM on SAMv7 seems to be not functional, at 
least I observe only that pin goes high when PWM start is executed and the 
goes to low when PWM stop is executed. 

Is anyone using PWM with SAMv7 based board? Maybe I'm missing something? 

Best regards, 
Petro 
"

Re: Anyone using SAMv7 PWM?

Posted by Gregory Nutt <sp...@gmail.com>.
> Recently I've tried to use PWM on SAMe70 based board. I tried to execute
> PWM example from apps. The PWM on SAMv7 seems to be not functional, at
> least I observe only that pin goes high when PWM start is executed and the
> goes to low when PWM stop is executed.
>
> Is anyone using PWM with SAMv7 based board? Maybe I'm missing something?
>
There are these configurations:

  * boards/arm/samv7/same70-xplained/configs/pwm/defconfig
  * boards/arm/samv7/same70-xplained/configs/pysim/defconfig

The GIT log says that there were verified:

commit 4236fa926f429761098d6c8c625ff52c63107ae8
Author: Michal Lenc <mi...@seznam.cz>
Date:   Sat Feb 12 11:48:24 2022 +0100

     boards/arm/samv7/same70-xplained: added PWM support

     This commit adds board level support of PWM driver to SAME70-XPLAINED
     board. The functionality is tested with two new configurations

     pwm:
       An example configuration with configured PWM.
     pysim:
       This configuration contains support for pysimCoder application and
       includes ADC and PWM peripherals and Ethernet driver.

     Signed-off-by: Michal Lenc <mi...@seznam.cz>