我正在尝试从我的 G473 生成来自 DAC3(仅连接到内部外围设备)的信号,并在跟随模式下通过 OPAMP1 输出该值。然而,OPAMP 引脚的输出永远处于低电平。我将 CUBEIDE 的 DAC 设置为:
- 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();
- }
- }
我将 CUBEIDE 的 OPAMP 设置为:
- 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();
- }
- }
然后在我的主要功能上,启用 DAC:
- HAL_DAC_Start(&hdac3, DAC_CHANNEL_1);
在 while 循环中,我设置了 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;
- }
我是不是配置错了。我需要调用其他功能来设置 OPAMP 吗?DAC1 和 DAC2 处于完美的工作状态。谢谢!