/*
 * File:   Crono.c
 * Author: Christian Mares
 *
 * Created on 14 de diciembre de 2017, 17:19
 */

#ifndef TMR4_H
#define TMR4_H

#define FlowCtrl_Timer 4 // Define el Timer a usar

#if(FlowCtrl_Timer == 1)
 #define _TFCCON T1CON
 #define _TFCTMR TMR1
 #define _TFCPR  PR1
 #define _TFCTCKPS T1CONbits.TCKPS
 #define _TFCTON T1CONbits.TON
 #define _T_FC_Interrupt _T1Interrupt
 #define _TFCIP _T1IP
 #define _TFCIF _T1IF
 #define _TFCIE _T1IE
#elif(FlowCtrl_Timer == 2)
 #define _TFCCON T2CON
 #define _TFCTMR TMR2
 #define _TFCPR  PR2
 #define _TFCTCKPS T2CONbits.TCKPS
 #define _TFCTON T2CONbits.TON
 #define _T_FC_Interrupt _T2Interrupt
 #define _TFCIP _T2IP
 #define _TFCIF _T2IF
 #define _TFCIE _T2IE
#elif(FlowCtrl_Timer == 3)
 #define _TFCCON T3CON
 #define _TFCTMR TMR3
 #define _TFCPR  PR3
 #define _TFCTCKPS T3CONbits.TCKPS
 #define _TFCTON T3CONbits.TON
 #define _T_FC_Interrupt _T3Interrupt
 #define _TFCIP _T3IP
 #define _TFCIF _T3IF
 #define _TFCIE _T3IE
#elif(FlowCtrl_Timer == 4)
 #define _TFCCON T4CON
 #define _TFCTMR TMR4
 #define _TFCPR  PR4
 #define _TFCTCKPS T4CONbits.TCKPS
 #define _TFCTON T4CONbits.TON
 #define _T_FC_Interrupt _T4Interrupt
 #define _TFCIP _T4IP
 #define _TFCIF _T4IF
 #define _TFCIE _T4IE
#elif(FlowCtrl_Timer==5)
 #define _TFCCON T5CON
 #define _TFCTMR TMR5
 #define _TFCPR  PR5
 #define _TFCTCKPS T5CONbits.TCKPS
 #define _TFCTON T5CONbits.TON
 #define _T_FC_Interrupt _T5Interrupt
 #define _TFCIP _T5IP
 #define _TFCIF _T5IF
 #define _TFCIE _T5IE
#elif(FlowCtrl_Timer == 0 || FlowCtrl_Timer >= 5)
#error ("TIMER PARA CRONO NO DEFINIDO")
#endif

#define PR_25000 24999 //Periodo   =  [24999 + 1] * 6.25*10e-8 * 64(prescaler) = 100ms -> 10Hz 
#define PR_2500  2499  //Periodo   =   [2499 + 1] * 6.25*10e-8 * 64(prescaler) = 10ms -> 100Hz 
#define PR_1250  1249  //Periodo   =   [1249 + 1] * 6.25*10e-8 * 64(prescaler) = 5ms -> 200Hz 
#define T4_Period PR_1250

#define T4_TimeSeconds_Const 0.000004 // = 6.25*10e-8 * 64

extern double PRSeconds;
extern double a;
extern volatile bool go;

void Inic_Timer4(void);

#endif