2019-06-27 02:27 PM
Hello,
I'm trying to use both channels of the DAC on STM32L432, but I'm having a very annoying issue: channel 2 only goes up to 0.5V! I think I've configured both channels correctly, because both channels output voltage that changes with my code... but the output just looks like this:
What I expected to see was two identical triangle waves... I'm sweeping an integer from 0-4095 and back down to 0, and sending it to both DAC's. I've tried multiple different commands to write the values to the DAC's, including:
HAL_DAC_SetValue(&hdac1, 1, DAC_ALIGN_12B_R, dac_val);
HAL_DAC_SetValue(&hdac1, 2, DAC_ALIGN_12B_R, dac_val);
and this:
DAC1->DHR12R1 = dac_val;
DAC1->DHR12R2 = dac_val;
and this:
HAL_DACEx_DualSetValue(&hdac1, DAC_ALIGN_12B_R, dac_val, dac_val);
All produce the exact same wave forms in the photo... Am I doing something wrong? Do I need to configure the two channels differently?
Here is my config:
static void MX_DAC1_Init(void)
{
DAC_ChannelConfTypeDef sConfig = {0};
/** DAC Initialization
*/
hdac1.Instance = DAC1;
if (HAL_DAC_Init(&hdac1) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT1 config
*/
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT2 config
*/
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
}
Any information that anyone could give me on this would be greatly appreciated. I could not find any tutorials or examples where people are using BOTH DAC channels.
Thank you!
Solved! Go to Solution.
2019-06-27 03:05 PM
Well... 30 minutes after posting this question I figured out what the problem is... typical.
This behavior really looked like a short circuit to me, something like a diode holding the channel 2 output to near 0V... sure enough, looking at the schematic for STM32L432KC I find that PA5 is shorted to PB7 by solder bridge 18... removed the solder birdge and now it works beautifully.
FYI to anyone who comes across a similar issue in the future: the schematic for your board might be more important than you think!
2019-06-27 02:29 PM
The photo I pasted in the original post did not show up... here is the photo of the wave forms
2019-06-27 03:05 PM
Well... 30 minutes after posting this question I figured out what the problem is... typical.
This behavior really looked like a short circuit to me, something like a diode holding the channel 2 output to near 0V... sure enough, looking at the schematic for STM32L432KC I find that PA5 is shorted to PB7 by solder bridge 18... removed the solder birdge and now it works beautifully.
FYI to anyone who comes across a similar issue in the future: the schematic for your board might be more important than you think!