STM32G431 Isolated sensor ADC software problem
Using STM32G431, I designed a controller and inverter with different pin sequences for my needs.
I used ACS781 as a current sensor. I use the software of ST only in test. Apart from that, I develop my own software.
In MC SDK 5.4.4 version, some corrections have been made on regular transformations, but this arrangement causes the software not to work in drives with insulated current sensors.
For this, I did backwards corrections to version 5.4.3 and the engine worked.
Also when I extracted the codes in 5.4.3 version it worked without any problems.
The CubeG4 Firmware Package I used is V1.2.0.
When I convert the RCM_ExecRegularConv() function into V5.4.3 as below, it works fine.
uint16_t RCM_ExecRegularConv (uint8_t handle)
{
uint16_t retVal;
LL_ADC_REG_SetSequencerRanks( RCM_handle_array[handle]->regADC,
LL_ADC_REG_RANK_1,
__LL_ADC_DECIMAL_NB_TO_CHANNEL( RCM_handle_array[handle]->channel ) );
LL_ADC_REG_ReadConversionData12( RCM_handle_array[handle]->regADC );
LL_ADC_REG_StartConversion( RCM_handle_array[handle]->regADC );
/* Wait until end of regular conversion */
while ( LL_ADC_IsActiveFlag_EOC( RCM_handle_array[handle]->regADC ) == 0u ) {}
retVal = LL_ADC_REG_ReadConversionData12( RCM_handle_array[handle]->regADC );
return retVal;
}The current version of V5.4.4 malfunctioning:
uint16_t RCM_ExecRegularConv (uint8_t handle)
{
uint16_t retVal;
uint8_t formerNext;
uint8_t i=0;
uint8_t LastEnable = RCM_MAX_CONV;
if (RCM_NoInj_array [handle].enable == false)
{
/* find position in the list */
while (i < RCM_MAX_CONV)
{
if (RCM_NoInj_array [i].enable == true)
{
if (RCM_NoInj_array [i].next > handle)
/* We found a previous reg conv to link with */
{
formerNext = RCM_NoInj_array [i].next;
RCM_NoInj_array [handle].next = formerNext;
RCM_NoInj_array [handle].prev = i;
RCM_NoInj_array [i].next = handle;
RCM_NoInj_array [formerNext].prev = handle;
i= RCM_MAX_CONV; /* stop the loop, handler inserted*/
}
else { /* We found an enabled regular conv,
* but do not know yet if it is the one we have to be linked to. */
LastEnable = i;
}
}
else
{ /* nothing to do */
}
i++;
if (i == RCM_MAX_CONV)
/* We reach end of the array without handler inserted*/
{
if (LastEnable != RCM_MAX_CONV )
/* we find a regular conversion with smaller position to be linked with */
{
formerNext = RCM_NoInj_array [LastEnable].next;
RCM_NoInj_array [handle].next = formerNext;
RCM_NoInj_array [handle].prev = LastEnable;
RCM_NoInj_array [LastEnable].next = handle;
RCM_NoInj_array [formerNext].prev = handle;
}
else
{ /* the current handle is the only one in the list */
/* previous and next are already pointing to itself (done at registerRegConv) */
RCM_currentHandle = handle;
}
}
else
{
/* Nothing to do we are parsing the array, nothing inserted yet*/
}
}
/* The handle is now linked with others, we can set the enable flag */
RCM_NoInj_array [handle].enable = true;
RCM_NoInj_array [handle].status = notvalid;
if (RCM_NoInj_array[RCM_currentHandle].status != ongoing )
{/* select the new conversion to be the next scheduled only if a conversion is not ongoing*/
RCM_currentHandle = handle;
}
}
else
{
/* Nothing to do the current handle is already scheduled */
}
if (PWM_Handle_M1.ADCRegularLocked == false)
/* The ADC is free to be used asynchronously*/
{
LL_ADC_REG_SetSequencerRanks( RCM_handle_array[handle]->regADC,
LL_ADC_REG_RANK_1,
__LL_ADC_DECIMAL_NB_TO_CHANNEL( RCM_handle_array[handle]->channel ) );
LL_ADC_REG_ReadConversionData12( RCM_handle_array[handle]->regADC );
/* Start ADC conversion */
LL_ADC_REG_StartConversion( RCM_handle_array[handle]->regADC );
/* Wait EOC */
while ( LL_ADC_IsActiveFlag_EOC( RCM_handle_array[handle]->regADC ) == RESET )
{
}
/* Read the "Regular" conversion (Not related to current sampling) */
RCM_NoInj_array [handle].value = LL_ADC_REG_ReadConversionData12( RCM_handle_array[handle]->regADC );
RCM_currentHandle = RCM_NoInj_array [handle].next;
RCM_NoInj_array [handle].status = valid;
}
retVal = RCM_NoInj_array [handle].value;
return retVal;
}