cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble using DMA to store ADC data in a Timer driven ADC sampling sequence.

BMcKe.2
Associate II

Description:

I'm running Timer 3 to produce a continuous PWM output on Channel 1.

I'm also running Timer 1 in slave mode to Timer 3, in PWM one shot mode with the Repetition Counter set to 5 and the Update Event Interrupt enabled.

This causes Timer 1 to produce a stream of 5 pulses on its Channel 1 output after every Update Event on Timer 3.

I'm running ADC 1 in DMA mode with data stored in an array variable.

The ADC is triggered by the 5 Capture/Compare Update events from Timer 1.

The DMA is set up to store the data in an array.

When Timer 1 completes the 5 pulses it issues an Update Event which triggers a Timer Interrupt.

A HAL_TIM_PeriodElapsedCallback(...) is called and a brief output pulse is generated on a GPIO output pin. This can be observed on the oscilloscope.

I use STM Studio to track the values in the data array.

I can vary the ADC input voltage.

Problem:

The data array values remain at zero no matter what the input voltage is set to.

What am I doing wrong?

Relevant Code:

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

#define Number_of_Samples 5    // Number of ADC samples to collect *** NOTE: Number_of_Samples = TIM1 RCR+1 ***

/* USER CODE END PD */

/* USER CODE BEGIN PV */

uint32_t adc_data[Number_of_Samples];     // Array for collecting raw ADC samples (12 bit)

uint32_t adc_data_sum;                    // Summation of all 5 values of adc_data

/* USER CODE END PV */

/* USER CODE BEGIN 2 */

 HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED);// Calibrate the ADC for both offset and linearity for single ended mode

 HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc_data, Number_of_Samples);// Start the ADC with DMA transfer of the output to the variable "adc_data"

 HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);     // Start the sampling time base timer

 HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);  // Start Timer 1 to produce 5 Capture/Compare Output Events that will trigger ADC1 to take a sample

 TIM1->DIER=0x1;                               // This instruction is required to enable Timer 1 Update Event Interrupt because HAL_TIM_PWM_Start_IT doesn't do it

 /* USER CODE END 2 */

/* USER CODE BEGIN 4 */

  void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)

{

  HAL_GPIO_WritePin(GPIOG, GPIO_PIN_4, GPIO_PIN_SET);  // Create an output pulse for the oscilloscope

  HAL_GPIO_WritePin(GPIOG, GPIO_PIN_4, GPIO_PIN_RESET); // Reset the output

}

STM32Cube IDE Set Up for ADC1:

 0693W00000AMZZUQA5.jpg 

0693W00000AMZZeQAP.jpg 

11 REPLIES 11

You can try to use/adopt some of the existing examples, e.g. https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/NUCLEO-H743ZI/Examples/ADC/ADC_DMA_Transfer

Or, read out the ADC and DMA registers content and check/post them, perhaps with reading the related parts of RM.

JW

BMcKe.2
Associate II

I duplicated the program and STM32CubeIDE setup, compiled it and ran it on an STM32F767ZI and it ran perfectly.

(Although I had to remove the HAL ADC Calibration command as it was specific to the STM32H743ZI.)

The DMA works fine and the output is as expected.

This tells me that there is nothing wrong with my C code, HAL code and STM32CubeIDE setup. There does seem to be a problem however with the STM32CubeIDE programming for the DMA for the STM32H743ZI that should be corrected by STM. As you suggested and according to the other posts, it seems to involve some complicated screwup in the MPU. The suggested solutions seem to require an intimate knowledge of the internal workings of he chip and extensive knowledge of microcontroller compiler and linker. This I do not have. The whole point of a language like HAL is to make programming possible without having to know the inner workings of the chip.

If I can live with the slower execution of the F767 and 12 bit A/D instead of 16 bits, I will carry on with this controller and wait until STM fixes the problems with the STM32HG743ZI version of the STM32CubeIDE.

It's too bad it won't work - it is otherwise a powerful chip.