ECE3849/frequency.c
2025-04-24 11:52:52 -04:00

43 lines
1.3 KiB
C

#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
#include "inc/tm4c1294ncpdt.h"
#include "driverlib/interrupt.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "frequency.h"
void start_frequency_scan() {
// config GPIO PD0 as timer input T0CCP0 at BoosterPack Connector #1 pin 14
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PD0_T0CCP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerDisable(TIMER0_BASE, TIMER_BOTH);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);
TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
// use maximum load value
TimerLoadSet(TIMER0_BASE, TIMER_A, 0xffff);
// use maximum prescale value
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 0xff);
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
TimerEnable(TIMER0_BASE, TIMER_A);
}
uint32_t previous;
void capture_handler() {
TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);
uint32_t current = TimerValueGet(TIMER0_BASE, TIMER_A);
uint32_t delta = current - previous;
gPeriod = delta;
previous = current;
}