Hello everybody,
I am working on a project in which i would like to read samples from an adc with 40us, lets say 512 samples. After sampling i would like to calculate an fft with the DSPLib.
now I initialize an timer which is handling my adc read.
void init_timer(void) { FPULazyStackingEnable(); SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ ); UARTprintf("Timerinit\n"); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()); IntEnable(INT_TIMER0A); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); IntMasterEnable(); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A);
}
void Timer0IntHandler(void) { adc_val=adc_read(); adc_flag=1; } unsigned long adc_read(void) { SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); ADCProcessorTrigger(ADC0_BASE, 3); while(!ADCIntStatus(ADC0_BASE, 3, false)) { } ADCIntClear(ADC0_BASE, 3); // Read ADC Value. ADCSequenceDataGet(ADC0_BASE, 3, &ulADC0_Value); //}//while return ulADC0_Value; }//adc_read
MAIN is working like that:
if(adc_flag) { Datenarray[cnt_fft]=adc_val; Datenarray[cnt_fft+1]=0; if(cnt_fft==samples*2-2) trig_fft=1; else trig_fft=0; cnt_fft=cnt_fft+2; adc_flag=0; } if(trig_fft) { fft_calc(samples, Datenarray, fft_done); //FFT berechnen trig_fft=0; } if(fft_done) { UARTprintf("Output_data_Datenarray\n"); for(k = 0 ; k < samples*2 ; k=k+2) { if (Datenarray[k]>=100) UARTprintf("%d:F_Re = %4d\t\t%d:F_Im= %4d\n",k/2, Datenarray[k],k/2, Datenarray[k+1]); else UARTprintf("%d:F_Re = %4d\t\t%d:F_Im= %4d\n",k/2, 0,k/2, Datenarray[k+1]); } fft_done=0; }
while debugging everything is fine, but in release it is doing weird things.
Is there a better way to read the values, then calculate while reading and calulate again after the array is full again? how do i config the timer that my adc reads every 40 us?
greetings