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));
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))
136 if(u32ChannelMask & (1 << i))
153 uint32_t u32Mask = 0, i;
156 if(u32ChannelMask & (1 << i))
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)
314 PWM->POE |= u32ChannelMask;
326 PWM->POE &= ~u32ChannelMask;
440 PWM->PIIR = u32BrakeSource;
455 return (
PWM->PIIR & u32BrakeSource ? 1 : 0);
#define PWM_PCR_CH0EN_Msk
#define PWM_PIER_INT_TYPE_Msk
#define PWM_PFBCON_BKF_Msk
#define PWM_PFBCON_PWMBKO0_Pos
#define PWM_PIIR_PWMDIF0_Msk
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake flag.
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
#define PWM_DZIR_DZI01_Msk
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
#define PWM_TRIGGER_ADC_CNTR_IS_CMR_U
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
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.
#define PWM_PCR_CH0MOD_Msk
void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
This function enable duty interrupt of selected channel.
#define PWM_TRIGGER_ADC_CNTR_IS_CNR
#define PWM_TRIGGER_ADC_CNTR_IS_CMR_D
#define PWM_PIER_PWMPIE0_Msk
#define PWM_PCR_PWMTYPE_Msk
void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
This function enable fault brake of selected channels.
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function clear selected channel trigger ADC flag.
#define PWM_PIER_PWMDIE0_Msk
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
#define PWM_PCR_DZEN01_Msk
#define PWM_PIER_BRKIE_Msk
#define PWM
Pointer to PWM register structure.
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
#define PWM_PIIR_PWMPIF0_Msk
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable duty interrupt of selected channel.
#define PWM_TRIGGER_ADC_CNTR_IS_0
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt of selected source.
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.