From 1ebee8e2a341ae323565015c3d64aace7bc87f9d Mon Sep 17 00:00:00 2001 From: Alex Wulff Date: Fri, 29 Jan 2021 15:34:23 -0500 Subject: [PATCH] Removed one file --- adc_fft/backup2.c | 123 ---------------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 adc_fft/backup2.c diff --git a/adc_fft/backup2.c b/adc_fft/backup2.c deleted file mode 100644 index fa4f15d..0000000 --- a/adc_fft/backup2.c +++ /dev/null @@ -1,123 +0,0 @@ -// Sample from the ADC continuously at a particular sample rate -// -// much of this code is from pico-examples/adc/dma_capture/dma_capture.c -// the rest is written by Alex Wulff (www.AlexWulff.com) - -#include -#include -#include "pico/stdlib.h" -#include "hardware/adc.h" -#include "hardware/dma.h" - -// set this to determine sample rate -// 0 = 500,000 Hz -// 960 = 50,000 Hz -// 9600 = 5,000 Hz -#define CLOCK_DIV 960 -#define FSAMP 50000 - -// Channel 0 is GPIO26 -#define CAPTURE_CHANNEL 0 -#define LED_PIN 25 -#define NSAMP 5000 - -// constants -#define PI2 6.2831852 - -// globals -dma_channel_config cfg; -uint dma_chan; -float freqs[NSAMP]; - -void setup(); -void sample(uint8_t *capture_buf); -void do_dft(float *in, float *out_re, float *out_im); - -int main() { - setup(); - - uint8_t cap_buf[NSAMP]; - float ft_in[NSAMP]; - float ft_out_re[NSAMP]; - float ft_out_im[NSAMP]; - - while (1) { - // get NSAMP samples at FSAMP - sample(cap_buf); - // fill fourier transform input - for (int i=0;ififo, // src - NSAMP, // transfer count - true // start immediately - ); - - gpio_put(LED_PIN, 1); - adc_run(true); - - uint64_t start_time = time_us_64(); - dma_channel_wait_for_finish_blocking(dma_chan); - uint64_t end_time = time_us_64(); - gpio_put(LED_PIN, 0); -} - -void setup() { - stdio_init_all(); - - gpio_init(LED_PIN); - gpio_set_dir(LED_PIN, GPIO_OUT); - adc_gpio_init(26 + CAPTURE_CHANNEL); - - adc_init(); - adc_select_input(CAPTURE_CHANNEL); - adc_fifo_setup( - true, // Write each completed conversion to the sample FIFO - true, // Enable DMA data request (DREQ) - 1, // DREQ (and IRQ) asserted when at least 1 sample present - false, // We won't see the ERR bit because of 8 bit reads; disable. - true // Shift each sample to 8 bits when pushing to FIFO - ); - - // set sample rate - adc_set_clkdiv(CLOCK_DIV); - - sleep_ms(1000); - // Set up the DMA to start transferring data as soon as it appears in FIFO - dma_chan = dma_claim_unused_channel(true); - cfg = dma_channel_get_default_config(dma_chan); - - // Reading from constant address, writing to incrementing byte addresses - channel_config_set_transfer_data_size(&cfg, DMA_SIZE_8); - channel_config_set_read_increment(&cfg, false); - channel_config_set_write_increment(&cfg, true); - - // Pace transfers based on availability of ADC samples - channel_config_set_dreq(&cfg, DREQ_ADC); - - // calculate frequencies of each bin - float f_max = FSAMP/2; - float f_res = f_max / NSAMP; - for (int i = 0; i < NSAMP; i++) {freqs[i] = f_res*i;} -}