| Nano102_112 Series BSP V3.03.002 The Board Support Package for Nano102_112 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 NANO1X2_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
93 #define PWM_GET_CAPTURE_RISING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->CRL0 + 2 * (u32ChannelNum)))
94
102 #define PWM_GET_CAPTURE_FALLING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->CFL0 + 2 * (u32ChannelNum)))
103
114 #define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
115 ((pwm)->PRES = ((pwm)->PRES & ~(PWM_PRES_CP01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
116
130 #define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
131 ((pwm)->CLKSEL = ((pwm)->CLKSEL & ~(PWM_CLKSEL_CLKSEL0_Msk << (4 * (u32ChannelNum)))) | (u32Divider << (4 * (u32ChannelNum))))
132
142 #define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) \
143 do { \
144 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) &= ~PWM_DUTY0_CM_Msk; \
145 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) |= (u32CMR << PWM_DUTY0_CM_Pos); \
146 }while(0)
147
158 #define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) \
159 do { \
160 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) &= ~PWM_DUTY0_CN_Msk; \
161 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) |= u32CNR; \
162 } while(0)
163
175 #define PWM_SET_ALIGNED_TYPE(pwm, u32ChannelMask, u32AlignedType) \
176 do { \
177 uint8_t i; \
178 (pwm)->CTL &= ~(PWM_CTL_PWMTYPE01_Msk | PWM_CTL_PWMTYPE23_Msk); \
179 for (i = 0; i < PWM_CHANNEL_NUM; i++) { \
180 if (u32AlignedType == PWM_CENTER_ALIGNED) \
181 if ( (u32ChannelMask) & (1 << i)) \
182 (pwm)->CTL |= (PWM_CTL_PWMTYPE01_Msk << (i >> 1)); \
183 } \
184 } while(0)
185
186 uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
187 uint32_t u32ChannelNum,
188 uint32_t u32Frequency,
189 uint32_t u32DutyCycle);
190 uint32_t PWM_ConfigCaptureChannel (PWM_T *pwm,
191 uint32_t u32ChannelNum,
192 uint32_t u32UnitTimeNsec,
193 uint32_t u32CaptureEdge);
194 void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
195 void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
196 void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
197 void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
198 void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum);
199 void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
200 uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum);
201 void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
202 void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
203 void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
204 void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
205 void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
206 void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
207 void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
208 void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
209 void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
210 uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
211 void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType);
212 void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum);
213 void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
214 uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
215 void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
216 void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
217 void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
218 uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
219 void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode);
220 void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum);
221
222
223 /* end of group NANO1X2_PWM_EXPORTED_FUNCTIONS */
225 /* end of group NANO1X2_PWM_Driver */
227 /* end of group NANO1X2_Device_Driver */
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif //__PWM_H__
235
236 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
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:578
PWM_DisableADCTrigger
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
Definition: pwm.c:289
PWM_GetADCTriggerFlag
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
Definition: pwm.c:314
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:301
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:261
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:469
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:138
PWM_EnableDutyInt
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
PWM_GetPeriodIntFlag
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
Definition: pwm.c:560
PWM_DisableCapture
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
Definition: pwm.c:350
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:278
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:453
PWM_Stop
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:241
PWM_DisableDeadZone
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:419
PWM_EnableCapture
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
Definition: pwm.c:327
PWM_GetCaptureIntFlag
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
Definition: pwm.c:485
PWM_GetDutyIntFlag
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
Definition: pwm.c:510
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:437
PWM_DisablePeriodInt
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
Definition: pwm.c:535
PWM_ClearPeriodIntFlag
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
Definition: pwm.c:546
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:378
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_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:220
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:403
PWM_DisableDutyInt
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
PWM_ClearDutyIntFlag
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
Definition: pwm.c:496
PWM_DisableOutput
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:390
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:523
PWM_DisablePDMA
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable capture PDMA of selected channel.
Definition: pwm.c:592
PWM_T
Definition: Nano1X2Series.h:5734