L431 stops working after enabling DAC
I am trying to use the onboard DAC to generate a sine signal. The program runs without any problem on the Nucleo L432KC board but it would not work on our PCB with L431. As soon as the DAC is enabled with LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_1); the program would stop running (or at least it appeared to be stopped from debug view) and all the variable values would reset to 0 in live expressions.
See DAC init code:
static void DAC_Init(void)
{
LL_DAC_InitTypeDef DAC_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DAC1);
/** DAC channel OUT1 config
*/
DAC_InitStruct.TriggerSource = LL_DAC_TRIG_SOFTWARE;
DAC_InitStruct.WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
DAC_InitStruct.OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
DAC_InitStruct.OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO;
DAC_InitStruct.OutputMode = LL_DAC_OUTPUT_MODE_NORMAL;
LL_DAC_Init(DAC1, LL_DAC_CHANNEL_1, &DAC_InitStruct);
LL_DAC_DisableTrigger(DAC1, LL_DAC_CHANNEL_1);
}
DAC start code:
static void Test(void)
{
if(!Test_flag)
{
if(!((READ_BIT(TIM1->CR1, TIM_CR1_CEN) == (TIM_CR1_CEN)) ? 1UL : 0UL)) //Check if counter is enabled
{
LL_TIM_SetCounter(TIM1, 0);
LL_TIM_ClearFlag_UPDATE(TIM1);
LL_TIM_EnableIT_UPDATE(TIM1);
LL_TIM_EnableCounter(TIM1);
}
LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_1);
}
}
TIM1 interrupt function to calculate for new sine output:
void TIM1_UP_TIM16_IRQHandler(void)
{
if(LL_TIM_IsActiveFlag_UPDATE(TIM1))
{
LL_TIM_ClearFlag_UPDATE(TIM1);
LL_TIM_DisableCounter(TIM1);
LL_TIM_SetCounter(TIM1, 0);
DAC1->DHR12R1 = (0.9428 / Supply_Voltage * sin((double)DAC_Count / 100 * 2 * PI) + 1) * 2048;
DAC_Count++;
if(DAC_Count >= 2500)
{
//LL_DAC_Disable(DAC1, LL_DAC_CHANNEL_1);
Test_flag = 0;
DAC_Count = 0;
}
LL_TIM_EnableCounter(TIM1);
}
}
What could be the cause of this problem?
Any general help/advice would be appreciated!
Zhi
