cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G031F4P ADC Trigger problem.

ABURM
Associate III

Hi everyone.

I am using STM32G431F4P MCU. I am using Timer3-Channel3 PWM output. PWM frequency is 20 kHz. ADC1 is DMA mode and i want to trigger ADC1 using Timer3-Channel1 (PWM generation no output). Timer3 and ADC1 settings are as follows;

0693W00000JPR75QAH.png0693W00000JPR88QAH.pngThis is code;

HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_3);
 
TIM3->CCR1 = TIM3->CCR3 = 1000;
 
HAL_Delay(100);
 
HAL_ADC_Start_DMA (&hadc1, (uint32_t*)&ADC1_value, 2);

But ADC1 is not triggered. It is only working one time (as soon as i start the ADC1). What is the problem?

Have a nice work.

1 ACCEPTED SOLUTION

Accepted Solutions
ABURM
Associate III

Ok guys, i fixed. Problem is DMA settings. I changed the "DMA mode" and "Data width". Now it is working. Thanks for your help.

Have a nice day.

View solution in original post

6 REPLIES 6
KnarfB
Principal III

G0 or G4, typo?

You set Pulse=0, is there a pulse at all? Might try a higher value.

hth

KnarfB

ABURM
Associate III

Sorry mate, my mistake i am using G0, not G4. I guess the problem is not ADC not triggering but DMA not working. I changed the trigger of the ADC1. I am currently using software trigger. I am reading current and voltage from inputs 0 and 2 of ADC1. I am doing PID in interrupt routine by reading these channels with DMA. DMA is not working properly right now. Program goes to the interrupt routine but I can only get the value of one of the channels (ADC1-IN0). Program is so simple;

  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
		HAL_Delay(1000);
		HAL_ADC_Start_DMA (&hadc1, (uint32_t*)&ADC1_value, 2);
  }
  /* USER CODE END 3 */
}

ABURM
Associate III

Ok, i solved the DMA problem. I'm starting the ADC from software and calculate new PID value in DMA interrupt. Now we are back to where we started. I can't trigger the ADC from the timer3.:grinning_face_with_sweat:

TDK
Guru

Did you fix the pulse=0 issue? Why use OC1REF at all? Using the update event is more straightforward.

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

Hi TDK. pulse=1000 didn't fix the problem. I am using OCREf because i want to read current and voltage feedbacks at the point i want. Also, update event didnt work. :expressionless_face:

ADC is working. ADC==>DR register is changing.I am seeing in system viewer window. But DMA interrupt is not working. I added breakpoint in interrupt routine. Program is not coming to this routine.

ABURM
Associate III

Ok guys, i fixed. Problem is DMA settings. I changed the "DMA mode" and "Data width". Now it is working. Thanks for your help.

Have a nice day.