Hello there I am having trouble in the code I have written for my stellaris Launchpad. The main problem I am having currently is that I cannot get the if function in my while loop to run the function in it.
The Function is a FFT Function running from CMSIS DSP lib . I Get the FFT working if I put the FFT code in the while loop. but I want it to be accessed only once when the ADC is finished sampling. Could you help me what might be the code error that does not let the if statement be to be run even if the statement is true.
Thanks
Maulik
#include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_adc.h" #include "driverlib/timer.h" #include "driverlib/debug.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" #include "arm_math.h"
float FFTInput[256] ; float FFTOutput[128];
unsigned long ulADC0Value[4]; volatile unsigned long ulTempAvg; int fftSize = 128 ; int ifftflag = 0 ; int doBitReverse = 1 ; uint32_t testindex = 0, refIndex = 213 ; int i = 0 ; int ulPeriod ;
int FFTFinish = 0 ; int samplingfinish = 0 ;
void ARM_FFT(void);
#ifdef DEBUG void __error__(char *pcFilename, unsigned long ulLine) { } #endif
void GPIOPinSetup(void) { //Basic GPIO PINF Setup SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}
void Timer0SetUp(void) { // Basic Timer A setup SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerControlTrigger(TIMER0_BASE, TIMER_A,true); ulPeriod = (SysCtlClockGet()/3000) ; TimerLoadSet(TIMER0_BASE, TIMER_A, (ulPeriod -1)); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A); }
void ADC0Setup(void) { //Basic ADC0 Setup SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); ADCSequenceDisable(ADC0_BASE, 1);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 1); }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
Timer0SetUp(); ADC0Setup(); GPIOPinSetup();
IntEnable(INT_ADC1);
//status = ARM_MATH_SUCCESS ;
//status = arm_cfft_radix4_init_f32(&S, fftSize, ifftflag, doBitReverse); while(1) {
if(samplingfinish) { /*arm_cfft_radix4_f32(&S, FFTInput);
arm_cmplx_mag_f32(FFTInput , FFTOutput, fftSize);
arm_max_f32(FFTOutput, fftSize, &maxvalue ,&testindex); if(status == ARM_MATH_SUCCESS) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14); SysCtlDelay(80000000); } FFTFinish = 1 ; samplingfinish = 0 ;*/ ARM_FFT(); }
else; }
}
void Timer0IntHandler(void) {
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14); }
}
void ADC1IntHandler(void) { //clear the adc interrupt ADCIntClear(ADC0_BASE, 1) ; // disable the timer so that we do not get a fault ISR routine TimerDisable(TIMER0_BASE, TIMER_A) ;
ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; IntPendClear(INT_ADC0SS1); if(i != 256 && FFTFinish == 0) { FFTInput[i] =(float) ulTempAvg ; i++ ; TimerLoadSet(TIMER0_BASE, TIMER_A, (ulPeriod -1)); TimerEnable(TIMER0_BASE, TIMER_A); } else { IntPendClear(INT_ADC0SS1); IntPendClear(INT_TIMER0A); TimerDisable(TIMER0_BASE, TIMER_A) ; ADCIntDisable(ADC0_BASE, 1); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); samplingfinish = 1 ; return ; }
}
void ARM_FFT(void) { arm_status status ; arm_cfft_radix4_instance_f32 S ; float maxvalue ;
status = arm_cfft_radix4_init_f32(&S, fftSize, ifftflag, doBitReverse);
arm_cfft_radix4_f32(&S, FFTInput);
arm_cmplx_mag_f32(FFTInput , FFTOutput, fftSize);
arm_max_f32(FFTOutput, fftSize, &maxvalue ,&testindex); if(status == ARM_MATH_SUCCESS) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14); SysCtlDelay(80000000); } FFTFinish = 1 ; }