cancel
Showing results for 
Search instead for 
Did you mean: 

ADC capture triggered by tim STM32 discovery

thorin
Associate
Posted on April 07, 2014 at 16:42

Hey everyone! I am new to working with the STM32F429 discoveryboard and can't seem to find a solution for sampling with the ADC via the DMA at 160Khz (I am trying to sample a 40kHz wave). Does anyone have any ideas on what in my approach that is incorrect?

Code used:

/*♯♯-1- Configure the ADC peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

  AdcHandle.Instance          = ADCx;

  

  AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

  AdcHandle.Init.Resolution = ADC_RESOLUTION12b;

  AdcHandle.Init.ScanConvMode = DISABLE;

  AdcHandle.Init.ContinuousConvMode = ENABLE;

  AdcHandle.Init.DiscontinuousConvMode = DISABLE;

  AdcHandle.Init.NbrOfDiscConversion = 0;

  AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_CC1;

  AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  AdcHandle.Init.NbrOfConversion = 1;

  AdcHandle.Init.DMAContinuousRequests = ENABLE;

  AdcHandle.Init.EOCSelection = DISABLE;

/*♯♯-2- Configure ADC regular channel ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/  

  sConfig.Channel = ADCx_CHANNEL;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

  sConfig.Offset = 0;

  

  if(HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)

  {

    /* Channel Configuration Error */

    Error_Handler(); 

  }

/* Enable HSE Oscillator and activate PLL with HSE as source */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLM = 16;

  RCC_OscInitStruct.PLL.PLLN = 360;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

  RCC_OscInitStruct.PLL.PLLQ = 0;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

 

  HAL_PWREx_ActivateOverDrive();

  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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;  

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);

}

//TIMER INIT

void TIM3_Config(void)

{

  static TIM_HandleTypeDef  htim;

  TIM_MasterConfigTypeDef sMasterConfig;

  /*♯♯-1- Configure the TIM peripheral ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

  /* Time base configuration */

  htim.Instance = TIM3;

//  htim.Init.Period = 799;

 // htim.Init.Period = 374; //test f�r 180MHZ klockfrekvens

  htim.Init.Period = 74;

  htim.Init.Prescaler = 0;

  htim.Init.ClockDivision = 0;

  htim.Init.CounterMode = TIM_COUNTERMODE_UP;

  HAL_TIM_Base_Init(&htim);

  /* TIM6 TRGO selection */

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim, &sMasterConfig);

  /*♯♯-2- Enable TIM peripheral counter ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

  HAL_TIM_Base_Start(&htim);

}

#adc #tim #stm32
1 REPLY 1
Posted on April 07, 2014 at 17:00

Not much interest for the Cube library from me, the STM32F429I-DISCO has limited ADC channels, I have posted examples for it, but mostly for the F2/F4 platform.

I posted a 200 KHz example about a third down [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Help%20with%20simple%20ADC%20on%20STM32F4&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=3749]This Thread
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..