cancel
Showing results for 
Search instead for 
Did you mean: 

Initiate 2nd ADC Watchdog Help

DWill.4
Associate II

I have two ADC channels that l am trying to configure to have their own ADC watchdog. Experimenting with the threshold values l can get the first watchdog to fire on each channel and it calls HAL_ADC_LevelOutOfWindowCallback() as needed. The second ADC watchdog does not fire at all. I didn't see it be initialized so l created some code that doesn't work. Can someone give insight on this? I eventually plan to use all three ADC watchdogs at once.

configuration:

static void MX_ADC3_Init(void)
{
 
  /* USER CODE BEGIN ADC3_Init 0 */
 
  /* USER CODE END ADC3_Init 0 */
 
  ADC_AnalogWDGConfTypeDef AnalogWDGConfig = {0};
  ADC_ChannelConfTypeDef sConfig = {0};
 
  /* USER CODE BEGIN ADC3_Init 1 */
 
  /* USER CODE END ADC3_Init 1 */
  /** Common config
  */
  hadc3.Instance = ADC3;
  hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
  hadc3.Init.Resolution = ADC_RESOLUTION_16B;
  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc3.Init.LowPowerAutoWait = DISABLE;
  hadc3.Init.ContinuousConvMode = DISABLE;
  hadc3.Init.NbrOfConversion = 2;
  hadc3.Init.DiscontinuousConvMode = DISABLE;
  hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
  hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
  hadc3.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc3) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Analog WatchDog 1
  */
  AnalogWDGConfig.WatchdogNumber = ADC_ANALOGWATCHDOG_1;
  AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;
  AnalogWDGConfig.Channel = ADC_CHANNEL_0;
  AnalogWDGConfig.ITMode = ENABLE;
  AnalogWDGConfig.HighThreshold = 67108863;
  AnalogWDGConfig.LowThreshold = 0;
  if (HAL_ADC_AnalogWDGConfig(&hadc3, &AnalogWDGConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  sConfig.OffsetSignedSaturation = DISABLE;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC3_Init 2 */
 
  /* Calibrate internal sensor on start up, Single-ended */
  if (HAL_ADCEx_Calibration_Start(&hadc3,ADC_CALIB_OFFSET,ADC_SINGLE_ENDED) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* USER CODE END ADC3_Init 2 */
 
}

code:

void watchdog_config_ether_arm(void){
 
	ADC_AnalogWDGConfTypeDef AnalogWDGConfig = {0};
	AnalogWDGConfig.WatchdogNumber = ADC_ANALOGWATCHDOG_2;
	AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;
	AnalogWDGConfig.Channel = ADC_CHANNEL_1;
	AnalogWDGConfig.ITMode = ENABLE;
 
	/* Configure threshold levels for ARM */
	AnalogWDGConfig.HighThreshold = 67108863; 
	AnalogWDGConfig.LowThreshold = 0;
 
	if (HAL_ADC_AnalogWDGConfig(&hadc3, &AnalogWDGConfig) != HAL_OK)
	  {
	    Error_Handler();
	  }
}

2 REPLIES 2
Imen.D
ST Employee

Hello @DWill.4​ ,

Which CubeMx release are you using ?

Please share your ioc file for check.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
SavasSahin
Associate II

Hi DWill4,

I am working with same issue, did you solve it ? If yes would be nice to share the solution.

if no;

You should be sure before configuring, there is no ADC conversion on going. Did you try with stop conversion function in the beginning of the second function?

void watchdog_config_ether_arm(void){

/**** you should add stop Conversion****/

ADC_ConversionStop(&hadc3,ADC_REGULAR_INJECTED_GROUP);

ADC_AnalogWDGConfTypeDef AnalogWDGConfig = {0};

AnalogWDGConfig.WatchdogNumber = ADC_ANALOGWATCHDOG_2;

AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;

AnalogWDGConfig.Channel = ADC_CHANNEL_1;

AnalogWDGConfig.ITMode = ENABLE;

/* Configure threshold levels for ARM */

AnalogWDGConfig.HighThreshold = 67108863;

AnalogWDGConfig.LowThreshold = 0;

if (HAL_ADC_AnalogWDGConfig(&hadc3, &AnalogWDGConfig) != HAL_OK)

{

Error_Handler();

}

}