CAP_disableInt(myCap, CAP_Int_Type_All); // Disable all capture interrupts
CAP_clearInt(myCap, CAP_Int_Type_All); // Clear all CAP interrupt flags
CAP_disableCaptureLoad(myCap); // Disable CAP1-CAP4 register loads
CAP_disableTimestampCounter(myCap); // Make sure the counter is stopped
void InitECapture()
{
CLK_enableEcap1Clock(myClk);
CAP_disableInt(myCap, CAP_Int_Type_All); // Disable all capture interrupts
CAP_clearInt(myCap, CAP_Int_Type_All); // Clear all CAP interrupt flags
CAP_disableCaptureLoad(myCap); // Disable CAP1-CAP4 register loads
CAP_disableTimestampCounter(myCap); // Make sure the counter is stopped
// Configure peripheral registers
CAP_setCapOneShot(myCap); // One-shot
CAP_setStopWrap(myCap, CAP_Stop_Wrap_CEVT4);// Stop at 4 events
CAP_setCapEvtPolarity(myCap, CAP_Event_1, CAP_Polarity_Falling); // Falling edge
CAP_setCapEvtPolarity(myCap, CAP_Event_2, CAP_Polarity_Rising); // Rising edge
CAP_setCapEvtPolarity(myCap, CAP_Event_3, CAP_Polarity_Falling); // Falling edge
CAP_setCapEvtPolarity(myCap, CAP_Event_4, CAP_Polarity_Rising); // Rising edge
CAP_setCapEvtReset(myCap, CAP_Event_1, CAP_Reset_Enable); // Difference operation
CAP_setCapEvtReset(myCap, CAP_Event_2, CAP_Reset_Enable); // Difference operation
CAP_setCapEvtReset(myCap, CAP_Event_3, CAP_Reset_Enable); // Difference operation
CAP_setCapEvtReset(myCap, CAP_Event_4, CAP_Reset_Enable); // Difference operation
CAP_enableSyncIn(myCap); // Enable sync in
CAP_setSyncOut(myCap, CAP_SyncOut_SyncIn); // Pass through
CAP_enableCaptureLoad(myCap);
CAP_enableTimestampCounter(myCap); // Start Counter
CAP_rearm(myCap); // arm one-shot
CAP_enableCaptureLoad(myCap); // Enable CAP1-CAP4 register loads
CAP_enableInt(myCap, CAP_Int_Type_CEVT4); // 4 events = interrupt
}
interrupt void ecap1_isr(void)
{
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation
if(CAP_getCap2(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap2(myCap) < PWM_getPeriod(myPwm)*2-1)
{
Fail();
}
if(CAP_getCap3(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap3(myCap) < PWM_getPeriod(myPwm)*2-1)
{
Fail();
}
if(CAP_getCap4(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap4(myCap) < PWM_getPeriod(myPwm)*2-1)
{
Fail();
}
ECap1IntCount++;
if(EPwm3TimerDirection == EPwm_TIMER_UP) {
if(PWM_getPeriod(myPwm) < PWM3_TIMER_MAX) {
PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) + 1);
}
else {
EPwm3TimerDirection = EPwm_TIMER_DOWN;
PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) - 1);
}
}
else {
if(PWM_getPeriod(myPwm) > PWM3_TIMER_MIN) {
PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) - 1);
}
else {
EPwm3TimerDirection = EPwm_TIMER_UP;
PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) + 1);
}
}
ECap1PassCount++;
CAP_clearInt(myCap, CAP_Int_Type_CEVT4);
CAP_clearInt(myCap, CAP_Int_Type_Global);
CAP_rearm(myCap);
// Acknowledge this interrupt to receive more interrupts from group 4
PIE_clearInt(myPie, PIE_GroupNumber_4);
}
void Fail()
{
asm(" ESTOP0");
}
一周热门 更多>