Part Number: TM4C1294NCPDT
Hello.
I am writing a code to measure the period of an oscillator circuit 555.
I configured two timers, Timer0A for interrupts every 1 second, and Timer1A for capture mode.
Timer0A interruption is working perfectly, but Timer1A is not being directed to interrupt.
Follows the configuration code ...
I already researched the forum on the subject but I could not solve the problem.
NOTE: The code is not finished, but it is not being directed to the interrupt.
Thank you.
#define VET_TRANSMIT 20
#define VET_PERIOD_FREQ 50
#define FREQ_MICRO 16000000.0
void Config_Clock(void);
void Config_Timer(void);
uint32_t g_ui32SysClock;
uint32_t tempo = 0, allCaptured = 0;
volatile uint32_t count, edge1, edge2, period[VET_PERIOD_FREQ], t = 0, l = 0,
flag = 0, tx_index = 0, temp = 0, segundo = 0;
volatile float freq[VET_PERIOD_FREQ], cap = 0, media_freq = 0, soma_freq = 0;
char buffer[VET_TRANSMIT], i = 0;
void main(void)
{
Config_Clock();
Config_Timer();
while (1)
{
flag = 0; // Initialise count for new capture
if (allCaptured == 1)
{
allCaptured = 0;
if (edge2 > edge1)
{ // Ignore calculation if overflow occured
period[t] = edge2 - edge1; // Calculate Period
t++;
edge1 = edge2;
}
}
}
}
void Config_Clock(void)
{
g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480),
120000000);
}
void Config_Timer(void)
{
//--------------Config TimerA0 Interupcao cada 1s---------------//
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //habilita clock para o timer
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // configura o timer para interpcoes periodicas
TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock); //gera uma interupcao a cada 1s
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerEnable(TIMER0_BASE, TIMER_A);
IntEnable(INT_TIMER0A);
//----------------------Timer2A Mode Capture--------------//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); // Enable the GPIO port that is used for the input edge counting
GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_0); // Configure PM0 as the positive edge capture on Timer 2A
GPIOPinConfigure(GPIO_PM0_T2CCP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // For use with edge-time mode
TimerConfigure(TIMER2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME));
TimerControlEvent(TIMER2_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);
TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT);
TimerEnable(TIMER2_BASE, TIMER_A); // Enable the timers
IntEnable(INT_TIMER2A); // Enable interrupt for Timer s
IntMasterEnable();
}
void Interrupt_Timer0A(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
tempo++;
}
void Interrupt_Timer2A(void)
{
uint32_t InterruptFlags = TimerIntStatus(TIMER2_BASE, true);
if (InterruptFlags & TIMER_CAPA_EVENT)
{
if (!flag)
{
// Capture first edge timer value and indicate that the program has captured first on
edge1 = MAP_TimerValueGet(TIMER2_BASE, TIMER_A);
flag = 1;
}
// Once falling edge has been captured, store the value of the second rising edge which completes the sample
else if (flag)
{
edge2 = MAP_TimerValueGet(TIMER2_BASE, TIMER_A);
// Indicates that all three edges required for calculations have been capture and is ready to calculate
allCaptured = 1;
}
}
// Clear interrupt flag to enable to interrupt to occur once more.
TimerIntClear(TIMER2_BASE, TIMER_CAPA_EVENT);
}