cancel
Showing results for 
Search instead for 
Did you mean: 

Confusion about Workbench external OPAMP gain - Bug in code generation?

ALedi.1
Associate III

In the workbench (5.Y.3 MCSDK-FUL) there are two locations to set/calculate the OP-gain. One is located under "Analog Input and Protection" and one under "Current Sensing". In my configuration I use external resistors so set the gain of the OPAMP. I found out that if you set the gain using the "calculate" button under "Analog Input and Protection" by entering all the right resistor values, and then go to the "Current Sensing" menu, the gain showing there is the same that you entered in the Analog input section. Now I save the project under a new name as Configuration 1 and generate the code. When I check the source code I can find the gain is set to as 7.333 (power_stage_parameters.h). Now back in the workbench I change the resistor values under "Current sensing" menu using the "calculate" button, I set the gain to 1 and click on "confirm". Now the gain value is changed only there under "current sensing", but if I go to "Analog Input and Protection", the previous set gain value is still shown 7.333). Now I save the project under a new name (Configuration 2) and generate the code, and I look in the source code for the gain value, it is still set to the old value 7.333, but now in the drive_parameters.h all the PI-regulator and CORDIC parameters are changed and also the rev-up current values in s16A unit are different. Now the question is should you enter the gain values twice in both menus (are the two meant to be the same?) or will the software apply the gain twice for the current measurement? Because those two gain values seem to be independent of each other, and the value shown under current sensing seems to be used for current calculation, even if the field itself is "greyed out" (and therefore assumed to be inactive)

0693W00000NsLzeQAF.png

3 REPLIES 3
Fred V.
ST Employee

Hello,

Yes, there are two places where current sensing OpAmp gains can be calculate in the Workbench of MCSDK 5.x, but only one of them is used in any project (or so should it be...):

  • In the "Analog Input and Protection" dialog, you set the gain of the OpAmps embedded in the MCU (if the MCU embeds OpAmps, which is the case for the STSPIN32G4. You can configure the gain here when "Embedded PGA" is checked in the top left of the dialog:

0693W00000NsvIbQAJ.png 

  • In the "Power Stage - Current Sensing" dialog, you set the gain of the current sensing OpAmp if it is present on the control stage (and not in the MCU). You can configure this gain when "Amplification on Board" is checked in this dialog:

0693W00000NsvQaQAJ.png 

If "Amplification on Board" is checked in the Current Sensing dialog, then "Embedded PGA" is cleared in the Analog Input and Protection. And vice-versa. There is a bug here, since you should not be able to access the Calculate button on the Current Sensing dialog if "Amplification on Board" is not checked. This bug will not be fixed on MCSDK 5.x as this series of MCSDK will soon be discontinued in favor of MCSDK 6.x. MCSDK 6.0.0 already fixes this issue.

The PI parameters, CORDIC (and PLL) parameters and the current targets for the rev-up are being changed when the current measurement amplification gain is changed (if computed automatically) . This is because the amplification gain impacts the definition of how much amperes 1 s16A is. The trouble you face is that with the bug you experience, the gains you set in the Current Sensing dialog, even if not used, are propagated to the PIs, the CORDIC, the PLL and the rev-up resulting in their parameters being recomputed. To solve the issue (when it has occurred), you need to go back to the Analog Input and Protection dialog change the resistors, click confirm, change the resistors back and click confirm. This trick should do it.

Now, to avoid the issue, it is best to modify the gains where they are used: in the Analog Input and Protection dialog if you use the MCU embedded OpAmp, or in the Current Sensing dialog if you do not use MCU embedded OpAmps (then making sure that "Amplification on Board" is checked.

The UI is indeed quite confusing on that aspect. We are working towards enhancing this with the MCSDK 6.0 onwards.

I hope it will help.

Best Regards,

Fred

thank you for explaining the bug, but a part of my question is still unanswered. When I open the example file for EVSPIN32G4, under Analog Input and Protection, the gain is set to 7.33. When I check under Current Sensing the gain is also set to 7.33. Now is this the correct way to set up the gain? Should the gains on both settings windows be set to the same value? Are those meant to be the same? Or should I set the gain in the current sensing window to "1"? My problem is that somehow, on my custom PCB the OPAMPs are amplifying the shunt voltage by a factor of approx. 50 instead of only 7.33. It appears to me as if the gain is somehow applied twice (7.33 x 7.33 = 53) and I have no idea why. I already opened a seperate thread for this issue.

Fred V.
ST Employee

OK. I got it.

Only one of these gain will be used. And the one that will actually be used depends on the "Amplification on Board" checkbox (from the Current Sensing dialog) and on the "Embedded PGA" checkbox (from the Analog Input and Protection dialog). One (and only one) of these checkbox must be checked.

If Amplification on Board is checked, the gain is set on the Current Sensing Dialog.

If Embedded PGA is checked, the gain is set on the Analog Input and Protection Dialog.

You may notice that changing the gain on the Analog Input and Protection Dialog changes that of the Current Sensing Dialog. The reverse is not true. However, the gain that is used is indeed the one resulting from the criteria above.

This indeed does not explain why the gain you experience is approx. 50. For this, I have no clue.

Best Regards,

Fred