Good afternoon Ladies and Gents,
I am trying to perform an ADC on an audio signal to around 20kHz and I'm taking 512 samples at a time. I then want to perform an FFT using the CMSIS library with this signal/sample to give me 64 frequency bins. The value from each of these bins will then dictate the colour of the led (there are 128 leds, 2 per frequency bin) in a later part of the project (just so you know), its sort of a spectrum analyser.
Currently I believe my ADC is working in some form but it's doing dome strange things, meaning I've set something up thats not right or forgotten to. I'm using a pot form 0v to 3.3v, not an audio signal (the audio signal will be 3V pk-pk biased around 1.5V), currently, so I can monitor the change I'm putting into the system.
I'm tracking the data being put into the arrays; audio_samples[ ] and adc_sample[ ], using the graph function so I can see all my samples
- Why are my values are all over the place?
- How come adc_sample isn't exactly the same as audio_samples? Am i not just replicating the array outside of the interrupt?
- What would be the best sampling frequency to run at?
Here's my code;
/* * main.c */ #include <stdint.h> #include <stdbool.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "driverlib/debug.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" //for the adc peripherals #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/interrupt.h" //#include "arm_math.h" #define NUM_SAMPLES 512 //number of samples taken by the ADC //declare ADC intrupt extern void ADCIntHandler(void); uint32_t g_ui32SysClock; uint32_t audio_samples[NUM_SAMPLES]; int main(void) { volatile uint32_t ui32Loop; //set syst clk frequency g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); /*// set up onboard LED on PN0 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)){} GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); */ //set up pin PE0 for ADC input SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)){} GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); //set up the ADC SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //enable the adc ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 1 ); ADCSequenceDisable(ADC0_BASE, 3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH3|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); //variable for adc value //uint32_t Value; //setup timer SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC); TimerLoadSet(TIMER0_BASE,TIMER_A, g_ui32SysClock); //calculate this to be the right freq for audio sampling and fft TimerControlTrigger(TIMER0_BASE,TIMER_A,true); TimerEnable(TIMER0_BASE,TIMER_A); //set interupts IntRegister(INT_ADC0SS3,ADCIntHandler); ADCIntEnable(ADC0_BASE,3); IntEnable(INT_ADC0SS3); IntMasterEnable(); while(1) { } } void ADCIntHandler(void) { uint32_t adc_sample[NUM_SAMPLES]; //dont really need this; just use the global variable uint32_t adc_sample_count; for(adc_sample_count=0; adc_sample_count<NUM_SAMPLES; adc_sample_count++){ //writes the sample value to array ADCSequenceDataGet(ADC0_BASE, 3, &adc_sample[adc_sample_count]); audio_samples[adc_sample_count] = adc_sample[adc_sample_count]; } ADCIntClear(ADC0_BASE,3); }
Sorry if these are basic questions, I'm new to microcontrollers and the launchpad, any help you could give me would be appreciated (dumbing it down might me help too)
Will:) x