cancel
Showing results for 
Search instead for 
Did you mean: 

Initialization of OpAmps in STM32G474

ErX
Visitor

Hi,

I'm going to use four different OpAmps in the STM32G474, namely OPAMP3, OPAMP4, OPAMP5, and OPAMP6.

At this moment I try to initialize all four OpAmps. The first three work perfectly well, the initialization of OPAMP6 results in a problem. The State of OPAMP6 is HAL_OPAMP_STATE_CALIBBUSY. And, therefore result in an error.

For the first three the State is '28', and initialize perfectly well.

How can I fix this? What is causing this behavior?

With kind regards,

ErX

1 ACCEPTED SOLUTION

Accepted Solutions

At this stage better to test without RTOS. Create a new project from scratch then do the test. It could be something related to your implementation.

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.

View solution in original post

4 REPLIES 4
mƎALLEm
ST Employee

Hello,

You need to show your code.

How to write your question to maximize your chances to find a solution

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.

Hi,

I'm using FreeRTOS to run a few tasks. Handling analog outputs via the OpAmps is done in my AnaControl-class.

I have one method to initialize all four OpAmps. The last one fails.

Here is the code of the initialize-method:

bool AnaControl::InitOpAmpModules()
{
	m_hOpAmp3.Instance = OPAMP3;
	m_hOpAmp3.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
	m_hOpAmp3.Init.Mode = OPAMP_FOLLOWER_MODE;
	m_hOpAmp3.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
	m_hOpAmp3.Init.InternalOutput = DISABLE;
	m_hOpAmp3.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
	m_hOpAmp3.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
	if (HAL_OPAMP_Init(&m_hOpAmp3) != HAL_OK)
		return false;

	m_hOpAmp4.Instance = OPAMP4;
	m_hOpAmp4.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
	m_hOpAmp4.Init.Mode = OPAMP_FOLLOWER_MODE;
	m_hOpAmp4.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
	m_hOpAmp4.Init.InternalOutput = DISABLE;
	m_hOpAmp4.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
	m_hOpAmp4.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
	if (HAL_OPAMP_Init(&m_hOpAmp4) != HAL_OK)
		return false;

	m_hOpAmp5.Instance = OPAMP5;
	m_hOpAmp5.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
	m_hOpAmp5.Init.Mode = OPAMP_FOLLOWER_MODE;
	m_hOpAmp5.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
	m_hOpAmp5.Init.InternalOutput = DISABLE;
	m_hOpAmp5.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
	m_hOpAmp5.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
	if (HAL_OPAMP_Init(&m_hOpAmp5) != HAL_OK)
		return false;

	m_hOpAmp6.Instance = OPAMP6;
	m_hOpAmp6.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
	m_hOpAmp6.Init.Mode = OPAMP_FOLLOWER_MODE;
	m_hOpAmp6.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
	m_hOpAmp6.Init.InternalOutput = DISABLE;
	m_hOpAmp6.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
	m_hOpAmp6.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
	if (HAL_OPAMP_Init(&m_hOpAmp6) != HAL_OK)
		return false;

	return true;
}

At this stage better to test without RTOS. Create a new project from scratch then do the test. It could be something related to your implementation.

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.
ErX
Visitor

Hi,

It worked great without RTOS. I thought of why. I think the m_hOpAmp<n> objects were created on the stack. When the RTOS switches tasks (and therefore the contents of the stack), they could be gone.

I went back to my RTOS project and moved the object from the stack into the memory. Now it works perfectly.

Greetings,

ErX