Hi I'm George, I want to make a query.
I am making a frequency counter, the way I do it is:
I configure Timer0 in Free Running mode.
I configure Timer1 as event counter , rising edge, whenever it detects an edge, an interrupt is generated that keeps the count of Timer0 to make the period calculation .
My firmware, it calculates the frequency, but only makes up to 600kHz, when the count more than 800kHz, stops working.
The clock of my system is set to 80MHz.
The variable that contains the frequency, I check from the debugger.
This is the code:
#include <stdio.h> #include <stdint.h> #include <stdbool.h> #include "stdlib.h" #include <math.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/systick.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "utils/uartstdio.h" //Con este firmware lo maximo que pude medir aceptable fueron 600KHz // function prototypes void init_timer0(void); void init_timer1(void); void Timer0_int(void); void contador(void); unsigned long cuenta_vieja; unsigned long cuenta_nueva=0; unsigned long cuenta; float periodo,frecuencia; int main() { // Configure system clock at 80 MHz. SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL| SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlDelay(3); IntMasterEnable(); init_timer0(); init_timer1(); TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); while(1) { periodo=(((float)cuenta)/80000000); frecuencia=1/periodo; } } void init_timer0(void) // Free Running Timer { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //habilito el TIMER0 SysCtlDelay(3); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //configuro como periodico TimerLoadSet(TIMER0_BASE, TIMER_A, 0xfffffffe); //cargo el valor de conteo 2^16-1 TimerEnable(TIMER0_BASE, TIMER_A); //habilito el timer A } void init_timer1(void) // Contador de flancos { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_CAP_TIME_UP)); // esto me permite contar 2^32 pulsos TimerControlEvent(TIMER1_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); //configuro por flanco de subida TimerLoadSet(TIMER1_BASE, TIMER_A,0xfffffffe ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB4_T1CCP0); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4); IntRegister(INT_TIMER1A, contador); TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT); TimerIntEnable(TIMER1_BASE, TIMER_CAPA_EVENT); IntEnable(INT_TIMER1A); } void contador(void) // entra aca cada vez que recibe un flanco { TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT); cuenta_vieja=cuenta_nueva; cuenta_nueva=TimerValueGet(TIMER0_BASE, TIMER_A); cuenta=abs(cuenta_nueva-cuenta_vieja); }
Someone can help me find the problem?
thank you very much.