/*main*/ void main(void) { /*Preliminary parts not important*/ LCD_Char_1_Start(); ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); Configure_DMA(); isr_1_StartEx(Buffer_complete); isr_2_StartEx(LPF_buffer_complete); ADC_DelSig_1_SetCoherency(ADC_DelSig_1_COHER_MID); Filter_SetDalign(Filter_STAGEA_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDA_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDA_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_A,Filter_KEY_MID); Filter_SetDalign(Filter_STAGEB_DALIGN,Filter_ENABLED); Filter_SetDalign(Filter_HOLDB_DALIGN,Filter_ENABLED); Filter_SetCoherency(Filter_STAGEB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_HOLDB_COHER,Filter_KEY_MID); Filter_SetCoherency(Filter_CHANNEL_B,Filter_KEY_MID); CyGlobalIntEnable; Filter_Start(); /*Writes ADC values to ADC_samples array*/ while(1){ if (isr_BC_flag==1){ arm_cfft_q15(&arm_cfft_sR_q15_len256, Buffer_samples, 0, 1); arm_cmplx_mag_q15(Buffer_samples, magoutput, fftlength); CyDmaChEnable(DMA_2_Chan, 1); isr_BC_flag=0; isr_1_ClearPending(); } } }
/** * \brief DSP task core function. * * \param pvParameters Junk parameter. */ static void dsp_task(void *pvParameters) { uint32_t i, j; uint32_t adc_potentiometer = 0; const float32_t display_factor = 700; float32_t bin; float32_t tmp; /* Just to avoid compiler warnings. */ UNUSED(pvParameters); /* Wait for user to read instructions. */ WAIT_FOR_TOUCH_EVENT; dsp_configure_button2(); dsp_configure_tc(); dsp_configure_adc(); dsp_configure_dacc(); dsp_sin_init(); /* Enable PDC transfer. */ dsp_clean_buffer(dacc_out_buffer[0], SAMPLE_BLOCK_SIZE); dsp_clean_buffer(dacc_out_buffer[1], SAMPLE_BLOCK_SIZE); dsp_clean_buffer(dacc_out_buffer[2], SAMPLE_BLOCK_SIZE); g_pdc_packet.ul_addr = (uint32_t) dacc_out_buffer[0]; g_pdc_packet.ul_size = SAMPLE_BLOCK_SIZE; g_pdc_nextpacket.ul_addr = (uint32_t) dacc_out_buffer[1]; g_pdc_nextpacket.ul_size = SAMPLE_BLOCK_SIZE; pdc_tx_init(dacc_pdc, &g_pdc_packet, &g_pdc_nextpacket); pdc_enable_transfer(dacc_pdc, PERIPH_PTCR_TXTEN); /* Start Timer counter 0 channel 0 for ADC-DACC trigger. */ tc_start(TC0, 1); /** DSP task loop. */ while (1) { /* Using input wave signal. */ if (g_mode_select == 1) { if (xSemaphoreTake(dacc_notification_semaphore, max_block_time_ticks)) { /* Copy dsp_sfx into wav_in_buffer and prepare Q15 format. */ for (i = 0, j = 0; i < 512; ++j) { tmp = (((dsp_sfx[offset] - (float) 128)) / 100); /* Store Audio sample real part in memory. */ wav_in_buffer[i++] = tmp; /* Store Audio sample imaginary part in memory. */ wav_in_buffer[i++] = 0; /* Prepare buffer for DACC. */ dacc_out_buffer[cur_dac_buffer][j] = (uint16_t)((tmp * 100 * sin_buffer[slider_pos][j]) + 128); /* Update the wave file offset pointer. */ if (offset < dsp_sfx_size - 1) { offset++; } else { offset = WAVE_OFFSET; } } } else { /* Ensure we take the semaphore. */ continue; } } else { /* Using generated input sinus signal. */ if (xSemaphoreTake(dacc_notification_semaphore, max_block_time_ticks)) { /* * Read potentiometer value and generate * sinus signal accordingly. */ adc_potentiometer_old = adc_potentiometer; adc_potentiometer = (afec_channel_get_value(AFEC0, ADC_CHANNEL_POTENTIOMETER)); adc_potentiometer = adc_potentiometer * 10000 / 4096; if (adc_potentiometer > adc_potentiometer_old && adc_potentiometer - adc_potentiometer_old < ADC_POTENTIOMETER_NOISE) { adc_potentiometer = adc_potentiometer_old; } else if (adc_potentiometer_old > adc_potentiometer && adc_potentiometer_old - adc_potentiometer < ADC_POTENTIOMETER_NOISE) { adc_potentiometer = adc_potentiometer_old; } /* Generate the sinus signal. */ dsp_sin_input(adc_potentiometer); /* Prepare buffer for DACC. */ for (i = 0, j = 0; i < 512; ++j, i += 2) { /* * 2048 is the 0 position for DACC. * 50 is an amplification factor. */ dacc_out_buffer[cur_dac_buffer][j] = (uint16_t)((wav_in_buffer[i] * sin_buffer[slider_pos][j]) * 50 + 2048); } } } afec_start_software_conversion(AFEC0); /* Perform FFT and bin Magnitude calculation */ arm_float_to_q15(wav_in_buffer, cfft_q15, SAMPLE_BLOCK_SIZE * 2); #if (__CM4_CMSIS_VERSION_MAIN >= (0x04)) arm_cfft_q15(&arm_cfft_sR_q15_len256, cfft_q15, 0, 1); #else /** cFFT configuration instance declaration */ arm_cfft_radix4_instance_q15 cfft_instance; arm_cfft_radix4_init_q15(&cfft_instance, SAMPLE_BLOCK_SIZE, 0, 1); arm_cfft_radix4_q15(&cfft_instance, cfft_q15); #endif arm_cmplx_mag_q15(cfft_q15, mag_in_buffer_q15, SAMPLE_BLOCK_SIZE); arm_q15_to_float(mag_in_buffer_q15, mag_in_buffer, 128); /* * Prepare bins rendering for web page and display. * Limit to 99, even if we got 128 magnitudes to display. * Bins are printed using col, incremented by mean of 2 to keep * a clean rendering. Hence we cannot render all the magnitudes, * because of the screen width. It would require a 128*2 space. */ for (i = 0; i < 99; ++i) { bin = (mag_in_buffer[i] * display_factor); if (bin > 0) { if (bin > 98) { bin = 98; } mag_in_buffer_int[i] = (uint32_t)bin; } else { mag_in_buffer_int[i] = 0; } } /* Notify GFX task to start refreshing screen (if necessary). */ if (g_mode_select == 1 || (g_mode_select == 0 && adc_potentiometer != adc_potentiometer_old)) { xSemaphoreGive(gfx_notification_semaphore); } } }