| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

pwm.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __PWM_H__
13#define __PWM_H__
14
15#ifdef __cplusplus
16 extern "C"
17{
18#endif
19
20
32#define PWM_CHANNEL_NUM (6)
33#define PWM_CH0 (0UL)
34#define PWM_CH1 (1UL)
35#define PWM_CH2 (2UL)
36#define PWM_CH3 (3UL)
37#define PWM_CH4 (4UL)
38#define PWM_CH5 (5UL)
39#define PWM_CH_0_MASK (1UL)
40#define PWM_CH_1_MASK (2UL)
41#define PWM_CH_2_MASK (4UL)
42#define PWM_CH_3_MASK (8UL)
43#define PWM_CH_4_MASK (16UL)
44#define PWM_CH_5_MASK (32UL)
45#define PWM_CLK_DIV_1 (4UL)
46#define PWM_CLK_DIV_2 (0UL)
47#define PWM_CLK_DIV_4 (1UL)
48#define PWM_CLK_DIV_8 (2UL)
49#define PWM_CLK_DIV_16 (3UL)
50#define PWM_EDGE_ALIGNED (0UL)
51#define PWM_CENTER_ALIGNED (1UL)
52#define PWM_TRIGGER_ADC_RISING_EDGE_POINT (0x1000000UL)
53#define PWM_TRIGGER_ADC_FALLING_EDGE_POINT (0x10000UL)
54#define PWM_TRIGGER_ADC_CENTER_POINT (0x100UL)
55#define PWM_TRIGGER_ADC_PERIOD_POINT (0x1UL)
56#define PWM_BRK0_BKP0 (PWM_BRKCTL_BRK0EN_Msk)
57#define PWM_BRK0_CPO0 (PWM_BRKCTL_CPO0BKEN_Msk)
58#define PWM_BRK0_CPO1 (PWM_BRKCTL_CPO1BKEN_Msk)
59#define PWM_BRK0_CPO2 (PWM_BRKCTL_CPO2BKEN_Msk)
60#define PWM_BRK1_LVDBK (PWM_BRKCTL_LVDBKEN_Msk)
61#define PWM_BK1SEL_BKP1 (0UL << PWM_BRKCTL_BK1SEL_Pos)
62#define PWM_BK1SEL_CPO0 (1UL << PWM_BRKCTL_BK1SEL_Pos)
63#define PWM_BK1SEL_CPO1 (2UL << PWM_BRKCTL_BK1SEL_Pos)
64#define PWM_PERIOD_INT_UNDERFLOW (0)
65#define PWM_PERIOD_INT_MATCH_CNR (1UL)
66#define PWM_DUTY_INT_MATCH_CMR_DN (0)
67#define PWM_DUTY_INT_MATCH_CMR_UP (0x100UL)
68#define PWM_FALLING_LATCH_INT_ENABLE (0x1000000UL)
69#define PWM_RISING_LATCH_INT_ENABLE (0x10000UL)
70#define PWM_RISING_FALLING_LATCH_INT_ENABLE (0x1010000UL)
71#define PWM_FALLING_LATCH_INT_FLAG (PWM_FALLING_LATCH_INT_ENABLE)
72#define PWM_RISING_LATCH_INT_FLAG (PWM_RISING_LATCH_INT_ENABLE)
73#define PWM_RISING_FALLING_LATCH_INT_FLAG (PWM_RISING_FALLING_LATCH_INT_ENABLE)
75/*---------------------------------------------------------------------------------------------------------*/
76/* Define Error Code */
77/*---------------------------------------------------------------------------------------------------------*/
78#define PWM_TIMEOUT_ERR (-1) /* end of group NUC472_442_PWM_EXPORTED_CONSTANTS */
81
82
93#define PWM_ENABLE_COMPLEMENTARY_MODE(pwm) ((pwm)->CTL = (pwm)->CTL | PWM_CTL_OUTMODE_Msk)
94
101#define PWM_DISABLE_COMPLEMENTARY_MODE(pwm) ((pwm)->CTL = (pwm)->CTL & ~PWM_CTL_OUTMODE_Msk)
102
109#define PWM_ENABLE_GROUP_MODE(pwm) ((pwm)->CTL = (pwm)->CTL | PWM_CTL_GROUPEN_Msk)
110
117#define PWM_DISABLE_GROUP_MODE(pwm) ((pwm)->CTL = (pwm)->CTL & ~PWM_CTL_GROUPEN_Msk)
118
125#define PWM_ENABLE_SYNC_MODE(pwm) ((pwm)->CTL = (pwm)->CTL | PWM_CTL_SYNCEN_Msk)
126
133#define PWM_DISABLE_SYNC_MODE(pwm) ((pwm)->CTL = (pwm)->CTL & ~PWM_CTL_SYNCEN_Msk)
134
143#define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask) ((pwm)->CTL = (((pwm)->CTL & ~PWM_CTL_PINV_Msk) | ((u32ChannelMask) << PWM_CTL_PINV_Pos)))
144
152#define PWM_GET_CAPTURE_RISING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->RCAPDAT0 + 2 * (u32ChannelNum)))
153
161#define PWM_GET_CAPTURE_FALLING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->FCAPDAT0 + 2 * (u32ChannelNum)))
162
172#define PWM_MASK_OUTPUT(pwm, u32ChannelMask, u32LevelMask) \
173 do { \
174 (pwm)->MSKEN = (u32ChannelMask); \
175 (pwm)->MSK = u32LevelMask; \
176}while(0)
177
188#define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
189 (pwm->CLKPSC = ((pwm)->CLKPSC & ~(PWM_CLKPSC_CLKPSC01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
190
204#define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
205 ((pwm)->CLKDIV = ((pwm)->CLKDIV & ~(PWM_CLKDIV_CLKDIV0_Msk << ((u32ChannelNum) * 4))) | ((u32Divider) << ((u32ChannelNum) * 4)))
206
216#define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) ((pwm)->CMPDAT[(u32ChannelNum)] = (u32CMR))
217
228#define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) ((pwm)->PERIOD[(u32ChannelNum)] = (u32CNR))
229
241#define PWM_SET_ALIGNED_TYPE(pwm, u32ChannelMask, u32AlignedType) \
242 do { \
243 (pwm)->CTL = ((pwm)->CTL & ~PWM_CTL_CNTTYPE_Msk); \
244 if ((u32AlignedType) == PWM_CENTER_ALIGNED) \
245 (pwm)->CTL = ((pwm)->CTL | ((u32ChannelMask) << PWM_CTL_CNTTYPE_Pos)); \
246} while(0)
247
248
249uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
250 uint32_t u32ChannelNum,
251 uint32_t u32Frequency,
252 uint32_t u32DutyCycle);
253uint32_t PWM_ConfigCaptureChannel (PWM_T *pwm,
254 uint32_t u32ChannelNum,
255 uint32_t u32UnitTimeNsec,
256 uint32_t u32CaptureEdge);
257 void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
258 void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
259 void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
260 void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
261 void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum);
262 void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
263uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum);
264 void PWM_EnableFaultBrake(PWM_T *pwm,
265 uint32_t u32ChannelMask,
266 uint32_t u32LevelMask,
267 uint32_t u32BrakeSource);
268 void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource);
269 void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
270 void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
271 void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
272 void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
273 void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
274 void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
275 void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
276 void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
277 void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
278uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
279 void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType);
280 void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum);
281 void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
282uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
283 void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
284 void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
285 void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
286uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
287 void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
288 void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
289 void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
290uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
291
292
293 /* end of group NUC472_442_PWM_EXPORTED_FUNCTIONS */
295 /* end of group NUC472_442_PWM_Driver */
297 /* end of group NUC472_442_Device_Driver */
299
300#ifdef __cplusplus
301}
302#endif
303
304#endif //__PWM_H__
305
306/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
PWM_ForceStop
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
Definition: pwm.c:393
PWM_Stop
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:373
PWM_EnableCapture
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
Definition: pwm.c:526
PWM_EnableDeadZone
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
Definition: pwm.c:578
PWM_ClearCaptureIntFlag
void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function clear capture interrupt flag of selected channel.
Definition: pwm.c:644
PWM_ClearADCTriggerFlag
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function clear selected channel trigger ADC flag.
Definition: pwm.c:442
PWM_DisableADCTrigger
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
Definition: pwm.c:423
PWM_ConfigCaptureChannel
uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
This function config PWM capture and get the nearest unit time.
Definition: pwm.c:207
PWM_DisablePeriodInt
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
Definition: pwm.c:792
PWM_EnableDutyInt
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
This function enable duty interrupt of selected channel.
Definition: pwm.c:674
PWM_GetFaultBrakeIntFlag
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt of selected source.
Definition: pwm.c:763
PWM_DisableCaptureInt
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function disable capture interrupt of selected channel.
Definition: pwm.c:628
PWM_DisableFaultBrakeInt
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
Definition: pwm.c:735
PWM_ConfigOutputChannel
uint32_t PWM_ConfigOutputChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode.
Definition: pwm.c:37
PWM_GetADCTriggerFlag
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
Definition: pwm.c:457
PWM_DisableCapture
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
Definition: pwm.c:540
PWM_DisableDutyInt
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable duty interrupt of selected channel.
Definition: pwm.c:688
PWM_ClearDutyIntFlag
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
Definition: pwm.c:699
PWM_EnablePeriodInt
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
Definition: pwm.c:778
PWM_EnableFaultBrake
void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
This function enable fault brake of selected channels.
Definition: pwm.c:487
PWM_GetDutyIntFlag
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
Definition: pwm.c:713
PWM_DisableDeadZone
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:594
PWM_DisableOutput
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:565
PWM_ClearFaultBrakeIntFlag
void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
Definition: pwm.c:748
PWM_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:361
PWM_ClearPeriodIntFlag
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
Definition: pwm.c:803
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:553
PWM_EnableFaultBrakeInt
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
Definition: pwm.c:724
PWM_GetCaptureIntFlag
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
Definition: pwm.c:660
PWM_GetPeriodIntFlag
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
Definition: pwm.c:817
PWM_ClearFaultBrakeFlag
void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake flag.
Definition: pwm.c:511
PWM_EnableCaptureInt
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function enable capture interrupt of selected channel.
Definition: pwm.c:612
PWM_EnableADCTrigger
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.
Definition: pwm.c:409
PWM_T
Definition: NUC472_442.h:19042