cancel
Showing results for 
Search instead for 
Did you mean: 

When I used HAL_ADC_Start_DMA Timer Pwm does not work

Bugrahan
Associate

I am working with stm32f407vg disc. I have to read couples adc same time, one of the sensors is should be control a servo motor. Without this hal function HAL_ADC_Start_DMA servo works clearly. when i activate this function servo doesnt work.

3 REPLIES 3

Ok, and what's the TIM's relationship to the ADC and the DMA?

Doesn't Work isn't really adequate to understand what is, and is not working.

Perhaps look at the ADC, TIM and DMA registers to understand the states of the assorted peripherals.

Show some code and context.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Bugrahan
Associate

Sorry, i should have posted some code.

When i trying find where is the mistake, i arranged like this.

If i made toggle comment in line 52 servo works flawlessly. Does not work in this case.

I dont understand where i making mistake.

Thank you for your answer.

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint32_t servo_move = 0;
uint32_t adc_buffer[2];
uint32_t sensor_1=0, sensor_2=0;
 
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
	sensor_1=adc_buffer[0];
	sensor_2=adc_buffer[1];
}
 
 
void servoAngle(int angle)
{
	if (angle < 0 )
		angle=0;
	if (angle > 180)
		angle = 180;
	angle = angle+35;
	 __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1,angle);
 
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */
  HAL_ADC_Start_DMA(&hadc1, adc_buffer, sizeof(adc_buffer));
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
	  for(servo_move=0;servo_move<=180;servo_move++)
	  {
		 servoAngle(servo_move);
		 HAL_Delay(50);
	  }
	  servoAngle(90);
	  HAL_Delay(3000);
 
  }
  /* USER CODE END 3 */
}

TDK
Guru

Probably the CPU is swamped with ADC callbacks. Debug your code, hit pause, is it in an ADC complete callback?

Increase size of ADC buffer or decrease sampling frequency.

If you feel a post has answered your question, please click "Accept as Solution".