/********************************************/
/*Timers Configuration Code                 */
/*PIC32MX795F512L-80I/PF                    */
/*                                          */
/*Timer 1 = RTC                             */
/*Timer 2 = backlight PWM                   */
/*Timer 3 = unused                          */
/*Timer 4 = unused                          */
/*Timer 5 = programmable delay              */
/********************************************/

#include "xc.h" 

void Timer2_Init(void)
{   
    //Stop Timer2
    T2CONbits.ON = 0;
    
    //Set Source = PBCLK
    T2CONbits.TCS = 0;
     
    //combine Timer2
    T2CONbits.T32 = 0;
    
    //Prescaler
    T2CONbits.TCKPS = 2;
    
    T2CONbits.TGATE = 0;
    
    T2CONbits.ON = 1;
    
    return;
}

void Timer3_Init(void)
{       
    //Set Default
    T3CON = 0;
    OC3CON = 0;
    
    //Prescaler 0-7
    T3CONbits.TCKPS = 6;
    
    //Start Timer3
    T3CONbits.ON = 1;
    
    return;
}

void Timer4_Init(void)
{   
    //Set defaults
    T4CON = 0;
    OC4CON = 0;
    
    //Enable Timer 4 Interrupt
    IEC0bits.T4IE = 1;
        
    //Prescaler 0-7
    T4CONbits.TCKPS = 6;
    
    //Set to Interrupt at 250Hz
    PR4 = 8250; 
    
    T4CONbits.ON = 1;
    
    return;
}

//Programmable Delay
void Timer5_Init(void)
{   
    //Stop Timer5
    T5CONbits.ON = 0;
    
    //Set Source = PBCLK
    T5CONbits.TCS = 0;
         
    //Prescaler 0-7
    T5CONbits.TCKPS = 0;
    
    T5CONbits.TGATE = 0;
    
    return;
}
