Hi
I received a new LaunchPad TM4C123GH6PM I tried a few examples without issue.
Now I'm trying my hand at by modifying an interrupt code.
I compiles error free, but when I single step, it does not flow linear pattern but skips code and jumps around, NO branch statements.
I placed code to light up all three LEDS RED Green & Blue, but only the RED comes on.
Example these lines should run one after the other but it does not:
line 198 main()
200, 203, 205, 207, 215, 218, 228 221 228 232 235 241 265 247 257 261 265 270 274 289 277 279 283 285 289
The yellow hi light is Linear, the Blue is where it jumps back I don't know why.
Also I set up to have all three LEDs light but only the Red works
Code below
I don't know the cause of this erratic behavior.
Regards Roman
//*****************************************************************************
//
// timers.c - Timers example.
//
//*****************************************************************************
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/adc.h"
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Timer (timers)</h1>
//!
//! This example application demonstrates the use of the timers to generate
//! periodic interrupts. One timer is set up to interrupt once per second and
//! the other to interrupt twice per second; each interrupt handler will toggle
//! its own indicator on the display.
//*****************************************************************************
//*****************************************************************************
//
// Flags that contain the current value of the interrupt indicator as displayed
// on the UART.
//
//*****************************************************************************
uint32_t g_ui32Flags;
uint32_t timer_value1;
uint32_t timer_value2;
uint32_t ADC_cnt;
uint32_t temp;
uint32_t pui32ADC0Value[1];
uint32_t ADC_Value[2048];
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// The interrupt handler for the first timer interrupt.
//
//*****************************************************************************
void FFT(void)
{
IntMasterDisable();
// Use the flags to Toggle the LED for this timer
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, g_ui32Flags << 1);
double M_PI = 3.1415926535;
unsigned long nn = 2048;
unsigned long n, mmax, m, j, istep, i;
double wtemp, wr, wpr, wpi, wi, theta;
double tempr, tempi;
// reverse-binary reindexing
n = nn<<1;
j=1;
for (i=1; i<n; i+=2)
{
if (j>i)
{
// swap(ADC_Value[j-1], ADC_Value[i-1]);
temp = ADC_Value[j-1];
ADC_Value[j-1]= ADC_Value[i-1];
ADC_Value[i-1] = temp;
// swap(ADC_Value[j], ADC_Value[i]);
temp = ADC_Value[j];
ADC_Value[j] = ADC_Value[i];
ADC_Value[i] = temp;
}
m = nn;
while (m>=2 && j>m)
{
j -= m;
m >>= 1;
}
j += m;
};
// here begins the Danielson-Lanczos section
mmax=2;
while (n>mmax)
{
istep = mmax<<1;
theta = -(2*M_PI/mmax);
wtemp = sin(0.5*theta);
wpr = -2.0*wtemp*wtemp;
wpi = sin(theta);
wr = 1.0;
wi = 0.0;
for (m=1; m < mmax; m += 2)
{
for (i=m; i <= n; i += istep)
{
j=i+mmax;
tempr = wr*ADC_Value[j-1] - wi*ADC_Value[j];
tempi = wr * ADC_Value[j] + wi*ADC_Value[j-1];
ADC_Value[j-1] = ADC_Value[i-1] - tempr;
ADC_Value[j] = ADC_Value[i] - tempi;
ADC_Value[i-1] += tempr;
ADC_Value[i] += tempi;
}
wtemp=wr;
wr += wr*wpr - wi*wpi;
wi += wi*wpr + wtemp*wpi;
}
mmax=istep;
}
IntMasterEnable();
}
void Timer0IntHandler(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Toggle the flag for the first timer.
HWREGBITW(&g_ui32Flags, 0) ^= 1;
// Use the flags to Toggle the LED for this timer
// why only the RED LED comes on, what is preventing the Green & Blue
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, g_ui32Flags << 1);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, g_ui32Flags << 1);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, g_ui32Flags << 1);
// Trigger the ADC conversion.
ADCProcessorTrigger(ADC0_BASE, 3);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
// Clear the ADC interrupt flag.
ADCIntClear(ADC0_BASE, 3);
// Read ADC Value.
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
ADC_Value[ADC_cnt] = pui32ADC0Value[0];
ADC_cnt++;
// TimerDisable(TIMER0_BASE, TIMER_A);
if (ADC_cnt > 10)
{
ADC_cnt = 0;
// FFT();
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, g_ui32Flags << 1);
}
// TimerEnable(TIMER0_BASE, TIMER_A);
}
//*****************************************************************************
//
// This example application demonstrates the use of the timers to generate
// periodic interrupts.
//
//*****************************************************************************
int
main(void)
{
timer_value1 = 120000; // RED LED 12000000
for (ADC_cnt = 0; ADC_cnt < 2048; ADC_cnt++)
{
ADC_Value[ADC_cnt] = 0;
}
ADC_cnt = 0;
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
// ROM_
FPULazyStackingEnable();
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
// Enable the GPIO port that is used for the on-board LED.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
// For this example ADC0 is used with AIN0 on port E7.
// The actual port and pins used may be different on your part, consult
// the ADC_Value sheet for more information. GPIO port E needs to be enabled
// so these pins can be used.
// TODO: change this to whichever GPIO port you are using.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_3);
// The ADC0 peripheral must be enabled for use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
// Select the analog ADC function for these pins.
// Consult the ADC_Value sheet to see which functions are allocated per pin.
// TODO: change this to select the port/pin you are using.
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
// Enable sample sequence 3 with a processor signal trigger. Sequence 3
// will do a single sample when the processor sends a signal to start the
// conversion. Each ADC module has 4 programmable sequences, sequence 0
// to sequence 3. This example is arbitrarily using sequence 3.
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
// Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in
// single-ended mode (default) and configure the interrupt flag
// (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic
// that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence
// 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and
// sequence 0 has 8 programmable steps. Since we are only doing a single
// conversion using sequence 3 we will only configure step 0. For more
// information on the ADC sequences and steps, reference the ADC_Valuesheet.
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
// Since sample sequence 3 is now configured, it must be enabled.
ADCSequenceEnable(ADC0_BASE, 3);
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
ADCIntClear(ADC0_BASE, 3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
// Enable processor interrupts.
IntMasterEnable();
// Configure the two 32-bit periodic timers.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, timer_value1);
// Setup the interrupts for the timer timeouts.
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Enable the timers.
TimerEnable(TIMER0_BASE, TIMER_A);
// Loop forever while the timers run.
while(1)
{
}
}