NANO100_BSP V3.04.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
16extern "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) /* end of group NANO100_PWM_EXPORTED_CONSTANTS */
61
62
75#define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask)\
76do { \
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) \
144do { \
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) \
160do { \
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
165uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
166 uint32_t u32ChannelNum,
167 uint32_t u32Frequency,
168 uint32_t u32DutyCycle);
169uint32_t PWM_ConfigCaptureChannel (PWM_T *pwm,
170 uint32_t u32ChannelNum,
171 uint32_t u32UnitTimeNsec,
172 uint32_t u32CaptureEdge);
173void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
174void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
175void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
176void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
177void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask);
178void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
179void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
180void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
181void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
182void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
183void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
184void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge);
185uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
186void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
187void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
188void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
189uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
190void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode);
191void 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. ***/
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
Definition: pwm.c:268
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:248
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
Definition: pwm.c:285
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
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
Definition: pwm.c:359
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
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
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
Definition: pwm.c:466
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function disable capture interrupt of selected channel.
Definition: pwm.c:409
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
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
Definition: pwm.c:308
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
Definition: pwm.c:454
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:375
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:346
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable capture PDMA of selected channel.
Definition: pwm.c:523
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:227
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
Definition: pwm.c:477
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:334
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
Definition: pwm.c:441
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
Definition: pwm.c:491
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function enable capture interrupt of selected channel.
Definition: pwm.c:393