Skip to content

Commit abdcc7b

Browse files
committed
Support M480 PWM duty cycle range as 0 ~ 10000
1 parent 76b2902 commit abdcc7b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

targets/TARGET_NUVOTON/TARGET_M480/device/StdDriver/src/m480_epwm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_
126126
* - EPWM1 : EPWM Group 1
127127
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
128128
* @param[in] u32Frequency Target generator frequency
129-
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
129+
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 10000. 1000 means 10%, 20000 means 20%...
130130
* @return Nearest frequency clock in nano second
131131
* @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure EPWM frequency may affect
132132
* existing frequency of other channel.
@@ -145,7 +145,7 @@ uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t
145145
* - EPWM1 : EPWM Group 1
146146
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
147147
* @param[in] u32Frequency Target generator frequency / u32Frequency2
148-
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
148+
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 10000. 1000 means 10%, 2000 means 20%...
149149
* @param[in] u32Frequency2 Target generator frequency = u32Frequency / u32Frequency2
150150
* @return Nearest frequency clock in nano second
151151
* @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure EPWM frequency may affect
@@ -211,7 +211,7 @@ uint32_t EPWM_ConfigOutputChannel2(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_
211211

212212
u32CNR -= 1U;
213213
EPWM_SET_CNR(epwm, u32ChannelNum, u32CNR);
214-
EPWM_SET_CMR(epwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1U) / 100U);
214+
EPWM_SET_CMR(epwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1U) / 10000U);
215215

216216
(epwm)->WGCTL0 = ((epwm)->WGCTL0 & ~(((1UL << EPWM_WGCTL0_PRDPCTL0_Pos) | (1UL << EPWM_WGCTL0_ZPCTL0_Pos)) << (u32ChannelNum << 1U))) | \
217217
((uint32_t)EPWM_OUTPUT_HIGH << ((u32ChannelNum << 1U) + (uint32_t)EPWM_WGCTL0_ZPCTL0_Pos));

targets/TARGET_NUVOTON/TARGET_M480/pwmout_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ static void pwmout_config(pwmout_t *obj, int start)
198198

199199
// NOTE: Support period < 1s
200200
// NOTE: ARM mbed CI test fails due to first PWM pulse error. Workaround by:
201-
// 1. Inverse duty cycle (100 - duty)
201+
// 1. Inverse duty cycle (10000 - duty)
202202
// 2. Inverse PWM output polarity
203203
// This trick is here to pass ARM mbed CI test. First PWM pulse error still remains.
204-
EPWM_ConfigOutputChannel2(pwm_base, chn, 1000 * 1000, 100 - obj->pulsewidth_us * 100 / obj->period_us, obj->period_us);
204+
EPWM_ConfigOutputChannel2(pwm_base, chn, 1000 * 1000, 10000 - obj->pulsewidth_us * 10000 / obj->period_us, obj->period_us);
205205
pwm_base->POLCTL |= 1 << (EPWM_POLCTL_PINV0_Pos + chn);
206206

207207
if (start) {

0 commit comments

Comments
 (0)