5907 views|2 replies

606

Posts

20

Resources
The OP
 

【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: Its schematic diagram is as follows: From the schematic diagram above, you can just connect the Output to any input channel of the ADC. Here I choose ADC_CHANNEL_10. PC0 pin. 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:
  1. void adc_config(void) { //Configure the ADC trigger source TIMER1 CH1 event select adc_external_trigger_source_config(ADC_REGULAR_CHANNEL,ADC_EXTTRIG_REGULAR_T1_CH1); adc_data_alignment_config(ADC_DATAALIGN_RIGHT); adc_channel_length_config(ADC_REGULAR_CHANNEL,1); adc_regular_channel_config(0,ADC_CHANNEL_10,ADC_SAMPLETIME_71POINT5); adc_external_trigger_config(ADC_REGULAR_CHANNEL,ENABLE); adc_enable(); delay_10us(2); adc_calibration_enable(); //Enable DMA mode adc_dma_mode_enable(); }
复制代码
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:
  1. void dma_config(void) { dma_parameter_struct dmaParam; //DMA_CH0 ADC dma_deinit(DMA_CH0); dmaParam.periph_addr = (uint32_t)&ADC_RDATA; dmaParam.periph_inc = DMA_PERIPH_INCREASE_DISABLE; dmaParam.periph_width = DMA_PERIPHERAL_WIDTH_16BIT; dmaParam.memory_addr = (uint32_t)&wav_value; dmaParam.memory_inc = DMA_MEMORY_INCREASE_ENABLE; dmaParam.memory_width = DMA_MEMORY_WIDTH_16BIT; dmaParam.direction = DMA_PERIPHERAL_TO_MEMORY; dmaParam.number = 1; dmaParam.priority = DMA_PRIORITY_HIGH; dma_init(DMA_CH0,&dmaParam); dma_circulation_enable(DMA_CH0); dma_interrupt_enable(DMA_CH0,DMA_INT_FTF); dma_channel_enable(DMA_CH0); }
复制代码
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:
  1. timer_parameter_struct timParam; //Timer1 8KHz for ADC Sample. timParam.prescaler = 53; timParam.alignedmode = TIMER_COUNTER_EDGE; timParam.counterdirection = TIMER_COUNTER_UP; timParam.period = 124; //124 8k, 44 22k tim Param.clockdivision = TIMER_CKDIV_DIV1; timParam.repetitioncounter = 0; timer_init(TIMER1,&timParam); timer_parameter_struct timParam; //Timer1 8KHz for ADC Sample. timParam.prescaler = 53; timParam.alignedmode = TIMER_COUNTER_EDGE; timParam.counterdirection = TIMER_COUNTER_UP; timParam.period = 124; //124 8k, 44 22k timParam.clockdivision = TIMER_CKDIV_DIV1; timParam.repetitioncounter = 0; timer_init(TIMER1,&timParam);
复制代码
Here is mainly to configure the 8K ADC trigger. Well, today is here, the next article will share 2.4G voice transmission.




This post is from GD32 MCU

Latest reply

Thanks for sharing, like  Details Published on 2018-10-19 21:33
 

196

Posts

0

Resources
2
 
Thanks for sharing!
This post is from GD32 MCU
 
 
 

29

Posts

2

Resources
3
 
Thanks for sharing, like
This post is from GD32 MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list