38 uint32_t u32ChannelNum,
39 uint32_t u32Frequency,
40 uint32_t u32DutyCycle)
45 uint8_t u8Divider = 1, u8Prescale = 0xFF;
46 uint16_t u16CNR = 0xFFFF;
70 for(; u8Divider < 17; u8Divider <<= 1)
72 i = (u32PWM_Clock / u32Frequency) / u8Divider;
74 if(i > (0x10000 * 0x100))
78 u8Prescale = (i + 0xFFFF)/ 0x10000;
97 i = u32PWM_Clock / (u8Prescale * u8Divider * u16CNR);
104 else if (u8Divider == 2)
106 else if (u8Divider == 4)
108 else if (u8Divider == 8)
115 pwm->
PRES = (pwm->
PRES & ~(
PWM_PRES_CP01_Msk << ((u32ChannelNum >> 1) * 8))) | (u8Prescale << ((u32ChannelNum >> 1) * 8));
119 if(u32DutyCycle == 0)
120 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CM_Msk;
123 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CM_Msk;
124 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) |= ((u32DutyCycle * (u16CNR + 1) / 100 - 1) <<
PWM_DUTY_CM_Pos);
126 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CN_Msk;
127 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) |= u16CNR;
143 uint32_t u32ChannelNum,
144 uint32_t u32UnitTimeNsec,
145 uint32_t u32CaptureEdge)
150 uint8_t u8Divider = 1, u8Prescale = 0xFF;
151 uint16_t u16CNR = 0xFFFF;
161 u32PWM_Clock =
__HXT;
164 u32PWM_Clock =
__LXT;
174 for(; u8Divider < 17; u8Divider <<= 1)
176 i = ((
long long)(u32PWM_Clock / u8Divider) * u32UnitTimeNsec) / 1000000000;
192 i = (
long long) (u8Prescale * u8Divider) * 1000000000 / u32PWM_Clock;
199 else if (u8Divider == 2)
201 else if (u8Divider == 4)
203 else if (u8Divider == 8)
210 pwm->
PRES = (pwm->
PRES & ~(
PWM_PRES_CP01_Msk << ((u32ChannelNum >> 1) * 8))) | (u8Prescale << ((u32ChannelNum >> 1) * 8));
214 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) &= ~PWM_DUTY_CN_Msk;
215 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * u32ChannelNum) |= u16CNR;
230 uint32_t u32Mask = 0;
234 if ( u32ChannelMask & (1 << i))
253 if(u32ChannelMask & (1 << i))
255 *(__IO uint32_t *) (&pwm->
DUTY0 + 3 * i) &= ~PWM_DUTY_CN_Msk;
273 if ( u32ChannelMask & (1 << i))
288 uint32_t u32Mask = 0;
292 if ( u32ChannelMask & (1 << i))
311 uint32_t u32CTLMask = 0;
312 uint32_t u32CAPCTLMask = 0;
316 if ( u32ChannelMask & (1 << i))
323 pwm->
CTL &= ~u32CTLMask;
324 pwm->
CAPCTL &= ~u32CAPCTLMask;
336 pwm->
OE |= u32ChannelMask;
348 pwm->
OE &= ~u32ChannelMask;
396 pwm->
CAPINTEN |= (u32Edge << (u32ChannelNum * 8));
412 pwm->
CAPINTEN &= ~(u32Edge << (u32ChannelNum * 8));
428 pwm->
CAPINTSTS = (u32Edge + 1) << (u32ChannelNum * 8);
511 if (u32ChannelNum == 0)
525 if (u32ChannelNum == 0)
526 pwm->
CAPCTL &= ~PWM_CAPCTL_CH0PDMAEN_Msk;
528 pwm->
CAPCTL &= ~PWM_CAPCTL_CH2PDMAEN_Msk;
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
#define PWM_CAPCTL_PDMACAPMOD0_Msk
#define PWM_INTEN_TMIE0_Msk
#define PWM_CAPCTL_CH0RFORDER_Msk
#define PWM_PRES_CP01_Msk
#define PWM_CLKSEL_CLKSEL0_Msk
#define PWM_PRES_DZ01_Msk
#define PWM_INTSTS_DUTY0SYNC_Msk
#define PWM_CAPCTL_PDMACAPMOD2_Msk
#define PWM_CAPCTL_CH2RFORDER_Msk
#define PWM_CAPCTL_CAPCH0EN_Msk
#define PWM_CAPCTL_CH0PDMAEN_Msk
#define PWM_CTL_CH0MOD_Msk
#define PWM_CTL_CH0EN_Msk
#define PWM_CTL_DZEN01_Msk
#define PWM_PRES_DZ01_Pos
#define PWM_INTSTS_TMINT0_Msk
#define PWM_INTSTS_PRESSYNC_Msk
#define PWM_CAPCTL_CAPCH0PADEN_Msk
#define PWM_CAPCTL_CH2PDMAEN_Msk
#define CLK_CLKSEL1_PWM0_CH01_S_Pos
#define CLK_CLKSEL2_PWM1_CH01_S_Msk
#define CLK_CLKSEL1_PWM0_CH01_S_Msk
#define CLK_CLKSEL2_PWM1_CH01_S_Pos
#define CLK
Pointer to CLK register structure.
#define PWM0
Pointer to PWM0 register structure.
#define PWM_RISING_FALLING_LATCH_INT_FLAG
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
This function enable capture PDMA of selected channel.
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function clear capture interrupt flag of selected channel.
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.
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function disable capture interrupt of selected channel.
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.
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable capture PDMA of selected channel.
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function enable capture interrupt of selected channel.