//void servo_interrupt() void Timer2Interrupt(void) { // is this an TMR1 interrupt ? if (IntGetFlag(INT_TIMER2)) { if (phase) { ServosPulseUp(); PR2 = f500us; // load period register phase = 0; } else { ServosPulseDown(); // 2 ms PR2 = f20ms; // load period register if (needreordering) SortServoTimings(); // 1 ms phase = 1; // will start the servos cycle on next interrupt } // enable interrupt again IntClearFlag(INT_TIMER2); } }
void IRrecv_enableIRIn(u8 recvpin) { u32 f=GetPeripheralClock(); // Configure interrupt IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); IntSetVectorPriority(INT_TIMER3_VECTOR, 7, 3); IntClearFlag(INT_TIMER3); IntEnable(INT_TIMER3); // Configure Timer3 to overload every 50us T3CON = 0; // no prescaler TMR3 = 0; // clear timer register PR3 = 50*(f/1000/1000); // nb cycles / 50 us T3CONSET = 0x8000; // start timer 1 // initialize state machine variables irparams.recvpin = recvpin; irparams.blinkflag = 0; irparams.rcvstate = STATE_IDLE; irparams.rawlen = 0; // set pin modes pinmode(irparams.recvpin, INPUT); }
void RTCCInterrupt(void) { if (IntGetFlag(INT_REAL_TIME_CLOCK)) { IntClearFlag(INT_REAL_TIME_CLOCK); intFunction(); } }
u32 OnTimer1(callback func, u32 timediv, u32 delay) { u32 tckps=0, freqhz, period; if (intUsed[INT_TIMER1] == INT_NOT_USED) { intUsed[INT_TIMER1] = INT_USED; intFunction[INT_TIMER1] = func; intCount[1] = 0; intCountLimit[1] = delay; // TMR1 Count register increments on every PBCLK clock cycle freqhz = GetPeripheralClock(); // Freq (Hz) = Nb ticks/sec. switch(timediv) { case INT_SEC: period = freqhz; break; case INT_MILLISEC: period = freqhz / 1000; break; case INT_MICROSEC: period = freqhz / 1000000; break; } // Timer1 period is 16-bit, only 4 prescaler values while ((period > 0xFFFF) & (tckps < 5)) { tckps += 1; period /= prescaler1[tckps]; } if (tckps == 4) { tckps = 3; // divided per 256 intCountLimit[1] = delay * 8; } // Configure interrupt IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); IntSetVectorPriority(INT_TIMER1_VECTOR, 7, 3); IntClearFlag(INT_TIMER1); IntEnable(INT_TIMER1); // Configure Timer1 T1CON = tckps << 4; // set prescaler (bit 5-4) TMR1 = 0; // clear timer register PR1 = period; // load period register T1CONSET = 0x8000; // start timer 1 return INT_TIMER1; } else { #ifdef DEBUG debug("Error : TIMER1 interrupt is already used !"); #endif return false; } }
void RTCC_Shutdown(void) { RTCC_SOSCdisable(); RTCC_Disable(); RTCC_SetWriteDisable(); RTCC_AlarmDisable(); RTCC_OutputDisable(); IntClearFlag(INT_REAL_TIME_CLOCK); }
void RTCC_init(void) { RTCC_SOSCenable(); RTCC_Enable(); RTCC_SetWriteDisable(); RTCC_AlarmDisable(); RTCC_OutputDisable(); IntClearFlag(INT_REAL_TIME_CLOCK); }
rtccRes RTCC_Open(unsigned long tm, unsigned long dt, int drift) { RTCC_SOSCenable(); RTCC_SetTime(tm); RTCC_SetDate(dt); RTCC_SetCalibration(drift); RTCC_Enable(); RTCC_AlarmDisable(); RTCC_OutputDisable(); RTCC_SetWriteDisable(); IntClearFlag(INT_REAL_TIME_CLOCK); }
void RTCC_SetAlarmIntEnable(int enable) { if (enable) { IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); IntSetVectorPriority(INT_RTCC_VECTOR, INT_PRIORITY_3, INT_SUBPRIORITY_1); IntClearFlag(INT_REAL_TIME_CLOCK); IntEnable(INT_REAL_TIME_CLOCK); } else { IntDisable(INT_REAL_TIME_CLOCK); } }
void Timer5Interrupt() { if (IntGetFlag(INT_TIMER5)) { if (intCount[5]++ >= intCountLimit[5]) { // reset the counter intCount[5] = 0; // call user's routine intFunction[INT_TIMER5](); } IntClearFlag(INT_TIMER5); } }
void servos_init() { unsigned int a; unsigned int fpb; // Filling up the servovalues table to 255. for(a=0;a<TotalPICpins;a++) { servovalues[a]=255; // Filling up the servovalues table to 255. maxminpos[0][a]= DefaultSERVOMIN; // Setting min servo position to 1000 usec. maxminpos[1][a]= DefaultSERVOMAX; // Setting max servo position to 2000 usec. } // Filling up the activated servos matrix. for(a=0;a<TotalPICports;a++) activatedservos[a]=0x00; // Setting all pins as deactivated as servo. // Timer2 Configuration // The Timer2 clock prescale (TCKPS) is 1:64 // TMR2 count register increments on every Peripheral clock cycle // TMR2 increments every 64 * 1/Fpb // 500 us => 500 / (64 / Fpb) = ( 500 * Fpb ) / 64 cycles // 2500 us => 2500 / (64 / Fpb) = ( 2500 * Fpb ) / 64 cycles fpb = GetPeripheralClock() / 1000 / 1000; f500us = ( 500 * fpb ) / 64; f20ms = ( 20000 * fpb ) / 64; IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); // bit 6-4 TCKPS<2:0>: Timer Input Clock Prescale Select bits // 0 = 1:1 default prescale value // 1 = 1:2 prescale value // 2 = 1:4 prescale value // 3 = 1:8 prescale value // 4 = 1:16 prescale value // 5 = 1:32 prescale value // 6 = 1:64 prescale value // 7 = 1:256 prescale value T2CON = 6 << 4; // prescaler 1:64, internal peripheral clock TMR2 = 0; // clear timer register PR2 = f500us; // load period register IntSetVectorPriority(INT_TIMER2_VECTOR, 7, 3); IntClearFlag(INT_TIMER2); IntEnable(INT_TIMER2); T2CONSET = 0x8000; // start timer 1 }
//#pragma interrupt Tmr2Interrupt ipl3 vector 8 void Tmr2Interrupt() { // is this an TMR2 interrupt ? #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032) TMR2 = _tmr2; // 0xD910; // because PR2 don't work on PIC32MX220F032D if (IFS0bits.T2IF) #else if (IntGetFlag(INT_TIMER2)) // TODO : add PIC32_PINGUINO_220 support #endif { #if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032) IFS0bits.T2IF=0; #else //IFS0CLR=0x00000100; IntClearFlag(INT_TIMER2); #endif _millis++; } }
void Timer3Interrupt() { if (IntGetFlag(INT_TIMER3)) // Timer3 interrupt ? { irdata = digitalread(irparams.recvpin); irparams.timer++; // One more 50us tick // Buffer overflow ? if (irparams.rawlen >= RAWBUF) irparams.rcvstate = STATE_STOP; switch(irparams.rcvstate) { // In the middle of a gap case STATE_IDLE: if (irdata == MARK) { // Not big enough to be a gap. if (irparams.timer < GAP_TICKS) irparams.timer = 0; // gap just ended, record duration and start recording transmission else { irparams.rawlen = 0; irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_MARK; } } break; // timing MARK case STATE_MARK: // MARK ended, record time if (irdata == SPACE) { irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_SPACE; } break; // timing SPACE case STATE_SPACE: // SPACE just ended, record it if (irdata == MARK) { irparams.rawbuf[irparams.rawlen++] = irparams.timer; irparams.timer = 0; irparams.rcvstate = STATE_MARK; } // SPACE else { // big SPACE, indicates gap between codes // Mark current code as ready for processing // Switch to STOP // Don't reset timer; keep counting space width if (irparams.timer > GAP_TICKS) irparams.rcvstate = STATE_STOP; } break; // waiting, measuring gap case STATE_STOP: // reset gap timer if (irdata == MARK) irparams.timer = 0; break; } if (irparams.blinkflag) { if (irdata == MARK) digitalwrite(USERLED, 1); // turn USERLED on else digitalwrite(USERLED, 0); // turn USERLED off } // Timer3 flag reset IntClearFlag(INT_TIMER3); } }