Compare commits

..

No commits in common. "bd79be6eac585bcf2cd36ccd28059099b4524bec" and "22a3b5e7951eff874cef32236e291ad01cdb7d2b" have entirely different histories.

20
main.c
View file

@ -59,14 +59,12 @@ static kiss_fft_cpx in[FFT_BUF_LEN], out[FFT_BUF_LEN];
typedef struct typedef struct
{ {
bool fft;
uint8_t voltage_scale; uint8_t voltage_scale;
uint8_t time_scale; uint8_t time_scale;
uint8_t trigger_mode; uint8_t trigger_mode;
} Options; } Options;
Options options = { Options options = {
.fft = false, // oscilloscope mode
.voltage_scale = 4, // 2v .voltage_scale = 4, // 2v
.time_scale = 5, // 20us .time_scale = 5, // 20us
.trigger_mode = 1, // rising .trigger_mode = 1, // rising
@ -187,11 +185,12 @@ void capture_waveform(UArg arg1, UArg arg2)
int32_t adc_current_index; int32_t adc_current_index;
int32_t i; int32_t i;
if (options.fft) { if (true) {
adc_current_index = gADCBufferIndex; adc_current_index = gADCBufferIndex;
int32_t j = 0;
for(i=adc_current_index-FFT_BUF_LEN; i<adc_current_index; i++) { for(i=adc_current_index-FFT_BUF_LEN; i<adc_current_index; i++) {
adc_buffer_fft_sample[j++] = gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + i)]; //in[i].r = sinf(20*PI*i/FFT_BUF_LEN);
in[i].r = (float) gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + i)];
in[i].i = 0;
} }
} else { } else {
// single read of options is atomic // single read of options is atomic
@ -230,11 +229,9 @@ void process_waveform(UArg arg1, UArg arg2) {
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
#define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0) #define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0)
if(options.fft) { // fft if(true) { // fft
for(i=0; i<FFT_BUF_LEN; i++) { for(i=0; i<FFT_BUF_LEN; i++) {
//in[i].r = sinf(20*PI*i/FFT_BUF_LEN); in[i].r *= w[i];
in[i].r = (float) adc_buffer_fft_sample[i] * w[i];
in[i].i = 0;
} }
kiss_fft(cfg, in, out); kiss_fft(cfg, in, out);
@ -243,7 +240,7 @@ void process_waveform(UArg arg1, UArg arg2) {
#define DB(out) 10 * log10f(out.r * out.r + out.i * out.i) #define DB(out) 10 * log10f(out.r * out.r + out.i * out.i)
//adc_buffer_processed[i] = CONSTRAIN(HEIGHT- (int)roundf(0.5 * DB(out[i]))); //adc_buffer_processed[i] = CONSTRAIN(HEIGHT- (int)roundf(0.5 * DB(out[i])));
adc_buffer_processed[i] = CONSTRAIN(HEIGHT- (int) (DB(out[i])) ); adc_buffer_processed[i] = CONSTRAIN(HEIGHT- (int) (DB(out[i])) + 64);
} }
@ -274,9 +271,6 @@ void handle_user_input() {
case S1: // toggle edge case S1: // toggle edge
local_options.trigger_mode = (local_options.trigger_mode + 1) % 3; local_options.trigger_mode = (local_options.trigger_mode + 1) % 3;
break; break;
case S2: // toggle fft
local_options.fft ^= 1;
break;
case Up: // next scale case Up: // next scale
local_options.voltage_scale = (local_options.voltage_scale + 1) % VOLTAGE_SCALES; local_options.voltage_scale = (local_options.voltage_scale + 1) % VOLTAGE_SCALES;
break; break;