2016-08-02 01:58 AM
Hello,
I use a nucleo stm32f401RC Evaluation Board for the regulation of a boost converter and I need to generate the interruption on the ON half-signal of PWM and I need also synchronize the conversion of 3 channel of the adc using DMA with this interruption, to do this I set the timer 3 on the way up / down and I activated the global interruption of this timer.My first problem is that the interrupt generated in the overflow and underflow of the timer, I want an interrupt only on the overflow.Second problem, I generate a event output of timer 3 for connecting it with the input trigger of the DMA and I got the same problem, the conversion is done on the overflow and underflow.int main(void){ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_TIM4_Init(); HAL_TIM_Base_Start_IT(&htim3); HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1); TIM3->CCR1=0; HAL_TIM_PWM_Start(&htim13,TIM_CHANNEL_2); TIM3->CCR2=0;/ while (1) { }}/* TIM3 init function */void MX_TIM3_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_SlaveConfigTypeDef sSlaveConfig; TIM_MasterConfigTypeDef sMasterConfig; TIM_OC_InitTypeDef sConfigOC; htim3.Instance = TIM3; htim3.Init.Prescaler = 0; htim3.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1; htim3.Init.Period = 10000; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&htim3); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig); HAL_TIM_PWM_Init(&htim3); sSlaveConfig.SlaveMode = TIM_SLAVEMODE_GATED; sSlaveConfig.InputTrigger = TIM_TS_ITR0; HAL_TIM_SlaveConfigSynchronization(&htim3, &sSlaveConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1); HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2); HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3); HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4);}/* ADC1 init function */void MX_ADC1_Init(void){ ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc1.Init.Resolution = ADC_RESOLUTION12b; hadc1.Init.ScanConvMode = ENABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_FALLING; hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 4; hadc1.Init.DMAContinuousRequests = ENABLE; hadc1.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc1); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 2; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_3; sConfig.Rank = 3; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = 4; HAL_ADC_ConfigChannel(&hadc1, &sConfig);}void TIM3_IRQHandler(void){ /* USER CODE BEGIN TIM3_IRQn 0 */ /* USER CODE END TIM3_IRQn 0 */ HAL_TIM_IRQHandler(&htim3); /* USER CODE BEGIN TIM3_IRQn 1 */ HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_8); TIM4->CCR1=5000;//duty_reg; /* USER CODE END TIM3_IRQn 1 */}in attachement a screenshot of the PWM and GPIO togled in the IRQ handlerAny help would be much appreciated!Many thanks,2016-08-31 07:06 AM
Hi bou.abdel
I suggest you refer to the (General-purpose timer cookbook) and its associated firmware (). It contains some examples that may be helpful for you, mainly the ones using DMA.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.