2021-09-20 06:14 PM
I try to learn how to use OPAMP by testing the example code Examples/OPAMP/OPAMP_PGA/.
The MCU board is Nucleo-G431RB.
This is the case of OPAMP_PGA_GAIN_2_OR_MINUS_1: blue line is output by DAC and red is by OPAMP.
My 1st question: why the amplified signal is distorted. Isn't it supposed to be another sine wave?
This is the case of OPAMP_PGA_GAIN_4_OR_MINUS_3.
My 2nd question: the amplitudes of the amplified signal seem not matching the gain.
Once the gain >= 8, the amplified signal becomes almost straight line. I also wonder why.
I want to modify the example code: I want to route the OPAMP output internally to a ADC channel. What steps I need to do?
Solved! Go to Solution.
2021-09-24 02:14 AM
Hi @HDaji.1 (Community Member) ,
Did you connect externally PA4 (DAC1_OUT1) to PA1 (OPAMP3_VINP)?
Those 2 pins must be connected together to sent signal from DAC to OPAMP. Those 2 pins are beside on Nucleo - so probably you didn't connect them together and there is only crosstalk from PA4 to PA1.
Regards
Igor
2021-09-22 09:21 AM
Hi @HDaji.1 ,
I need to do some tests before answering the 2 questions. I add @Igor Cesko in case he has some hints.
But I would like to come back to your last request I want to modify the example code: I want to route the OPAMP output internally to a ADC channel. What steps I need to do?
What is good with the examples in STM32CubeG4 is that you have an ioc file with the example.
You can use it to do some more configuration and add other peripherals.
First thing to do in your case is to change OPAMP mode as "PGA Internally Connected" from STM32CubeMX configuration wizard.
Referring to the table "Operational amplifier possible connection" of the reference manual RM0440, you can see that OPMAP3_VOUT can be connected to ADC1_IN12 or ADC2_IN18 (on STM32G431RB).
If you hover over the cursor on ADC1 or ADC2, you will have a pop-up guiding you each time on the configuration to setup:
Once the configuration is done, you can generate your project and the new setup will be added to initial project.
-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-09-22 10:15 AM
Hi @HDaji.1 (Community Member) ,
Please check at first in the code if the OPAMP is correctly configured in required mode. We observed one mistake in STM32CubeMX - for STM32G4 is there not possible to set OPAMP into "PGA internally connected" mode. This mode was present in STM32CubeMX in past but now disappeared (by mistake). If you generated code from the .ioc file (STM32CubeMX) then is there probability that generated code is wrong (but original code should be OK). See please this STCommunity entry for solution.
The OPAMP works fine and required functionality is possible to correctly set by proper OPAMP setting.
Regards
Igor
2021-09-23 05:43 PM
@Amel NASRI
I checked IN12 Single-ended. Anything else?
And in ADC2 menu, I don't see IN18, instead it is sth like this:
Why is it different from ADC1?
2021-09-23 05:55 PM
In CubeMX, I chose "PGA internally connected", and in the generated code function: MX_OPAMP3_Init, I got this.
hopamp3.Init.Mode = OPAMP_PGA_MODE;
you mean that mode is not correct? But I have only 3 options from stm32g4xx_hal_opamp.h.
#define OPAMP_STANDALONE_MODE (0x00000000UL) /*!< standalone mode */
#define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
#define OPAMP_FOLLOWER_MODE OPAMP_CSR_VMSEL /*!< follower mode */
2021-09-23 07:12 PM
Hi Guys,
In this DAC-->OPAMP example, DAC value change is triggered by "Timer 2 trigger out event", which I guess happens in a Timer2 timeout function. However, I cannot find in which c file it is located.
2021-09-24 01:48 AM
Hi @HDaji.1 ,
Timer2 is initialized in stm32g4xx_hal_msp.c. Then, it is set as a trigger for DAC conversions in the function MX_DAC_Init():
sConfig.DAC_Trigger = DAC_TRIGGER_T2_TRGO;
-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-09-24 02:14 AM
Hi @HDaji.1 (Community Member) ,
Did you connect externally PA4 (DAC1_OUT1) to PA1 (OPAMP3_VINP)?
Those 2 pins must be connected together to sent signal from DAC to OPAMP. Those 2 pins are beside on Nucleo - so probably you didn't connect them together and there is only crosstalk from PA4 to PA1.
Regards
Igor
2021-09-25 04:47 AM
@Amel NASRI
In this case, because DAC is directly triggered by timer, MCU is not involved and spared. Is it correct to say that?
2021-09-25 04:53 AM
@Igor Cesko Once I connect PA4 to PA1, I see amplified signal from PB1 (OPAMP3_OUT). Thx for the tip.
In the readme file, it says "Connect a wire between DAC output (PA4 - pin 32 on connector CN7) to OPAMP non inverting input (PB0 - pin 34 on connector CN7)". I guess it is wrong, isn't it?