/* 波形1的基波输出函数: 状态机
* |----stage1----| _______stage2____.
* stage1: CMR=CNR,输出高电平脉宽
* stage2: CMR=0; ,输出低电平脉宽,
* stage2中, 如果低电平的脉宽数大于65535,则
*/
static u16 wave1_s2_n = 0;
static u16 wave2_s2_n = 0;
static u16 wave3_s2_n = 0;
void pwm_wave1( void )
{
/* 状态0:输出脉冲高电平(脉宽)*/
if(SYS_wave1_state == 0 )
{
/* 判断是否具有空周期,没有则一直在状态0 */
if( SYS_wave1_s2_n >0 )
{
SYS_wave1_state =1;
wave1_s2_n = SYS_wave1_s2_n;
}
else
{
SYS_wave1_state = 0;
}
/*根据pwm的硬件特性,输出时,cmr尽量在前面 */
PWM_SET_CMR(PWMB,0,SYS_wave1_cmr_s1);
if( SYS_wave1_cnr_s1 == 0 ) SYS_wave1_cnr_s1 = 1250;
PWM_SET_CNR(PWMB,0,SYS_wave1_cnr_s1 );
}
else
{
SYS_UnlockReg();
SYS->P2_MFP &= ~(SYS_MFP_P24_Msk );
SYS->P2_MFP |= SYS_MFP_P24_GPIO ;
SYS_LockReg();
WAVE1_PWM =0;
/* 低电平重复次数 */
if( wave1_s2_n >0)
{
wave1_s2_n --;
/*s2 输出完毕,切换到s1*/
if(wave1_s2_n ==0)
{
/* 推出低电平输出,*/
SYS_wave1_state = 0;
SYS_UnlockReg();
SYS->P2_MFP &= ~(SYS_MFP_P24_Msk );
SYS->P2_MFP |= SYS_MFP_P24_PWM4 ;
SYS_LockReg();
}
}
PWM_SET_CMR(PWMB,0,SYS_wave1_cmr_s2);
if( SYS_wave1_cnr_s2 == 0 ) SYS_wave1_cnr_s2 = 1250;
PWM_SET_CNR(PWMB,0,SYS_wave1_cnr_s2);
}
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] PWMA IRQ Handler,处理本项目的 PWM4-7
*
* @param None
*
* [url=home.php?mod=space&uid=266161]@return[/url] None
*
* [url=home.php?mod=space&uid=1543424]@Details[/url] ISR to handle PWMB interrupt event
*/
void PWMB_IRQHandler(void)
{
uint32_t u32PwmIntFlag;
/* Handle PWMA Timer function */
u32PwmIntFlag = PWMB->PIIR;
/* PWMB channel 0 PWM timer interrupt */
if(u32PwmIntFlag & PWM_PIIR_PWMIF0_Msk)
{
PWMB->PIIR =PWM_PIIR_PWMIF0_Msk;
pwm_wave1();
}
if(u32PwmIntFlag & PWM_PIIR_PWMIF2_Msk)
{
PWMB->PIIR =PWM_PIIR_PWMIF2_Msk;
pwm_wave2();
}
if(u32PwmIntFlag & PWM_PIIR_PWMIF1_Msk)
{
PWMB->PIIR =PWM_PIIR_PWMIF1_Msk;
pwm_wave3();
}
if(u32PwmIntFlag & PWM_PIIR_PWMIF3_Msk)
{
PWMB->PIIR = PWM_PIIR_PWMIF3_Msk;
pwm_wave4();
}
}
|