Hello Xiangjun.
thanks for your answer.
that is what i am doing but every time i get an input when i am doing a high frequency meassure lets say 5000Hz the capt1 is correct 4000 for 20MHz clock but tick2 should be 0 instead it is one.
void Inic_Timer(void)
{
SIM_SCGC5 |= SIM_SCGC5_TMR0_MASK + SIM_SCGC5_TMR1_MASK +SIM_SCGC5_TMR2_MASK +SIM_SCGC5_TMR3_MASK + SIM_SCGC5_PORTF_MASK;
PORTF_PCR0 = PORT_PCR_MUX(0x03);
TMR2_CTRL = TMR_CTRL_CM(0) // Cascaded counter mode (up/down)4
+ TMR_CTRL_PCS(8) // IP bus clock divide by 1 prescaler
+ TMR_CTRL_SCS(2) // Counter 0 input pin
+ TMR_CTRL_OUTMODE(0); // Asserted while counter is active
// LENGHT = 0 DIR=0 ONCE=0 COINIT=0
TMR3_CTRL = TMR_CTRL_CM(7) // Cascaded counter mode (up/down)4
+ TMR_CTRL_PCS(6) // ICounter 2 output
+ TMR_CTRL_SCS(2) // Counter 0 input pin
+ TMR_CTRL_OUTMODE(0); // Asserted while counter is active
// LENGHT = 0 DIR=0 ONCE=0 COINIT=0
TMR2_SCTRL = TMR_SCTRL_CAPTURE_MODE(1) + TMR_SCTRL_IEFIE_MASK; //Load capture register on rising edge (when IPS=0) or falling edge (when IPS=1) of input
TMR3_SCTRL = TMR_SCTRL_CAPTURE_MODE(1); //Load capture register on rising edge (when IPS=0) or falling edge (when IPS=1) of input
TMR3_CNTR = 0X0000;
TMR2_CNTR = 0X0000;
TMR3_CSCTRL = TMR_CSCTRL_DBG_EN(0)+ TMR_CSCTRL_ROC_MASK; //Continue with normal operation during debug mode. (default)
TMR2_CSCTRL = TMR_CSCTRL_DBG_EN(0)+ TMR_CSCTRL_ROC_MASK; //Continue with normal operation during debug mode. (default)
valor1 = TMR2_CAPT;
int_timer = 0;
TMR2_SCTRL &= ~TMR_SCTRL_IEF_MASK;
TMR3_SCTRL &= ~TMR_SCTRL_IEF_MASK;
NVIC_EnableIRQ(TMR2_IRQn);
NVIC_SetPriority(TMR2_IRQn,0);
TMR2_CTRL |= TMR_CTRL_CM(1); /* Run counter */
}
void TMR2_IRQ_ISR(void)
{
valor1 = TMR2_CAPT;
valor_tot = TMR3_CAPT;
TMR2_SCTRL &= ~TMR_SCTRL_IEF_MASK;
TMR3_SCTRL &= ~TMR_SCTRL_IEF_MASK;
valor_tot <<= 16;
valor_tot +=valor1;
if (int_timer == 0)
{
int_timer = 1;
valor_display = valor_tot;
acumula = 0;
soma = 0;
}
valor1 = 0;
valor_tot = 0;
}