Ejemplo n.º 1
0
/*********************************************************************
* Function:         void InitSymbolTimer()
*
* PreCondition:     none
*
* Input:		    none
*
* Output:		    none
*
* Side Effects:	    TMR0 for PIC18 is configured for calculating
*                   the correct symbol times.  TMR2/3 for PIC24/dsPIC
*                   is configured for calculating the correct symbol
*                   times
*
* Overview:		    This function will configure the UART for use at 
*                   in 8 bits, 1 stop, no flowcontrol mode
*
* Note:			    The timer interrupt is enabled causing the timer
*                   roll over calculations.  Interrupts are required
*                   to be enabled in order to extend the timer to
*                   4 bytes in PIC18.  PIC24/dsPIC version do not 
*                   enable or require interrupts
********************************************************************/
void InitSymbolTimer()
{
#if defined(__18CXX)
    TMR_CON = 0b00000000 | CLOCK_DIVIDER_SETTING;
    TMR_IP = 1;
    TMR_IF = 0;
    TMR_IE = 1;
    TMR_ON = 1;

    timerExtension1 = 0;
    timerExtension2 = 0;
#elif defined(__dsPIC30F__) || defined(__dsPIC33F__) || defined(__PIC24F__) || defined(__PIC24FK__) || defined(__PIC24H__)
    T2CON = 0b0000000000001000 | CLOCK_DIVIDER_SETTING;
    T2CONbits.TON = 1;
#elif defined(__PIC32MX__)
    #if defined (SECOND_PROTOTYPE) //Timer 3 freed for ADC rjk
        CloseTimer4();
        WriteTimer4(0x00);
        WriteTimer5(0x00);
        WritePeriod5(0xFFFF);
        OpenTimer4((T4_ON|T4_32BIT_MODE_ON|CLOCK_DIVIDER_SETTING),0xFFFFFFFF);
    #else
        CloseTimer2();
        WriteTimer2(0x00);
        WriteTimer3(0x00);
        WritePeriod3(0xFFFF);
        OpenTimer2((T2_ON|T2_32BIT_MODE_ON|CLOCK_DIVIDER_SETTING),0xFFFFFFFF);
    #endif
#else
    #error "Symbol timer implementation required for stack usage."
#endif
}
Ejemplo n.º 2
0
char Stepper_ChangeStepRate(unsigned short int rate)
{
    unsigned short int overflowPeriod;
    if ((rate > TWENTY_KILOHERTZ)||(stepperState == off)) return ERROR;
    dbprintf("\nChanging step rate");
    T5CONbits.ON = 0; // halt timer5
    overflowPeriod = CalculateOverflowPeriod(rate);
    WritePeriod5(overflowPeriod);
    if (stepperState != halted) {
        T3CONbits.ON = 1; // restart timer3
    }
    return SUCCESS;
}