1 /**************************************************************************//**
\r
4 * @brief M2351 series BPWM driver source file
\r
7 * Copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.
\r
8 *****************************************************************************/
\r
11 /** @addtogroup Standard_Driver Standard Driver
\r
15 /** @addtogroup BPWM_Driver BPWM Driver
\r
20 /** @addtogroup BPWM_EXPORTED_FUNCTIONS BPWM Exported Functions
\r
25 * @brief Configure BPWM capture and get the nearest unit time.
\r
26 * @param[in] bpwm The pointer of the specified BPWM module
\r
27 * - BPWM0 : BPWM Group 0
\r
28 * - BPWM1 : BPWM Group 1
\r
29 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
30 * @param[in] u32UnitTimeNsec The unit time of counter
\r
31 * @param[in] u32CaptureEdge The condition to latch the counter. This parameter is not used
\r
32 * @return The nearest unit time in nano second.
\r
33 * @details This function is used to Configure BPWM capture and get the nearest unit time.
\r
35 uint32_t BPWM_ConfigCaptureChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
\r
37 uint32_t u32PWMClockSrc;
\r
38 uint32_t u32NearestUnitTimeNsec;
\r
39 uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
\r
40 uint8_t u8BreakLoop = 0U;
\r
42 /* clock source is from PCLK */
\r
43 if((((uint32_t)bpwm) == BPWM0_BASE) || (((uint32_t)bpwm) == BPWM0_BASE + NS_OFFSET))
\r
45 u32PWMClockSrc = CLK_GetPCLK0Freq();
\r
47 else/* if((bpwm == BPWM1)||(bpwm == BPWM1_NS)) */
\r
49 u32PWMClockSrc = CLK_GetPCLK1Freq();
\r
52 u32PWMClockSrc /= 1000UL;
\r
53 for(u32Prescale = 1U; u32Prescale <= 0x1000UL; u32Prescale++)
\r
55 u32NearestUnitTimeNsec = (1000000UL * u32Prescale) / u32PWMClockSrc;
\r
56 if(u32NearestUnitTimeNsec < u32UnitTimeNsec)
\r
58 if(u32Prescale == 0x1000U)
\r
60 /* limit to the maximum unit time(nano second) */
\r
63 if(!((1000000UL * (u32Prescale + 1UL) > (u32NearestUnitTimeNsec * u32PWMClockSrc))))
\r
78 /* convert to real register value */
\r
79 u32Prescale = u32Prescale - 1U;
\r
80 /* all channels share a prescaler */
\r
81 BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescale);
\r
83 /* set BPWM to down count type(edge aligned) */
\r
84 (bpwm)->CTL1 = (1UL);
\r
86 BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR);
\r
88 return (u32NearestUnitTimeNsec);
\r
92 * @brief This function Configure BPWM generator and get the nearest frequency in edge aligned(up counter type) auto-reload mode
\r
93 * @param[in] bpwm The pointer of the specified BPWM module
\r
94 * - BPWM0 : BPWM Group 0
\r
95 * - BPWM1 : BPWM Group 1
\r
96 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
97 * @param[in] u32Frequency Target generator frequency
\r
98 * @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
\r
99 * @return Nearest frequency clock in nano second
\r
100 * @note Since all channels shares a prescaler. Call this API to configure BPWM frequency may affect
\r
101 * existing frequency of other channel.
\r
102 * @note This function is used for initial stage.
\r
103 * To change duty cycle later, it should get the configured period value and calculate the new comparator value.
\r
105 uint32_t BPWM_ConfigOutputChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
\r
107 uint32_t u32PWMClockSrc;
\r
109 uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
\r
111 /* clock source is from PCLK */
\r
112 if(((uint32_t)bpwm == BPWM0_BASE) || ((uint32_t)bpwm == BPWM0_BASE + NS_OFFSET))
\r
114 u32PWMClockSrc = CLK_GetPCLK0Freq();
\r
116 else/* if((bpwm == BPWM1)||(bpwm == BPWM1_NS)) */
\r
118 u32PWMClockSrc = CLK_GetPCLK1Freq();
\r
121 for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)/* prescale could be 0~0xFFF */
\r
123 i = (u32PWMClockSrc / u32Frequency) / u32Prescale;
\r
124 /* If target value is larger than CNR, need to use a larger prescaler */
\r
125 if(i <= (0x10000U))
\r
131 /* Store return value here 'cos we're gonna change u32Prescale & u32CNR to the real value to fill into register */
\r
132 i = u32PWMClockSrc / (u32Prescale * u32CNR);
\r
134 /* convert to real register value */
\r
135 u32Prescale = u32Prescale - 1U;
\r
136 /* all channels share a prescaler */
\r
137 BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescale);
\r
138 /* set BPWM to up counter type(edge aligned) */
\r
139 (bpwm)->CTL1 = BPWM_UP_COUNTER;
\r
141 u32CNR = u32CNR - 1U;
\r
142 BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR);
\r
143 BPWM_SET_CMR(bpwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1UL) / 100UL);
\r
146 (bpwm)->WGCTL0 = ((bpwm)->WGCTL0 & ~((BPWM_WGCTL0_PRDPCTL0_Msk | BPWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum << 1))) | \
\r
147 (BPWM_OUTPUT_HIGH << (u32ChannelNum << 1UL << BPWM_WGCTL0_ZPCTL0_Pos));
\r
148 (bpwm)->WGCTL1 = ((bpwm)->WGCTL1 & ~((BPWM_WGCTL1_CMPDCTL0_Msk | BPWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum << 1))) | \
\r
149 (BPWM_OUTPUT_LOW << (u32ChannelNum << 1UL << BPWM_WGCTL1_CMPUCTL0_Pos));
\r
155 * @brief Start BPWM module
\r
156 * @param[in] bpwm The pointer of the specified BPWM module
\r
157 * - BPWM0 : BPWM Group 0
\r
158 * - BPWM1 : BPWM Group 1
\r
159 * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.
\r
161 * @details This function is used to start BPWM module.
\r
162 * @note All channels share one counter.
\r
164 void BPWM_Start(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
166 (bpwm)->CNTEN = BPWM_CNTEN_CNTEN0_Msk;
\r
170 * @brief Stop BPWM module
\r
171 * @param[in] bpwm The pointer of the specified BPWM module
\r
172 * - BPWM0 : BPWM Group 0
\r
173 * - BPWM1 : BPWM Group 1
\r
174 * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.
\r
176 * @details This function is used to stop BPWM module.
\r
177 * @note All channels share one period.
\r
179 void BPWM_Stop(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
181 (bpwm)->PERIOD = 0UL;
\r
185 * @brief Stop BPWM generation immediately by clear channel enable bit
\r
186 * @param[in] bpwm The pointer of the specified BPWM module
\r
187 * - BPWM0 : BPWM Group 0
\r
188 * - BPWM1 : BPWM Group 1
\r
189 * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.
\r
191 * @details This function is used to stop BPWM generation immediately by clear channel enable bit.
\r
192 * @note All channels share one counter.
\r
194 void BPWM_ForceStop(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
196 (bpwm)->CNTEN &= ~BPWM_CNTEN_CNTEN0_Msk;
\r
200 * @brief Enable selected channel to trigger ADC
\r
201 * @param[in] bpwm The pointer of the specified BPWM module
\r
202 * - BPWM0 : BPWM Group 0
\r
203 * - BPWM1 : BPWM Group 1
\r
204 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
205 * @param[in] u32Condition The condition to trigger ADC. Combination of following conditions:
\r
206 * - \ref BPWM_TRIGGER_ADC_EVEN_ZERO_POINT
\r
207 * - \ref BPWM_TRIGGER_ADC_EVEN_PERIOD_POINT
\r
208 * - \ref BPWM_TRIGGER_ADC_EVEN_ZERO_OR_PERIOD_POINT
\r
209 * - \ref BPWM_TRIGGER_ADC_EVEN_CMP_UP_COUNT_POINT
\r
210 * - \ref BPWM_TRIGGER_ADC_EVEN_CMP_DOWN_COUNT_POINT
\r
211 * - \ref BPWM_TRIGGER_ADC_ODD_CMP_UP_COUNT_POINT
\r
212 * - \ref BPWM_TRIGGER_ADC_ODD_CMP_DOWN_COUNT_POINT
\r
214 * @details This function is used to enable selected channel to trigger ADC
\r
216 void BPWM_EnableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
\r
218 if(u32ChannelNum < 4UL)
\r
220 (bpwm)->EADCTS0 &= ~((BPWM_EADCTS0_TRGSEL0_Msk) << (u32ChannelNum << 3));
\r
221 (bpwm)->EADCTS0 |= ((BPWM_EADCTS0_TRGEN0_Msk | u32Condition) << (u32ChannelNum << 3));
\r
225 (bpwm)->EADCTS1 &= ~((BPWM_EADCTS1_TRGSEL4_Msk) << ((u32ChannelNum - 4UL) << 3));
\r
226 (bpwm)->EADCTS1 |= ((BPWM_EADCTS1_TRGEN4_Msk | u32Condition) << ((u32ChannelNum - 4UL) << 3));
\r
231 * @brief Disable selected channel to trigger ADC
\r
232 * @param[in] bpwm The pointer of the specified BPWM module
\r
233 * - BPWM0 : BPWM Group 0
\r
234 * - BPWM1 : BPWM Group 1
\r
235 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~3
\r
237 * @details This function is used to disable selected channel to trigger ADC
\r
239 void BPWM_DisableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
241 if(u32ChannelNum < 4UL)
\r
243 (bpwm)->EADCTS0 &= ~(BPWM_EADCTS0_TRGEN0_Msk << (u32ChannelNum << 3));
\r
247 (bpwm)->EADCTS1 &= ~(BPWM_EADCTS1_TRGEN4_Msk << ((u32ChannelNum - 4UL) << 3));
\r
252 * @brief Clear selected channel trigger ADC flag
\r
253 * @param[in] bpwm The pointer of the specified BPWM module
\r
254 * - BPWM0 : BPWM Group 0
\r
255 * - BPWM1 : BPWM Group 1
\r
256 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
257 * @param[in] u32Condition This parameter is not used
\r
259 * @details This function is used to clear selected channel trigger ADC flag
\r
261 void BPWM_ClearADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
\r
263 (bpwm)->STATUS = (BPWM_STATUS_EADCTRG0_Msk << u32ChannelNum);
\r
267 * @brief Get selected channel trigger ADC flag
\r
268 * @param[in] bpwm The pointer of the specified BPWM module
\r
269 * - BPWM0 : BPWM Group 0
\r
270 * - BPWM1 : BPWM Group 1
\r
271 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
272 * @retval 0 The specified channel trigger ADC to start of conversion flag is not set
\r
273 * @retval 1 The specified channel trigger ADC to start of conversion flag is set
\r
274 * @details This function is used to get BPWM trigger ADC to start of conversion flag for specified channel
\r
276 uint32_t BPWM_GetADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
278 return (((bpwm)->STATUS & (BPWM_STATUS_EADCTRG0_Msk << u32ChannelNum)) ? 1UL : 0UL);
\r
282 * @brief Enable capture of selected channel(s)
\r
283 * @param[in] bpwm The pointer of the specified BPWM module
\r
284 * - BPWM0 : BPWM Group 0
\r
285 * - BPWM1 : BPWM Group 1
\r
286 * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
\r
287 * Bit 0 is channel 0, bit 1 is channel 1...
\r
289 * @details This function is used to enable capture of selected channel(s)
\r
291 void BPWM_EnableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
293 (bpwm)->CAPINEN |= u32ChannelMask;
\r
294 (bpwm)->CAPCTL |= u32ChannelMask;
\r
298 * @brief Disable capture of selected channel(s)
\r
299 * @param[in] bpwm The pointer of the specified BPWM module
\r
300 * - BPWM0 : BPWM Group 0
\r
301 * - BPWM1 : BPWM Group 1
\r
302 * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
\r
303 * Bit 0 is channel 0, bit 1 is channel 1...
\r
305 * @details This function is used to disable capture of selected channel(s)
\r
307 void BPWM_DisableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
309 (bpwm)->CAPINEN &= ~u32ChannelMask;
\r
310 (bpwm)->CAPCTL &= ~u32ChannelMask;
\r
314 * @brief Enables BPWM output generation of selected channel(s)
\r
315 * @param[in] bpwm The pointer of the specified BPWM module
\r
316 * - BPWM0 : BPWM Group 0
\r
317 * - BPWM1 : BPWM Group 1
\r
318 * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
\r
319 * Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...
\r
321 * @details This function is used to enables BPWM output generation of selected channel(s)
\r
323 void BPWM_EnableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
325 (bpwm)->POEN |= u32ChannelMask;
\r
329 * @brief Disables BPWM output generation of selected channel(s)
\r
330 * @param[in] bpwm The pointer of the specified BPWM module
\r
331 * - BPWM0 : BPWM Group 0
\r
332 * - BPWM1 : BPWM Group 1
\r
333 * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel
\r
334 * Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output...
\r
336 * @details This function is used to disables BPWM output generation of selected channel(s)
\r
338 void BPWM_DisableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
\r
340 (bpwm)->POEN &= ~u32ChannelMask;
\r
344 * @brief Enable capture interrupt of selected channel.
\r
345 * @param[in] bpwm The pointer of the specified BPWM module
\r
346 * - BPWM0 : BPWM Group 0
\r
347 * - BPWM1 : BPWM Group 1
\r
348 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
349 * @param[in] u32Edge Rising or falling edge to latch counter.
\r
350 * - \ref BPWM_CAPTURE_INT_RISING_LATCH
\r
351 * - \ref BPWM_CAPTURE_INT_FALLING_LATCH
\r
353 * @details This function is used to enable capture interrupt of selected channel.
\r
355 void BPWM_EnableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
\r
357 (bpwm)->CAPIEN |= (u32Edge << u32ChannelNum);
\r
361 * @brief Disable capture interrupt of selected channel.
\r
362 * @param[in] bpwm The pointer of the specified BPWM module
\r
363 * - BPWM0 : BPWM Group 0
\r
364 * - BPWM1 : BPWM Group 1
\r
365 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
366 * @param[in] u32Edge Rising or falling edge to latch counter.
\r
367 * - \ref BPWM_CAPTURE_INT_RISING_LATCH
\r
368 * - \ref BPWM_CAPTURE_INT_FALLING_LATCH
\r
370 * @details This function is used to disable capture interrupt of selected channel.
\r
372 void BPWM_DisableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
\r
374 (bpwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);
\r
378 * @brief Clear capture interrupt of selected channel.
\r
379 * @param[in] bpwm The pointer of the specified BPWM module
\r
380 * - BPWM0 : BPWM Group 0
\r
381 * - BPWM1 : BPWM Group 1
\r
382 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
383 * @param[in] u32Edge Rising or falling edge to latch counter.
\r
384 * - \ref BPWM_CAPTURE_INT_RISING_LATCH
\r
385 * - \ref BPWM_CAPTURE_INT_FALLING_LATCH
\r
387 * @details This function is used to clear capture interrupt of selected channel.
\r
389 void BPWM_ClearCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
\r
391 (bpwm)->CAPIF = (u32Edge << u32ChannelNum);
\r
395 * @brief Get capture interrupt of selected channel.
\r
396 * @param[in] bpwm The pointer of the specified BPWM module
\r
397 * - BPWM0 : BPWM Group 0
\r
398 * - BPWM1 : BPWM Group 1
\r
399 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
400 * @retval 0 No capture interrupt
\r
401 * @retval 1 Rising edge latch interrupt
\r
402 * @retval 2 Falling edge latch interrupt
\r
403 * @retval 3 Rising and falling latch interrupt
\r
404 * @details This function is used to get capture interrupt of selected channel.
\r
406 uint32_t BPWM_GetCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
408 uint32_t u32CapIf = 0UL;
\r
410 u32CapIf = ((((bpwm)->CAPIF & (BYTE1_Msk << u32ChannelNum)) ? 1UL : 0UL) << 1);
\r
411 u32CapIf |= (((bpwm)->CAPIF & (BYTE0_Msk << u32ChannelNum)) ? 1UL : 0UL);
\r
415 * @brief Enable duty interrupt of selected channel
\r
416 * @param[in] bpwm The pointer of the specified BPWM module
\r
417 * - BPWM0 : BPWM Group 0
\r
418 * - BPWM1 : BPWM Group 1
\r
419 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
420 * @param[in] u32IntDutyType Duty interrupt type, could be either
\r
421 * - \ref BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP
\r
422 * - \ref BPWM_DUTY_INT_UP_COUNT_MATCH_CMP
\r
424 * @details This function is used to enable duty interrupt of selected channel.
\r
426 void BPWM_EnableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
\r
428 (bpwm)->INTEN |= (u32IntDutyType << u32ChannelNum);
\r
432 * @brief Disable duty interrupt of selected channel
\r
433 * @param[in] bpwm The pointer of the specified BPWM module
\r
434 * - BPWM0 : BPWM Group 0
\r
435 * - BPWM1 : BPWM Group 1
\r
436 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
438 * @details This function is used to disable duty interrupt of selected channel
\r
440 void BPWM_DisableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
442 (bpwm)->INTEN &= ~((BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP | BPWM_DUTY_INT_UP_COUNT_MATCH_CMP) << u32ChannelNum);
\r
446 * @brief Clear duty interrupt flag of selected channel
\r
447 * @param[in] bpwm The pointer of the specified BPWM module
\r
448 * - BPWM0 : BPWM Group 0
\r
449 * - BPWM1 : BPWM Group 1
\r
450 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
452 * @details This function is used to clear duty interrupt flag of selected channel
\r
454 void BPWM_ClearDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
456 (bpwm)->INTSTS = (BYTE2_Msk | BYTE3_Msk) << u32ChannelNum;
\r
460 * @brief Get duty interrupt flag of selected channel
\r
461 * @param[in] bpwm The pointer of the specified BPWM module
\r
462 * - BPWM0 : BPWM Group 0
\r
463 * - BPWM1 : BPWM Group 1
\r
464 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
465 * @return Duty interrupt flag of specified channel
\r
466 * @retval 0 Duty interrupt did not occur
\r
467 * @retval 1 Duty interrupt occurred
\r
468 * @details This function is used to get duty interrupt flag of selected channel
\r
470 uint32_t BPWM_GetDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
472 return ((((bpwm)->INTSTS & ((BYTE2_Msk | BYTE3_Msk) << u32ChannelNum))) ? 1UL : 0UL);
\r
476 * @brief Enable period interrupt of selected channel
\r
477 * @param[in] bpwm The pointer of the specified BPWM module
\r
478 * - BPWM0 : BPWM Group 0
\r
479 * - BPWM1 : BPWM Group 1
\r
480 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
481 * @param[in] u32IntPeriodType Period interrupt type. This parameter is not used.
\r
483 * @details This function is used to enable period interrupt of selected channel.
\r
484 * @note All channels share channel 0's setting.
\r
486 void BPWM_EnablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
\r
488 (bpwm)->INTEN |= BPWM_INTEN_PIEN0_Msk;
\r
492 * @brief Disable period interrupt of selected channel
\r
493 * @param[in] bpwm The pointer of the specified BPWM module
\r
494 * - BPWM0 : BPWM Group 0
\r
495 * - BPWM1 : BPWM Group 1
\r
496 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
498 * @details This function is used to disable period interrupt of selected channel.
\r
499 * @note All channels share channel 0's setting.
\r
501 void BPWM_DisablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
503 (bpwm)->INTEN &= ~BPWM_INTEN_PIEN0_Msk;
\r
507 * @brief Clear period interrupt of selected channel
\r
508 * @param[in] bpwm The pointer of the specified BPWM module
\r
509 * - BPWM0 : BPWM Group 0
\r
510 * - BPWM1 : BPWM Group 1
\r
511 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
513 * @details This function is used to clear period interrupt of selected channel
\r
514 * @note All channels share channel 0's setting.
\r
516 void BPWM_ClearPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
518 (bpwm)->INTSTS = BPWM_INTSTS_PIF0_Msk;
\r
522 * @brief Get period interrupt of selected channel
\r
523 * @param[in] bpwm The pointer of the specified BPWM module
\r
524 * - BPWM0 : BPWM Group 0
\r
525 * - BPWM1 : BPWM Group 1
\r
526 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
527 * @return Period interrupt flag of specified channel
\r
528 * @retval 0 Period interrupt did not occur
\r
529 * @retval 1 Period interrupt occurred
\r
530 * @details This function is used to get period interrupt of selected channel
\r
531 * @note All channels share channel 0's setting.
\r
533 uint32_t BPWM_GetPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
535 return (((bpwm)->INTSTS & BPWM_INTSTS_PIF0_Msk) ? 1UL : 0UL);
\r
539 * @brief Enable zero interrupt of selected channel
\r
540 * @param[in] bpwm The pointer of the specified BPWM module
\r
541 * - BPWM0 : BPWM Group 0
\r
542 * - BPWM1 : BPWM Group 1
\r
543 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
545 * @details This function is used to enable zero interrupt of selected channel.
\r
546 * @note All channels share channel 0's setting.
\r
548 void BPWM_EnableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
550 (bpwm)->INTEN |= BPWM_INTEN_ZIEN0_Msk;
\r
554 * @brief Disable zero interrupt of selected channel
\r
555 * @param[in] bpwm The pointer of the specified BPWM module
\r
556 * - BPWM0 : BPWM Group 0
\r
557 * - BPWM1 : BPWM Group 1
\r
558 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
560 * @details This function is used to disable zero interrupt of selected channel.
\r
561 * @note All channels share channel 0's setting.
\r
563 void BPWM_DisableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
565 (bpwm)->INTEN &= ~BPWM_INTEN_ZIEN0_Msk;
\r
569 * @brief Clear zero interrupt of selected channel
\r
570 * @param[in] bpwm The pointer of the specified BPWM module
\r
571 * - BPWM0 : BPWM Group 0
\r
572 * - BPWM1 : BPWM Group 1
\r
573 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
575 * @details This function is used to clear zero interrupt of selected channel.
\r
576 * @note All channels share channel 0's setting.
\r
578 void BPWM_ClearZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
580 (bpwm)->INTSTS = BPWM_INTSTS_ZIF0_Msk;
\r
584 * @brief Get zero interrupt of selected channel
\r
585 * @param[in] bpwm The pointer of the specified BPWM module
\r
586 * - BPWM0 : BPWM Group 0
\r
587 * - BPWM1 : BPWM Group 1
\r
588 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
589 * @return zero interrupt flag of specified channel
\r
590 * @retval 0 zero interrupt did not occur
\r
591 * @retval 1 zero interrupt occurred
\r
592 * @details This function is used to get zero interrupt of selected channel.
\r
593 * @note All channels share channel 0's setting.
\r
595 uint32_t BPWM_GetZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
597 return (((bpwm)->INTSTS & BPWM_INTSTS_ZIF0_Msk) ? 1UL : 0UL);
\r
601 * @brief Enable load mode of selected channel
\r
602 * @param[in] bpwm The pointer of the specified BPWM module
\r
603 * - BPWM0 : BPWM Group 0
\r
604 * - BPWM1 : BPWM Group 1
\r
605 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
606 * @param[in] u32LoadMode BPWM counter loading mode.
\r
607 * - \ref BPWM_LOAD_MODE_IMMEDIATE
\r
608 * - \ref BPWM_LOAD_MODE_CENTER
\r
610 * @details This function is used to enable load mode of selected channel.
\r
612 void BPWM_EnableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
\r
614 (bpwm)->CTL0 |= (u32LoadMode << u32ChannelNum);
\r
618 * @brief Disable load mode of selected channel
\r
619 * @param[in] bpwm The pointer of the specified BPWM module
\r
620 * - BPWM0 : BPWM Group 0
\r
621 * - BPWM1 : BPWM Group 1
\r
622 * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5
\r
623 * @param[in] u32LoadMode BPWM counter loading mode.
\r
624 * - \ref BPWM_LOAD_MODE_IMMEDIATE
\r
625 * - \ref BPWM_LOAD_MODE_CENTER
\r
627 * @details This function is used to disable load mode of selected channel.
\r
629 void BPWM_DisableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
\r
631 (bpwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);
\r
635 * @brief Set BPWM clock source
\r
636 * @param[in] bpwm The pointer of the specified BPWM module
\r
637 * - BPWM0 : BPWM Group 0
\r
638 * - BPWM1 : BPWM Group 1
\r
639 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
640 * @param[in] u32ClkSrcSel BPWM external clock source.
\r
641 * - \ref BPWM_CLKSRC_BPWM_CLK
\r
642 * - \ref BPWM_CLKSRC_TIMER0
\r
643 * - \ref BPWM_CLKSRC_TIMER1
\r
644 * - \ref BPWM_CLKSRC_TIMER2
\r
645 * - \ref BPWM_CLKSRC_TIMER3
\r
647 * @details This function is used to set BPWM clock source.
\r
648 * @note All channels share channel 0's setting.
\r
650 void BPWM_SetClockSource(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
\r
652 (bpwm)->CLKSRC = (u32ClkSrcSel);
\r
656 * @brief Get the time-base counter reached its maximum value flag of selected channel
\r
657 * @param[in] bpwm The pointer of the specified BPWM module
\r
658 * - BPWM0 : BPWM Group 0
\r
659 * - BPWM1 : BPWM Group 1
\r
660 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
661 * @return Count to max interrupt flag of specified channel
\r
662 * @retval 0 Count to max interrupt did not occur
\r
663 * @retval 1 Count to max interrupt occurred
\r
664 * @details This function is used to get the time-base counter reached its maximum value flag of selected channel.
\r
665 * @note All channels share channel 0's setting.
\r
667 uint32_t BPWM_GetWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
669 return (((bpwm)->STATUS & BPWM_STATUS_CNTMAX0_Msk) ? 1UL : 0UL);
\r
673 * @brief Clear the time-base counter reached its maximum value flag of selected channel
\r
674 * @param[in] bpwm The pointer of the specified BPWM module
\r
675 * - BPWM0 : BPWM Group 0
\r
676 * - BPWM1 : BPWM Group 1
\r
677 * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.
\r
679 * @details This function is used to clear the time-base counter reached its maximum value flag of selected channel.
\r
680 * @note All channels share channel 0's setting.
\r
682 void BPWM_ClearWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
\r
684 (bpwm)->STATUS = BPWM_STATUS_CNTMAX0_Msk;
\r
688 /*@}*/ /* end of group BPWM_EXPORTED_FUNCTIONS */
\r
690 /*@}*/ /* end of group BPWM_Driver */
\r
692 /*@}*/ /* end of group Standard_Driver */
\r
694 /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/
\r