#ifndef _BIANMAQI_H_
#define _BIANMAQI_H_
#include "MYFUN\TIMINIT.H"
#include "MYFUN\BIANLIANGBIAO.H"
//声明PWM捕获终端函数
void DRVPWM_CapIRQHandler1();
void DRVPWM_CapIRQHandler2();
void DRVPWM_CapIRQHandler3();
void DRVPWM_CapIRQHandler4();
void DRVPWM_CapIRQHandler5();
void DRVPWM_CapIRQHandler6();
void DRVPWM_CapIRQHandler7();
void DRVPWM_CapIRQHandler8();
//
void PWMinit()
{
//PWM使能
DrvPWM_Open();
//PWM配置
DrvGPIO_InitFunction(FUNC_PWM01);
DrvGPIO_InitFunction(FUNC_PWM23);
DrvGPIO_InitFunction(FUNC_PWM45);
DrvGPIO_InitFunction(FUNC_PWM67);
//PWM捕获方式
DrvPWM_Enable(DRVPWM_CAP0, 1);
DrvPWM_Enable(DRVPWM_CAP1, 1);
DrvPWM_Enable(DRVPWM_CAP1, 1);
DrvPWM_Enable(DRVPWM_CAP2, 1);
DrvPWM_Enable(DRVPWM_CAP3, 1);
DrvPWM_Enable(DRVPWM_CAP4, 1);
DrvPWM_Enable(DRVPWM_CAP5, 1);
DrvPWM_Enable(DRVPWM_CAP6, 1);
DrvPWM_Enable(DRVPWM_CAP7, 1);
}
//PWM捕获函数
void SETPWMCAP()
{
DrvPWM_SetTimerIO(DRVPWM_CAP0, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP1, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP2, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP3, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP4, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP5, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP6, 1);
DrvPWM_SetTimerIO(DRVPWM_CAP7, 1);
//
DrvPWM_SelectClockSource(DRVPWM_CAP0, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP1, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP2, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP3, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP4, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP5, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP6, DRVPWM_HCLK);
DrvPWM_SelectClockSource(DRVPWM_CAP7, DRVPWM_HCLK);
DrvPWM_EnableInt(DRVPWM_CAP0, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler1);
DrvPWM_EnableInt(DRVPWM_CAP1, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler2);
DrvPWM_EnableInt(DRVPWM_CAP2, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler3);
DrvPWM_EnableInt(DRVPWM_CAP3, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler4);
DrvPWM_EnableInt(DRVPWM_CAP4, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler5);
DrvPWM_EnableInt(DRVPWM_CAP5, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler6);
DrvPWM_EnableInt(DRVPWM_CAP6, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler7);
DrvPWM_EnableInt(DRVPWM_CAP7, DRVPWM_CAP_RISING_FLAG,
*DRVPWM_CapIRQHandler8);
}
//PWM终端函数
void GETPWMIRQ()
{
PWM_RISING[1] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP0,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[1] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP0,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[2] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP1,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[2] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP1,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[3] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP2,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[3] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP2,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[4] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP3,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[4] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP3,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[5] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP4,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[5] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP4,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[6] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP5,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[6] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP5,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[7] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP6,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[7] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP6,
DRVPWM_CAP_FALLING_FLAG);
//
PWM_RISING[8] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP7,
DRVPWM_CAP_RISING_FLAG);
PWM_FALLING[8] = DrvPWM_GetCaptureIntStatus(DRVPWM_CAP7,
DRVPWM_CAP_FALLING_FLAG);
}
//清除捕获中断
void CLRCAPIRQ()
{
// 1
if (PWM_RISING[1])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP0, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[1])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP0, DRVPWM_CAP_FALLING_FLAG);
}
// 2
if (PWM_RISING[2])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP1, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[2])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP1, DRVPWM_CAP_FALLING_FLAG);
}
// 3
if (PWM_RISING[3])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP2, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[3])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP2, DRVPWM_CAP_FALLING_FLAG);
}
// 4
if (PWM_RISING[4])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP3, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[4])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP3, DRVPWM_CAP_FALLING_FLAG);
}
// 5
if (PWM_RISING[5])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP4, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[5])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP4, DRVPWM_CAP_FALLING_FLAG);
}
// 6
if (PWM_RISING[6])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP5, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[6])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP5, DRVPWM_CAP_FALLING_FLAG);
}
// 7
if (PWM_RISING[7])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP6, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[7])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP6, DRVPWM_CAP_FALLING_FLAG);
}
// 8
if (PWM_RISING[8])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP7, DRVPWM_CAP_RISING_FLAG);
}
if (PWM_FALLING[8])
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP7, DRVPWM_CAP_FALLING_FLAG);
}
}
//上电清除中断
void FIRSTCLRCAPIRQ()
{
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP0, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP1, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP2, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP3, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP4, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP5, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP6, DRVPWM_CAP_RISING_FLAG);
DrvPWM_ClearCaptureIntStatus(DRVPWM_CAP7, DRVPWM_CAP_RISING_FLAG);
}
//中断计数
void DRVPWM_CapIRQHandler1()
{
PWM_cnt[1]++;
}
void DRVPWM_CapIRQHandler2()
{
PWM_cnt[2]++;
}
void DRVPWM_CapIRQHandler3()
{
PWM_cnt[3]++;
}
void DRVPWM_CapIRQHandler4()
{
PWM_cnt[4]++;
}
void DRVPWM_CapIRQHandler5()
{
PWM_cnt[5]++;
}
void DRVPWM_CapIRQHandler6()
{
if (CT >0&&CT <100)
PWM_cnt[6]++;
}
void DRVPWM_CapIRQHandler7()
{
PWM_cnt[7]++;
}
void DRVPWM_CapIRQHandler8()
{
PWM_cnt[8]++;
}
#endif
|