Skip to content

Commit a62c877

Browse files
committed
M263: modify epwm-config-output
1 parent 2596b7c commit a62c877

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

targets/TARGET_NUVOTON/TARGET_M261/device/StdDriver/m261_epwm.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_
103103
* To change duty cycle later, it should get the configured period value and calculate the new comparator value.
104104
*/
105105
uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
106+
{
107+
return EPWM_ConfigOutputChannel2(epwm, u32ChannelNum, u32Frequency, u32DutyCycle, 1);
108+
}
109+
110+
/**
111+
* @brief This function Configure EPWM generator and get the nearest frequency in edge aligned(up counter type) auto-reload mode
112+
* @param[in] epwm The pointer of the specified EPWM module
113+
* - EPWM0 : EPWM Group 0
114+
* - EPWM1 : EPWM Group 1
115+
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
116+
* @param[in] u32Frequency Target generator frequency
117+
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
118+
* @param[in] u32Frequency2 Target generator frequency = u32Frequency / u32Frequency2
119+
* @return Nearest frequency clock in nano second
120+
* @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure EPWM frequency may affect
121+
* existing frequency of other channel.
122+
* @note This function is used for initial stage.
123+
* To change duty cycle later, it should get the configured period value and calculate the new comparator value.
124+
*/
125+
uint32_t EPWM_ConfigOutputChannel2(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle, uint32_t u32Frequency2)
106126
{
107127
uint32_t u32PWMClockSrc;
108128
uint32_t i;
@@ -113,14 +133,15 @@ uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t
113133
{
114134
u32PWMClockSrc = CLK_GetPCLK0Freq();
115135
}
116-
else /* if((epwm == EPWM1)||(epwm == EPWM1_NS)) */
136+
else /* if(epwm == EPWM1) */
117137
{
118138
u32PWMClockSrc = CLK_GetPCLK1Freq();
119139
}
120140

121141
for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)/* prescale could be 0~0xFFF */
122142
{
123-
i = (u32PWMClockSrc / u32Frequency) / u32Prescale;
143+
// Note: Support frequency < 1
144+
i = (uint64_t) u32PWMClockSrc * u32Frequency2 / u32Frequency / u32Prescale;
124145
/* If target value is larger than CNR, need to use a larger prescaler */
125146
if(i <= (0x10000U))
126147
{

targets/TARGET_NUVOTON/TARGET_M261/device/StdDriver/m261_epwm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ extern "C"
541541
/*---------------------------------------------------------------------------------------------------------*/
542542
uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge);
543543
uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle);
544+
uint32_t EPWM_ConfigOutputChannel2(EPWM_T *epwm,
545+
uint32_t u32ChannelNum,
546+
uint32_t u32Frequency,
547+
uint32_t u32DutyCycle,
548+
uint32_t u32Frequency2);
544549
void EPWM_Start(EPWM_T *epwm, uint32_t u32ChannelMask);
545550
void EPWM_Stop(EPWM_T *epwm, uint32_t u32ChannelMask);
546551
void EPWM_ForceStop(EPWM_T *epwm, uint32_t u32ChannelMask);

0 commit comments

Comments
 (0)