38 uint32_t u32ChannelNum,
39 uint32_t u32Frequency,
40 uint32_t u32DutyCycle)
43 uint8_t u8Divider = 1, u8Prescale = 0xFF;
44 uint16_t u16CNR = 0xFFFF;
46 for(; u8Divider < 17; u8Divider <<= 1)
50 if(i > (0x10000 * 0x100))
54 u8Prescale = (i + 0xFFFF)/ 0x10000;
80 else if (u8Divider == 2)
82 else if (u8Divider == 4)
84 else if (u8Divider == 8)
90 PWM->PPR = (
PWM->PPR & ~(PWM_PPR_CP01_Msk << ((u32ChannelNum >> 1) * 8))) | (u8Prescale << ((u32ChannelNum >> 1) * 8));
91 PWM->CSR = (
PWM->CSR & ~(PWM_CSR_CSR0_Msk << (4 * u32ChannelNum))) | (u8Divider << (4 * u32ChannelNum));
92 PWM->PCR = (
PWM->PCR & ~PWM_PCR_PWMTYPE_Msk) | (PWM_PCR_CH0MOD_Msk << (4 * u32ChannelNum));
94 PWM->CMR[u32ChannelNum] = 0;
96 PWM->CMR[u32ChannelNum] = u32DutyCycle * (u16CNR + 1) / 100 - 1;
97 PWM->CNR[u32ChannelNum] = u16CNR;
112 uint32_t u32Mask = 0, i;
115 if(u32ChannelMask & (1 << i))
117 u32Mask |= (PWM_PCR_CH0EN_Msk << (i * 4));
136 if(u32ChannelMask & (1 << i))
153 uint32_t u32Mask = 0, i;
156 if(u32ChannelMask & (1 << i))
158 u32Mask |= (PWM_PCR_CH0EN_Msk << (i * 4));
162 PWM->PCR &= ~u32Mask;
178 if(u32ChannelNum < 4)
203 if(u32ChannelNum < 4)
232 if(u32ChannelNum < 4)
234 PWM->TRGSTS0 |= (u32Condition << (8 * u32ChannelNum));
238 PWM->TRGSTS1 |= (u32Condition << (8 * (u32ChannelNum - 4)));
256 if(u32ChannelNum < 4)
258 u32Ret =
PWM->TRGSTS0 >> (8 * u32ChannelNum);
262 u32Ret =
PWM->TRGSTS1 >> (8 * (u32ChannelNum - 4 ));
286 uint32_t u32ChannelMask,
287 uint32_t u32LevelMask,
288 uint32_t u32BrakeSource)
290 PWM->PFBCON = (u32LevelMask << PWM_PFBCON_PWMBKO0_Pos) | u32BrakeSource;
302 PWM->PFBCON = PWM_PFBCON_BKF_Msk;
314 PWM->POE |= u32ChannelMask;
326 PWM->POE &= ~u32ChannelMask;
342 PWM->PDZIR = (
PWM->PDZIR & ~(PWM_DZIR_DZI01_Msk << (8 * u32ChannelNum))) | (u32Duration << (8 * u32ChannelNum));
344 PWM->PCR |= (PWM_PCR_DZEN01_Msk << u32ChannelNum);
358 PWM->PCR &= ~(PWM_PCR_DZEN01_Msk << u32ChannelNum);
370 PWM->PIER |= (PWM_PIER_PWMDIE0_Msk << u32ChannelNum);
381 PWM->PIER &= ~(PWM_PIER_PWMDIE0_Msk << u32ChannelNum);
392 PWM->PIIR = (PWM_PIIR_PWMDIF0_Msk << u32ChannelNum);
405 return(
PWM->PIIR & (PWM_PIIR_PWMDIF0_Msk << u32ChannelNum) ? 1 : 0);
416 PWM->PIER |= PWM_PIER_BRKIE_Msk;
427 PWM->PIER &= ~PWM_PIER_BRKIE_Msk;
440 PWM->PIIR = u32BrakeSource;
455 return (
PWM->PIIR & u32BrakeSource ? 1 : 0);
470 PWM->PIER = (
PWM->PIER & ~PWM_PIER_INT_TYPE_Msk) | (PWM_PIER_PWMPIE0_Msk << u32ChannelNum) | u32IntPeriodType;
481 PWM->PIER &= ~(PWM_PIER_PWMPIE0_Msk << u32ChannelNum);
492 PWM->PIIR = (PWM_PIIR_PWMPIF0_Msk << u32ChannelNum);
505 return(
PWM->PIIR & (PWM_PIIR_PWMPIF0_Msk << u32ChannelNum) ? 1 : 0);
NUC029FAE peripheral access layer header file. This file contains all the peripheral register's defin...
#define PWM
Pointer to PWM register structure.
#define PWM_TRIGGER_ADC_CNTR_IS_0
#define PWM_TRIGGER_ADC_CNTR_IS_CMR_U
#define PWM_TRIGGER_ADC_CNTR_IS_CNR
#define PWM_TRIGGER_ADC_CNTR_IS_CMR_D
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_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone 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.
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_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_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_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_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.