2015-07-31 06:25 AM
Hello all,
I have configured the ADC to trigger based on Timer 6 update event every (1/48000) seconds. DMA is used to transfer the ADC conversion to memory. However, when I debug, I see the timer count being incremented, but I don't see any ADC conversion being made or anything in the memory location where it saves the ADC values through DMA. I have used ST's CubeMX to generate the initialization code.#include ''stm32f7xx_hal.h''
uint16_t ADC3ConvertedValue = 0;
uint16_t ADC_Value = 0;
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc3;
DMA_HandleTypeDef hdma_adc3;
TIM_HandleTypeDef htim6;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC3_Init(void);
static void MX_TIM6_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
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();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC3_Init();
MX_TIM6_Init();
HAL_TIM_Base_Start(&htim6);
HAL_ADC_Start_DMA(&hadc3, (uint32_t*)&ADC3ConvertedValue, 1);
while (1)
{
}
/* USER CODE END 3 */
}
Solved! Go to Solution.
2015-08-05 04:04 PM
for anyone with same problem, enabling the DAC clock via __HAL_RCC_DAC_CLK_ENABLE() command before starting the timer solved the issue.
2015-07-31 08:37 AM
You'd think the salient code would be one level below this...
2015-07-31 01:10 PM
What do you mean?
2015-08-04 06:11 AM
ok, I have narrowed down the problem a bit. The issue lies with the Timer 6 not triggering the ADC.
I guess I could use the timer interrupt to manually trigger the ADC conversion on overflow (1/48000s), but I would rather like to have it trigger automatically. Any suggestions?2015-08-05 07:00 AM
There is probably salient code missing for timer configuration. See the ADC Trigger Mode example that comes with the HAL library.
Cheers, Hal2015-08-05 08:58 AM
I had no idea there were more examples in the STM32756G_EVAL folder. I was previously only looking under the STM32746G-Discovery folder, and there is only one ADC_regular_conversion_DMA example. T
Anyways, I looked at the main.c file of the ADC_TriggerMode example and found the following differences: 1. Before starting the timer using the HAL_TIM_Base_Start(&htim) function, they have enabled the DAC clock using __HAL_RCC_DAC_CLK_ENABLE(); 2. Under the timer configuration, they had MasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE, whereas the initialization code that was generated by CUBEMX has MasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE
3. in addition, they have used Timer 2 instead of Timer 6, but that shouldn't really make a difference. I currently don't have access to the discovery board, but do you think these differences are what's causing timer 6 to not trigger? Thanks for the help.
2015-08-05 04:04 PM
for anyone with same problem, enabling the DAC clock via __HAL_RCC_DAC_CLK_ENABLE() command before starting the timer solved the issue.
2016-11-11 09:42 AM
I am having the same problem on the nucleo-f746zg board and with the __HAL_RCC_DAC_CLK_ENABLE() it at least seems to do something now. So thanks a lot for sharing!
Still I am wondering what the DAC-Clock has to do with a timer-triggered ADC?! Is this just some mistake in HAL or am I missing something? I know that the CubeMX tool only provides code for initialisation and you have to add your own code to make the controller do what you want, but shouldn't clock enabling be part of that initialization?