38 uint32_t u32ChannelNum,
39 uint32_t u32Frequency,
40 uint32_t u32DutyCycle)
43 uint32_t u32PWM_CLock =
__HIRC;
44 uint8_t u8Divider = 1, u8Prescale = 0xFF;
45 uint16_t u16CNR = 0xFFFF;
50 if (u32ChannelNum < 2)
63 else if (u32ChannelNum < 4)
76 else if (u32ChannelNum < 6)
92 if (u32ChannelNum < 2)
105 else if (u32ChannelNum < 4)
108 u32PWM_CLock =
__HXT;
110 u32PWM_CLock =
__LXT;
118 else if (u32ChannelNum < 6)
121 u32PWM_CLock =
__HXT;
123 u32PWM_CLock =
__LXT;
133 for(; u8Divider < 17; u8Divider <<= 1)
135 i = (u32PWM_CLock / u32Frequency) / u8Divider;
137 if(i > (0x10000 * 0x100))
141 u8Prescale = (i + 0xFFFF)/ 0x10000;
160 i = u32PWM_CLock / (u8Prescale * u8Divider * u16CNR);
167 else if (u8Divider == 2)
169 else if (u8Divider == 4)
171 else if (u8Divider == 8)
177 while((pwm->
SBS[u32ChannelNum] & 1) == 1)
188 if(u32DutyCycle == 0)
189 pwm->
CMPDAT[u32ChannelNum] = 0;
191 pwm->
CMPDAT[u32ChannelNum] = u32DutyCycle * (u16CNR + 1) / 100 - 1;
192 pwm->
PERIOD[u32ChannelNum] = u16CNR;
208 uint32_t u32ChannelNum,
209 uint32_t u32UnitTimeNsec,
210 uint32_t u32CaptureEdge)
213 uint32_t u32PWM_CLock =
__HIRC;
214 uint8_t u8Divider = 1, u8Prescale = 0xFF;
215 uint16_t u16CNR = 0xFFFF;
220 if (u32ChannelNum < 2)
223 u32PWM_CLock =
__HXT;
225 u32PWM_CLock =
__LXT;
233 else if (u32ChannelNum < 4)
236 u32PWM_CLock =
__HXT;
238 u32PWM_CLock =
__LXT;
246 else if (u32ChannelNum < 6)
249 u32PWM_CLock =
__HXT;
251 u32PWM_CLock =
__LXT;
260 else if (pwm ==
PWM1)
262 if (u32ChannelNum < 2)
265 u32PWM_CLock =
__HXT;
267 u32PWM_CLock =
__LXT;
275 else if (u32ChannelNum < 4)
278 u32PWM_CLock =
__HXT;
280 u32PWM_CLock =
__LXT;
288 else if (u32ChannelNum < 6)
291 u32PWM_CLock =
__HXT;
293 u32PWM_CLock =
__LXT;
303 for(; u8Divider < 17; u8Divider <<= 1)
305 i = ((u32PWM_CLock / u8Divider) * u32UnitTimeNsec) / 1000000000;
321 i = (u8Prescale * u8Divider) * 1000000000/ u32PWM_CLock;
328 else if (u8Divider == 2)
330 else if (u8Divider == 4)
332 else if (u8Divider == 8)
338 while((pwm->
SBS[u32ChannelNum] & 1) == 1)
349 pwm->
PERIOD[u32ChannelNum] = u16CNR;
363 pwm->
CNTEN |= u32ChannelMask;
378 if(u32ChannelMask & (1 << i))
380 *(__IO uint32_t *) (&pwm->
CNTEN + 1 * i) = 0;
395 pwm->
CNTEN &= ~u32ChannelMask;
444 pwm->
TRGADCSTS |= (u32Condition << (1 * u32ChannelNum));
461 u32Ret = pwm->
TRGADCSTS >> u32ChannelNum;
488 uint32_t u32ChannelMask,
489 uint32_t u32LevelMask,
490 uint32_t u32BrakeSource)
513 if (u32BrakeSource == 0)
528 pwm->
CAPCTL |= u32ChannelMask;
529 pwm->
CAPINEN |= u32ChannelMask;
542 pwm->
CAPCTL &= ~u32ChannelMask;
543 pwm->
CAPINEN &= ~u32ChannelMask;
555 pwm->
POEN |= u32ChannelMask;
567 pwm->
POEN &= ~u32ChannelMask;
615 pwm->
INTEN |= (u32Edge << u32ChannelNum);
631 pwm->
INTEN &= ~(u32Edge << u32ChannelNum);
647 pwm->
INTSTS = (u32Edge << u32ChannelNum);
737 pwm->
INTEN &= ~PWM_INTEN_BRKIEN_Msk;
750 pwm->
INTSTS = u32BrakeSource;
765 return (pwm->
INTSTS & u32BrakeSource ? 1 : 0);
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
#define PWM_BRKCTL_BKOD_Pos
#define CLK_CLKSEL2_PWM1CH45SEL_Msk
#define PWM_INTSTS_PIF_Pos
#define PWM_INTSTS_BRKLK0_Msk
#define PWM_CLKDIV_CLKDIV0_Msk
#define PWM_CTL_CNTMODE_Pos
#define PWM_DTCTL_DTCNT01_Msk
#define PWM_BRKCTL_BRK0EN_Msk
#define CLK_CLKSEL2_PWM1CH45SEL_Pos
#define PWM_INTSTS_BRKIF0_Msk
#define PWM_BRKCTL_BRK1EN_Msk
#define CLK_CLKSEL2_PWM0CH23SEL_Msk
#define CLK_CLKSEL2_PWM0CH45SEL_Pos
#define PWM_INTSTS_DIF_Pos
#define CLK_CLKSEL2_PWM0CH23SEL_Pos
#define PWM_DTCTL_DTEN01_Msk
#define CLK_CLKSEL2_PWM1CH23SEL_Pos
#define PWM_INTSTS_BRKIF1_Msk
#define PWM_INTEN_PIEN_Pos
#define CLK_CLKSEL2_PWM1CH01SEL_Pos
#define CLK_CLKSEL2_PWM1CH01SEL_Msk
#define PWM_INTEN_DIEN_Pos
#define CLK_CLKSEL2_PWM1CH23SEL_Msk
#define PWM_BRKCTL_LVDBKEN_Msk
#define CLK_CLKSEL2_PWM0CH01SEL_Msk
#define CLK_CLKSEL2_PWM0CH45SEL_Msk
#define PWM_INTEN_BRKIEN_Msk
#define PWM_CLKPSC_CLKPSC01_Msk
#define PWM_PERIOD_INT_MATCH_CNR
#define PWM_TRIGGER_ADC_FALLING_EDGE_POINT
#define PWM_DUTY_INT_MATCH_CMR_UP
#define PWM_TRIGGER_ADC_RISING_EDGE_POINT
#define PWM_RISING_FALLING_LATCH_INT_FLAG
#define PWM_TRIGGER_ADC_PERIOD_POINT
#define PWM_TRIGGER_ADC_CENTER_POINT
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_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.
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function clear selected channel trigger ADC flag.
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
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_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
This function enable duty interrupt of selected channel.
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt of selected source.
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function disable capture interrupt of selected channel.
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
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.
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable duty interrupt of selected channel.
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
This function enable fault brake of selected channels.
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag 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_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
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.
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
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_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake flag.
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function enable capture interrupt of selected channel.
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.