diff --git a/main.c b/main.c index 65796d3..79ecb6b 100644 --- a/main.c +++ b/main.c @@ -31,18 +31,32 @@ #include "driverlib/pin_map.h" #include "sampling.h" #include "buttons.h" +#include "kiss_fft.h" +#include "_kiss_fft_guts.h" + #define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz uint32_t gSystemClock = 120000000; // [Hz] system clock frequency +#define PI 3.14159265358979f + tContext sContext; uint32_t cputime_unloaded; +#define FFT_EN false + #define LOCAL_BUF_LEN 128 uint16_t adc_buffer_sample[LOCAL_BUF_LEN]; // copy of g adc buffer uint8_t adc_buffer_processed[LOCAL_BUF_LEN]; // copy of g adc buffer +#define FFT_BUF_LEN 1024 +uint16_t adc_buffer_fft_sample[FFT_BUF_LEN]; // copy of g adc buffer +uint8_t adc_buffer_fft_processed[FFT_BUF_LEN]; // copy of g adc buffer + +kiss_fft_cfg cfg; +static kiss_fft_cpx in[FFT_BUF_LEN], out[FFT_BUF_LEN]; + typedef struct { uint8_t voltage_scale; @@ -151,64 +165,94 @@ int main(void) GrContextInit(&sContext, &g_sCrystalfontz128x128); // Initialize the grlib graphics context GrContextFontSet(&sContext, &g_sFontFixed6x8); // select font + #define KISS_FFT_CFG_SIZE (sizeof(struct kiss_fft_state)+sizeof(kiss_fft_cpx)*(FFT_BUF_LEN-1)) + static char kiss_fft_cfg_buffer[KISS_FFT_CFG_SIZE]; + size_t buffer_size = KISS_FFT_CFG_SIZE; + cfg = kiss_fft_alloc(FFT_BUF_LEN, 0, kiss_fft_cfg_buffer, &buffer_size); + /* Start BIOS */ BIOS_start(); return (0); } -void task0_func(UArg arg1, UArg arg2) -{ - IntMasterEnable(); - - while (true) { - // do nothing - } -} - void capture_waveform(UArg arg1, UArg arg2) { IntMasterEnable(); while(true) { Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER); - // single read of options is atomic - int32_t trigger_mode = options.trigger_mode; - int32_t adc_current_index; - int32_t j; - int trigger; - if (trigger_mode == 2) { - trigger = gADCBufferIndex - (WIDTH / 2); // show latest if trigger disabled + int32_t i; + + if (true) { + adc_current_index = gADCBufferIndex; + for(i=adc_current_index-FFT_BUF_LEN; i(b))?(a):(b)) + #define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0) - float fVoltsPerDiv = gVoltageScale[options.voltage_scale]; - float fScale = (VIN_RANGE * PIXELS_PER_DIV)/((1 << ADC_BITS) * fVoltsPerDiv); + if(true) { // fft + for(i=0; i(b))?(a):(b)) - #define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0) - #define TRANSPOSE(x) CONSTRAIN((HEIGHT/2) - (int)roundf(fScale * ((int)x - ADC_OFFSET))) - adc_buffer_processed[j] = TRANSPOSE(adc_buffer_sample[j]); + kiss_fft(cfg, in, out); + + for(i=0; i(b))?(a):(b)) - uint32_t upper,lower, current, last; - - if (j==0) { - upper = adc_buffer_processed[j]; - lower = upper; - last = upper; - } else { - current = adc_buffer_processed[j]; - - upper = MAX(current, last); - lower = MIN(current, last); - - last = current; - } - - GrLineDrawV(&sContext, j, lower, upper); + for(j=1; j