2025-09-26 8:29 AM
Hi,
I designed the us and ms delay functions using timer 2 and 4.
Initially in the PLL source, I was using HSI, but it had some errors, so I switched it to HSE. I was using my delay function to control the DAC output, but when I switched to HSE, all my delay functions became twice as long.
This is my code.
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 2854); //
Delay_us(500);
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 868);
Delay_us(500);
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 1861);
Delay_ms(10);
}
This is the waveform of the oscilloscope.
In the clock tree settings, I only switched the clock source to HSE, and the divider settings did not change. I wonder why this happened.
Best,
2025-09-26 9:24 AM
Change HSE to 8 MHz if that's what's on your board.
You don't mention your board, but most of the ST boards have this as 8 MHz.