2017-02-08 10:25 AM
Hello,
I am using the the HAL library for calibrating the DAC on STM32L4.
I read the documentation for DAC on page 286 (DOCID027704 Rev 4) in HAL L4 user manual. I am still confused about how to correctly use the HAL DAC calibration APIs.
My question is how does the
HAL_DACEx_SelfCalibrate() API work? Does it automatically apply the trimming offset?
or do I also need to use the APIs below?
HAL_DACEx_GetTrimOffset()
HAL_DACEx_SetUserTrimming()
If yes should I be manually adding the TrimOffset before making a call to
HAL_DAC_SetValue, s
omething like below?trim_offset = HAL_DACEx_GetTrimOffset(&hdac1, DAC_CHANNEL_2)
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_2, DAC_ALIGN_8B_R, input_data + trim_offset )?
Just for reference I have posted my current code below.
Below is my current calibration function:
void DAC_SelfCalibrate(void)
{ DAC_ChannelConfTypeDef sConfig; 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_USER; //Calibrate DAC channel 1 if (HAL_DACEx_SelfCalibrate(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK) { Error_Handler(); }//Calibrate DAC channel 2
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK) { Error_Handler(); }}and here is my code to set the DAC
int set_dac_val(uint8_t input_index, uint8_t input_data)
{
//set dac channel 1 if(input_index==0) { HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_8B_R, input_data);//set dac channel 2
}else if(input_index==1)
{
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_2, DAC_ALIGN_8B_R, input_data); } return 0;}Below is my sequence of calls for initialization.
MX_DAC1_Init();
DAC_SelfCalibrate();
HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
HAL_DAC_Start(&hdac1, DAC_CHANNEL_2);I have a similar question about HAL based ADC calibration and usage of calibration factor. I will post that under a separate thread.
Thanks!
#hal #dac #calibration2017-02-14 06:14 AM
Hello
Panuganti.Jnana.002
,The
useofthe HAL DAC calibration
depends on your needs and your use case defined.The settings can be figured out using self calibration handled by HAL_DACEx_SelfCalibrate whichruns automatically the calibration and enables the user trimming mode with fresh calibration results.
You can refer to the 'DAC channel buffer calibration' in your reference manual, it may help you on DAC calibration, on user trimming calibration and about the function to use for an N-bit DAC.
Maybe the working example in the STM32CubeL4 firmware package can help you to implement your project:
STM32Cube_FW_L4_V1.6.0\Projects\STM32L476G_EVAL\Examples\DAC
Best Regards
Imen