2017-10-04 04:01 AM
Hello everyone!
I'm working on the project with an STM32F373 microprocessor. I'm using all three SDADC-s simultaneously. SDADC3 works constantly in Injected scan mode with frequency 16,66kHz. SDADC1 and SDADC2 are working on 16,66 kHz and in the Injected scan mode for 200ms. SDADC2 is triggered synchronously with SDADC1. When the samples are collected both SDADC-s (1 and 2) are stopped in order to reset their configuration. I set both of them to Regular conversion and single channel fast mode so they both can work with the frequency 50 kHz. Now I run them for 100 ms and then stop them again, set to the original and repeat the process.The problem is that this doesn't work well. It looks like something stays in the output buffer and then the SDADC need some time to stabilize back, like 200 ms (like uncharging and charging the capacitor. Am I something missing during reconfiguration? Or It just isn't possible to switch configurations so quick?
If I don't switch the configuration during measurement everything works fine. Below is my C code.
Below is my C code. I'm using HAL drivers.
void MX_SDADC1_Init(void)
{
SDADC_ConfParamTypeDef ConfParamStruct;
hsdadc1.Instance = SDADC1;
hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
hsdadc1.Init.ReferenceVoltage = SDADC_VREF_EXT;
hsdadc1.InjectedTrigger = SDADC_SOFTWARE_TRIGGER;
if (HAL_SDADC_Init(&hsdadc1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_MultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Injected Mode
*/
if (HAL_SDADC_SelectInjectedDelay(&hsdadc1, SDADC_INJECTED_DELAY_NONE) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_SOFTWARE_TRIGGER) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_SelectRegularTrigger(&hsdadc1, SDADC_SOFTWARE_TRIGGER) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_4|SDADC_CHANNEL_6
|SDADC_CHANNEL_8, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Set parameters for SDADC configuration 0 Register
*/
ConfParamStruct.InputMode = SDADC_INPUT_MODE_DIFF;
ConfParamStruct.Gain = SDADC_GAIN_1;
ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
ConfParamStruct.Offset = 0;
if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_4, SDADC_CONF_INDEX_0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_6, SDADC_CONF_INDEX_0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Injected Channel
*/
if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_8, SDADC_CONF_INDEX_0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_SDADC_CalibrationStart(&hsdadc1,SDADC_CALIBRATION_SEQ_2);
while(HAL_SDADC_PollForCalibEvent(&hsdadc1,CALIBRATION_TIMEOUT)!=HAL_OK);
}
void SDADC1_set_normal(void)
{
/* Disable SDADC */
hsdadc1.Instance->CR2 &= ~(SDADC_CR2_ADON);
hsdadc1.Instance->CR2 &= ~(SDADC_CR2_FAST);
hsdadc1.Instance->CR2 |= SDADC_FAST_CONV_DISABLE;
/* Enable SDADC */
hsdadc1.Instance->CR2 |= SDADC_CR2_ADON;
/* Wait end of stabilization */
while((hsdadc1.Instance->ISR & SDADC_ISR_STABIP) != 0U)
{
}
hsdadc1.State = HAL_SDADC_STATE_READY;
if (HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_8|SDADC_CHANNEL_4
|SDADC_CHANNEL_6, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
void SDADC1_set_fast(void)
{
/* Disable SDADC */
hsdadc1.Instance->CR2 &= ~(SDADC_CR2_ADON);//more bit drgac ne dela
hsdadc1.Instance->CR2 &= ~(SDADC_CR2_FAST);
hsdadc1.Instance->CR2 |= SDADC_FAST_CONV_ENABLE;
/* Enable SDADC */
hsdadc1.Instance->CR2 |= SDADC_CR2_ADON;
/* Wait end of stabilization */
while((hsdadc1.Instance->ISR & SDADC_ISR_STABIP) != 0U)
{
}
hsdadc1.State = HAL_SDADC_STATE_READY;
if(SDADC1_ch_cnt==0)
{
if (HAL_SDADC_ConfigChannel(&hsdadc1, SDADC_CHANNEL_8, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
uln_thd_channel=ULN1_CHANNEL;
}
else if(SDADC1_ch_cnt==1)
{
if (HAL_SDADC_ConfigChannel(&hsdadc1, SDADC_CHANNEL_4, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
uln_thd_channel=ULN2_CHANNEL;
}
else if(SDADC1_ch_cnt==2)
{
if (HAL_SDADC_ConfigChannel(&hsdadc1, SDADC_CHANNEL_6, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
uln_thd_channel=ULN3_CHANNEL;
}
SDADC1_ch_cnt++;
if(SDADC1_ch_cnt==3) SDADC1_ch_cnt=0;
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
#stm32f373 #sdadc