Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
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;
    }
}
Exemplo n.º 3
0
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);
	}
}
Exemplo n.º 4
0
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
}