2021-01-29 01:16 AM
I'm trying to generate a signal from DAC3 (connected only to internal peripherals) from my G473 and output that value through OPAMP1 in follower mode. The output of the pin of the OPAMP is stuck at low forever however. I set the DAC from CUBEIDE as such:
static void MX_DAC3_Init(void)
{
DAC_ChannelConfTypeDef sConfig = {0};
hdac3.Instance = DAC3;
if (HAL_DAC_Init(&hdac3) != HAL_OK) {
Error_Handler();
}
/** DAC channel OUT1 config
*/
sConfig.DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC;
sConfig.DAC_DMADoubleDataMode = DISABLE;
sConfig.DAC_SignedFormat = DISABLE;
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_Trigger2 = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_INTERNAL;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac3, &sConfig, DAC_CHANNEL_1) != HAL_OK){
Error_Handler();
}
}
I set the OPAMP from CUBEIDE as such:
static void MX_OPAMP1_Init(void){
hopamp1.Instance = OPAMP1;
hopamp1.Init.PowerMode = OPAMP_POWERMODE_NORMAL;
hopamp1.Init.Mode = OPAMP_FOLLOWER_MODE;
hopamp1.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
hopamp1.Init.InternalOutput = DISABLE;
hopamp1.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
hopamp1.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&hopamp1) != HAL_OK)
{
Error_Handler();
}
}
And then on my main function, I enable DAC:
HAL_DAC_Start(&hdac3, DAC_CHANNEL_1);
and on the while loop, I set the value of the DAC:
while (1)
{
/* USER CODE BEGIN 3 */
var = value * (0xfff+1)/3.3;
HAL_DAC_SetValue(&hdac3, DAC_CHANNEL_1, DAC_ALIGN_12B_R, var);
value += 0.5;
HAL_Delay(100);
if (value > 3) value = 0.2;
}
Am I configuring something wrong. Is there an additional function I need to call to setup the OPAMP? DAC1 and DAC2 are in perfect working condition. Thank you!
Solved! Go to Solution.
2021-02-02 01:29 AM
Hi @RAnge.1 ,
There is an example in the STM32CubeG4 package which is doing almost the same thing.
It is STM32Cube_FW_G4\Projects\STM32G474E-EVAL\Examples\OPAMP\OPAMP_InternalFollower.
You can also review the configuration in STM32CubeMX using the .ioc file provided there.
What I noted missing on the code you shared are the following:
Please check this and let me know if you succeeded to make it work.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2021-02-02 01:29 AM
Hi @RAnge.1 ,
There is an example in the STM32CubeG4 package which is doing almost the same thing.
It is STM32Cube_FW_G4\Projects\STM32G474E-EVAL\Examples\OPAMP\OPAMP_InternalFollower.
You can also review the configuration in STM32CubeMX using the .ioc file provided there.
What I noted missing on the code you shared are the following:
Please check this and let me know if you succeeded to make it work.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.