| Nano100BN Series BSP V3.03.002 The Board Support Package for Nano100BN Series

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 (4)
33 #define PWM_CH0 (0UL)
34 #define PWM_CH1 (1UL)
35 #define PWM_CH2 (2UL)
36 #define PWM_CH3 (3UL)
37 #define PWM_CH_0_MASK (1UL)
38 #define PWM_CH_1_MASK (2UL)
39 #define PWM_CH_2_MASK (4UL)
40 #define PWM_CH_3_MASK (8UL)
41 #define PWM_CLK_DIV_1 (4UL)
42 #define PWM_CLK_DIV_2 (0UL)
43 #define PWM_CLK_DIV_4 (1UL)
44 #define PWM_CLK_DIV_8 (2UL)
45 #define PWM_CLK_DIV_16 (3UL)
46 #define PWM_EDGE_ALIGNED (0UL)
47 #define PWM_CENTER_ALIGNED (1UL)
48 #define PWM_RISING_LATCH_INT_ENABLE (1UL)
49 #define PWM_FALLING_LATCH_INT_ENABLE (2UL)
50 #define PWM_RISING_FALLING_LATCH_INT_ENABLE (3UL)
51 #define PWM_RISING_LATCH_INT_FLAG (2UL)
52 #define PWM_FALLING_LATCH_INT_FLAG (4UL)
53 #define PWM_RISING_FALLING_LATCH_INT_FLAG (6UL)
54 #define PWM_RISING_LATCH_PDMA_ENABLE (0x10UL)
55 #define PWM_FALLING_LATCH_PDMA_ENABLE (0x20UL)
56 #define PWM_RISING_FALLING_LATCH_PDMA_ENABLE (0x30UL)
57 #define PWM_CAP_PDMA_RFORDER_R (0x1000UL)
58 #define PWM_CAP_PDMA_RFORDER_F (0UL)
60 /* end of group NANO100_PWM_EXPORTED_CONSTANTS */
61
62
75 #define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask)\
76 do { \
77 uint8_t i; \
78 (pwm)->CTL &= ~(PWM_CTL_CH0INV_Msk | PWM_CTL_CH1INV_Msk | PWM_CTL_CH2INV_Msk | PWM_CTL_CH3INV_Msk);\
79 for (i = 0; i < PWM_CHANNEL_NUM; i++) { \
80 if ( (u32ChannelMask) & (1 << i)) { \
81 (pwm)->CTL |= (PWM_CTL_CH0INV_Msk << (i * 8)); \
82 } \
83 } \
84 }while(0)
85
86
94 #define PWM_GET_CAPTURE_RISING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&pwm->CRL0 + 2 * u32ChannelNum))
95
103 #define PWM_GET_CAPTURE_FALLING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&pwm->CFL0 + 2 * u32ChannelNum))
104
115 #define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
116 (pwm->PRES = (pwm->PRES & ~(PWM_PRES_CP01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
117
131 #define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
132 (pwm->CLKSEL = (pwm->CLKSEL & ~(PWM_CLKSEL_CLKSEL0_Msk << (4 * u32ChannelNum))) | (u32Divider << (4 * u32ChannelNum)))
133
143 #define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) \
144 do { \
145 *(__IO uint32_t *) (&pwm->DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CM_Msk; \
146 *(__IO uint32_t *) (&pwm->DUTY0 + 3 * u32ChannelNum) |= (u32CMR << PWM_DUTY_CM_Pos); \
147 }while(0)
148
159 #define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) \
160 do { \
161 *(__IO uint32_t *) (&pwm->DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CN_Msk; \
162 *(__IO uint32_t *) (&pwm->DUTY0 + 3 * u32ChannelNum) |= u32CNR; \
163 } while(0)
164
165 uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
166 uint32_t u32ChannelNum,
167 uint32_t u32Frequency,
168 uint32_t u32DutyCycle);
169 uint32_t PWM_ConfigCaptureChannel (PWM_T *pwm,
170 uint32_t u32ChannelNum,
171 uint32_t u32UnitTimeNsec,
172 uint32_t u32CaptureEdge);
173 void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
174 void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
175 void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
176 void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
177 void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
178 void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
179 void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
180 void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
181 void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
182 void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
183 void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
184 void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
185 uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
186 void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
187 void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
188 void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
189 uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
190 void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode);
191 void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum);
192 /* end of group NANO100_PWM_EXPORTED_FUNCTIONS */
194 /* end of group NANO100_PWM_Driver */
196 /* end of group NANO100_Device_Driver */
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif //__PWM_H__
204
205 /*** (C) COPYRIGHT 2013-2014 Nuvoton Technology Corp. ***/
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:334
PWM_DisablePeriodInt
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
Definition: pwm.c:466
PWM_GetPeriodIntFlag
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
Definition: pwm.c:491
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:268
PWM_EnableCapture
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
Definition: pwm.c:285
PWM_Stop
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:248
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:454
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:409
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:359
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:425
PWM_DisableOutput
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:346
PWM_DisablePDMA
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable capture PDMA of selected channel.
Definition: pwm.c:523
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_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:142
PWM_GetCaptureIntFlag
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
Definition: pwm.c:441
PWM_EnablePDMA
void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
This function enable capture PDMA of selected channel.
Definition: pwm.c:509
PWM_ClearPeriodIntFlag
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
Definition: pwm.c:477
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:393
PWM_DisableCapture
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
Definition: pwm.c:308
PWM_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:227
PWM_DisableDeadZone
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:375
PWM_T
Definition: Nano100Series.h:6583