cancel
Showing results for 
Search instead for 
Did you mean: 

ADC MULTI CHANNEL DMA isssue

kkhli.1
Associate III

I' m using ADC2(with 4 channel ) and ADC3 (with 2 CHANNEL) i need them to measur current from 6 sensor ACS712 the process was fine with DMA  and works pretty good, but the problem  is with the while loop.  the while loop never runs. i found some tutorial said that  When the ADC channel frequency is high, the DMA interrupts gets triggered very often and the control always remains in the callback function, and the while loop remains inactive forever.i'm using STM32F746ZG , ADCCLOCK (36 MHZ)  the sampling time for all channel is set to 480 ? please any advice 

 

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "dma.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "interruption.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#define frequencyM1     1000/(periodMotor1)    // FREQUENCE DU L ENCODEUR 1
#define frequencyM2     1000/(periodMotor2)    // FREQUENCE DU L ENCODEUR 2
#define frequencyM3     1000/(periodMotor3)    // FREQUENCE DU L ENCODEUR 3
#define frequencyM4     1000/(periodMotor4)    // FREQUENCE DU L ENCODEUR 4
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
float speedMotor1=0;
float speedMotor2=0;
float speedMotor3=0;
float speedMotor4=0;

uint16_t periodMotor1=0;
uint16_t periodMotor2=0;
uint16_t periodMotor3=0;
uint16_t periodMotor4=0;

volatile float Is_First_Captured1=0;// VARIABLE POUR TESTER SILE FRONT MONTANT DU L ENCODEUR 1 EST DETECTE
volatile float Is_First_Captured2=0;// VARIABLE POUR TESTER SILE FRONT MONTANT DU L ENCODEUR 2 EST DETECTE
volatile float Is_First_Captured3=0;// VARIABLE POUR TESTER SILE FRONT MONTANT DU L ENCODEUR 3 EST DETECTE
volatile float Is_First_Captured4=0;// VARIABLE POUR TESTER SILE FRONT MONTANT DU L ENCODEUR 4 EST DETECTE
volatile int IC1_Val1=0;        //VARIABLE POUR STOCKER LA VALEUR DU  FRONT MONTANT DU L ENCODEUR 1
volatile int IC2_Val1=0;        //VARIABLE POUR STOCKER LA VALEUR DU  FRONT MONTANT DU L ENCODEUR 2
volatile int IC3_Val1=0;        //VARIABLE POUR STOCKER LA VALEUR DU  FRONT MONTANT DU L ENCODEUR 3
volatile int IC4_Val1=0;        //VARIABLE POUR STOCKER LA VALEUR DU  FRONT MONTANT DU L ENCODEUR 4
 volatile int CountMR1=0; // NOMBRE D IMPULSION ENCODEUR1
 volatile int CountMR2=0; // NOMBRE D IMPULSION ENCODEUR2
 volatile int CountMR3=0; // NOMBRE D IMPULSION ENCODEUR3
 volatile int CountMR4=0; // NOMBRE D IMPULSION ENCODEUR4
 volatile float CourantR1;
 volatile float CourantR2;
 volatile float CourantR3;
 volatile float CourantR4;
 volatile float CourantDES;
uint16_t buffer2[4];
uint16_t buffer3[2];
int sum=0;
float PWM_MEULE;
int i=0;
uint8_t senddata[4] = {0x66, 0x42, 0x00, 0xA8};//TX UART avec bldc
uint8_t trame[10];//RX UART from bldc
uint8_t CUR_MTMeule;
float moyenne = 0;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{

	 if (hadc->Instance == ADC2)
	 	  {

	        CourantR1=((buffer2[0]*3.3f/ 4095.0f)-2.5f)/0.066f;
	        CourantR2=((buffer2[1]*3.3f/ 4095.0f)-2.5f)/0.066f;
			CourantR3=((buffer2[2]*3.3f/ 4095.0f)-2.5f)/0.066f;
			CourantDES=((buffer2[3]*3.3f/ 4095.0f)-2.5f)/0.066f;

	 	  }

	   if (hadc->Instance == ADC3)
		 	  {

			          CourantR4=((buffer3[0]*3.3f/ 4095.0f)-2.5f)/0.066f;
			          PWM_MEULE=buffer3[1];


		 	  }


}


void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  {

	HAL_UART_Receive_IT(&huart1,trame, 10);//sizeof(buffer));
	CUR_MTMeule= trame[9]/10.0;

  }

void sendParameter()
  {

     HAL_UART_Transmit_IT(&huart1, senddata, 4);
     HAL_Delay(100);

  }





/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
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_DMA_Init();
  MX_ADC2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();
  MX_UART4_Init();
  MX_ADC3_Init();
  MX_TIM12_Init();
  /* USER CODE BEGIN 2 */
  	
  	//moteur4
  	HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_4);//PE14



  	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);//MT1
  	


	HAL_ADC_Start_DMA(&hadc2,(uint32_t *)buffer2,  4);//
	HAL_ADC_Start_DMA(&hadc3,(uint32_t *)buffer3, 2);// 

	HAL_UART_Receive_IT(&huart1,trame, 10);//sizeof(buffer));

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */


sum=sum+1;
	  }



  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 4;
  RCC_OscInitStruct.PLL.PLLN = 216;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 3;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Activate the Over-Drive mode
  */
  if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

 

, you find attached my project 

1 REPLY 1
TDK
Guru

Debug your code, let it run, then hit pause and examine where the code is at. If you do this many times and it always ends up in an interrupt, you are triggering interrupts too quickly.

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