Answer the question
In order to leave comments, you need to log in
How to correctly set the interrupt frequency for sound output through the DAC of the microcontroller?
Gentlemen, I have encountered an unusual problem and need help and advice.
Task: output a WAV file to the DAC channel of the microcontroller (I work with the STM32F4discovery board). The task is trivial, you don't even need to read the file from the flash drive - I immediately ripped out the PCM data from the WAV file (the file was specially prepared: 8 kHz, 8-bit, mono) and loaded them as an array from the header file.
The next portion of information is output to the DAC by interrupts from a timer operating at a frequency of 8 kHz (which corresponds to the file sampling frequency). However, when I try to bring it all to the speaker, I get some kind of wheezing and hiss, which is quite far from what I want to hear.
void Audio_TIM_Init(void) {
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
__HAL_RCC_TIM3_CLK_ENABLE();
htim.Instance = TIM3;
htim.Init.Prescaler = (uint16_t) (SystemCoreClock / 1000000) - 1;
htim.Init.CounterMode = TIM_COUNTERMODE_UP;
htim.Init.Period = 125;
htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim, &sClockSourceConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim, &sMasterConfig);
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
HAL_TIM_Base_Start_IT(&htim);
}
Answer the question
In order to leave comments, you need to log in
Connect your DAC to an oscilloscope (sound card will suffice) and look at the signal.
Remember Kotelnikov's theorem.... The polling frequency should be at least twice as high as the frequency of the polled signal. And, of course, filtering... That is, the frequency is higher than 30-40 kHz... The more often, the better....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question