@@ -103,6 +103,26 @@ uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_
103
103
* To change duty cycle later, it should get the configured period value and calculate the new comparator value.
104
104
*/
105
105
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 )
106
126
{
107
127
uint32_t u32PWMClockSrc ;
108
128
uint32_t i ;
@@ -113,14 +133,15 @@ uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t
113
133
{
114
134
u32PWMClockSrc = CLK_GetPCLK0Freq ();
115
135
}
116
- else /* if(( epwm == EPWM1)||(epwm == EPWM1_NS) ) */
136
+ else /* if(epwm == EPWM1) */
117
137
{
118
138
u32PWMClockSrc = CLK_GetPCLK1Freq ();
119
139
}
120
140
121
141
for (u32Prescale = 1U ; u32Prescale < 0xFFFU ; u32Prescale ++ )/* prescale could be 0~0xFFF */
122
142
{
123
- i = (u32PWMClockSrc / u32Frequency ) / u32Prescale ;
143
+ // Note: Support frequency < 1
144
+ i = (uint64_t ) u32PWMClockSrc * u32Frequency2 / u32Frequency / u32Prescale ;
124
145
/* If target value is larger than CNR, need to use a larger prescaler */
125
146
if (i <= (0x10000U ))
126
147
{
0 commit comments