This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 6376d90c3d In case of SAMV7 it is possible to overwrite the pwm output with 0 or 1 immediately. Changing the dutycycle to 0 or 100 will take effect only on end of cycle, which could be to late for some applications. 6376d90c3d is described below commit 6376d90c3d9997c339425dbb3e102ef80ddf3d54 Author: Simon Filgis <si...@ingenieurbuero-filgis.de> AuthorDate: Tue Nov 15 20:41:25 2022 +0100 In case of SAMV7 it is possible to overwrite the pwm output with 0 or 1 immediately. Changing the dutycycle to 0 or 100 will take effect only on end of cycle, which could be to late for some applications. This solution adds a overwrite flag and value when updating the duty cycle. --- arch/arm/src/samv7/sam_pwm.c | 18 ++++++++++++++++++ include/nuttx/timers/pwm.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm/src/samv7/sam_pwm.c b/arch/arm/src/samv7/sam_pwm.c index e446c60248..28205e4fe0 100644 --- a/arch/arm/src/samv7/sam_pwm.c +++ b/arch/arm/src/samv7/sam_pwm.c @@ -449,6 +449,7 @@ static int pwm_start(struct pwm_lowerhalf_s *dev, const struct pwm_info_s *info) { struct sam_pwm_s *priv = (struct sam_pwm_s *)dev; + uint32_t regval; #ifdef CONFIG_PWM_MULTICHAN for (int i = 0; i < PWM_NCHANNELS; i++) @@ -472,6 +473,23 @@ static int pwm_start(struct pwm_lowerhalf_s *dev, info->frequency); pwm_set_output(dev, priv->channels[index - 1].channel, info->channels[i].duty); + + if (info->channels[i].ch_outp_ovrwr) + { + regval = pwm_getreg(priv, SAMV7_PWM_OOV); + regval &= ~(info->channels[i].ch_outp_ovrwr_val + << priv->channels[i].channel); + pwm_putreg(priv, SAMV7_PWM_OOV, regval); + + regval = (1 << priv->channels[i].channel); + pwm_putreg(priv, SAMV7_PWM_OSS, regval); + } + else + { + /* release overwrite of channel */ + regval = (1 << priv->channels[i].channel); + pwm_putreg(priv, SAMV7_PWM_OSC, regval); + } } } #else diff --git a/include/nuttx/timers/pwm.h b/include/nuttx/timers/pwm.h index dccbb991c4..75ff9ba50a 100644 --- a/include/nuttx/timers/pwm.h +++ b/include/nuttx/timers/pwm.h @@ -120,6 +120,10 @@ struct pwm_chan_s { ub16_t duty; +#ifdef CONFIG_SAMV7_PWM + bool ch_outp_ovrwr; + bool ch_outp_ovrwr_val; +#endif int8_t channel; }; #endif