//************************************************************************ void turnOffPWM(uint8_t timer) { switch(timer) { #ifdef _OCMP1 case TIMER_OC1: CloseOC1(); break; #endif #ifdef _OCMP2 case TIMER_OC2: CloseOC2(); break; #endif #ifdef _OCMP3 case TIMER_OC3: CloseOC3(); break; #endif #ifdef _OCMP4 case TIMER_OC4: CloseOC4(); break; #endif #ifdef _OCMP5 case TIMER_OC5: CloseOC5(); break; #endif } }
// Interrupt Service Routine for TIMER 3. This is used to switch between the // buzzing and quiet periods when ON_CYCLES or OFF_CYCLES are reached. extern "C" void __ISR (_TIMER_3_VECTOR, ipl5) T3_IntHandler (void) { alarm--; if (alarm == 0) { buzzing = !buzzing; if (is_buzzer_on && buzzing) { switch(BUZZER_PIN) { case 9: OpenOC4(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE, DUTY_CYCLE, 0); break; case 10: OpenOC5(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE, DUTY_CYCLE, 0); break; } alarm = ON_CYCLES; } else { switch(BUZZER_PIN) { case 9: CloseOC4(); break; case 10: CloseOC5(); break; } alarm = OFF_CYCLES; pin_write(BUZZER_PIN, LOW); } } // Clear interrupt flag // This will break other interrupts and millis() (read+clear+write race condition?) // IFS0bits.T3IF = 0; // DON'T!! // Instead: mT3ClearIntFlag(); }
/**************************************************************************** Function PWM_end Parameters None. Returns None Description Disables the PWM sub-system. Notes Simply releases the lines and disables the timer Author Max Dunne, 2011.11.14 ****************************************************************************/ void PWM_end(void) { CloseTimer2(); CloseOC1(); CloseOC2(); CloseOC3(); CloseOC4(); CloseOC5(); usedChannels=0; }