【Wireless digital intercom based on GDF350】 1. ADC+DMA voice signal acquisition[Copy link]
This post was last edited by ketose on 2018-9-27 23:15 After a period of hard work, my GD32F350-based digital intercom has been successful. First of all, let's talk about the main control: the new GD32F350 series products have a maximum main frequency of 108MHz and support DSP instruction operations. Equipped with 16KB to 128KB of built-in Flash and 4KB to 16KB of SRAM, the kernel accesses the flash memory at high speed and zero wait, and the working performance at the highest main frequency can reach 135DMIPS. The code execution efficiency at the same main frequency is 30% higher than that of similar Cortex-M3 products on the market, and more than 50% higher than that of Cortex-M0+ products. From today on, I will share some of my experiences and insights in the production process. The basic principle is to sample through ADC 8K, then display the sound and audio frequency on the OLED, and then transmit it to the other end through 2.4G wireless transmission to notify the DAC to play the voice signal. That's the principle, there's nothing much to say. The first step to voice transmission is to collect voice signals. Since the GD32F50 development board itself does not have an integrated digital MIC, an external MIC module is required. Here I choose the GY-MAX9814 voice module. MAX9814 is a low-cost, high-performance microphone amplifier with automatic gain control (AGC) and low-noise microphone bias. The device has a low-noise front-end amplifier, a variable gain amplifier (VGA), an output amplifier, a microphone bias voltage generator, and an AGC control circuit. The low-noise preamplifier has a fixed gain of 12dB; the VGA gain is automatically adjusted between 20dB and 0dB according to the output voltage and the AGC threshold. The output amplifier provides selectable gains of 8dB, 18dB, and 28dB. In the uncompressed case, the cascade gain of the amplifier is 40dB, 50dB, or 60dB. The output amplifier gain is programmed by a three-state digital input. The AGC threshold is controlled by an external resistor divider, and the action/release time is programmed by a single capacitor. The action/release time ratio is set by a three-state digital input. The AGC hold time is fixed at 30ms. The low noise microphone bias voltage generator can provide bias for most electret microphones. Module physical picture:
To achieve 8K sampling, you need to use the external trigger of the ADC. Here, channel 1 of TIMER1 is used to trigger the ADC. The configuration code is as follows:
DMA is used here. We originally planned to use double buffering, but during debugging, we found that the voice would be affected when switching buffers, causing the voice to freeze. So we did not use double buffering, and just sent the collected data. The receiving end also became simpler. DAC conversion was performed after receiving the data, and the timer was no longer needed. It can also ensure voice synchronization without delay. The DMA configuration code is as follows:
Then notify the front desk in the DMA interrupt that the data is ready and can be sent. The front desk code is responsible for sending the data. The interrupt code is as follows: void DMA_Channel0_IRQHandler(void) { extern uint8_t StartSend; /* ADPCM encoding uint8_t d1 = ADPCM_Encode(adc_value); uint16_t d2 = ADPCM_Decode(d1); */ //Send audio data StartSend = 1; dma_interrupt_flag_clear(DMA_CH0,DMA_INT_FLAG_FTF); }[/code] Here I found an anti-human design of the DMA driver of the GD32F350 firmware library
Based on past experience, this should be a pointer. I don't know what the GD32 firmware library engineer thought of passing a structure entity here. I had to change it myself. The configuration code of TIIMER1 is as follows: