TIM16 PWM signal generation please help!!
Hi All
I am trying to get the TIM16 to work in output compare mode especially generate a PWM signal on channel 1. I am using the LL libraries of STM32L4xxx to do the job. I am using NUCLEO L432KC board and probing PA6. What i see is I get an ISR call every period of the PWM time and in the ISR I clear the flag using LL_TIM_ClearFlag_CC1(TIM16). The thing is I do not see the output on GPIO ping A6. Please help!!!
The settings of TIM16 and GPIO A pin 6 is as below:
/******************************/ /* Peripheral clocks enabling */ /******************************/ /* Enable the timer peripheral clock */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16); /*************************/ /* GPIO AF configuration */ /*************************/ /* Enable the peripheral clock of GPIOs */ LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); /* GPIO TIM2_CH3 configuration */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_6, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_6, LL_GPIO_AF_14); /***********************************************/ /* Configure the NVIC to handle TIM16 interrupt */ /***********************************************/ NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 0); NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); PrescalerValue= __LL_TIM_CALC_PSC(RCC_ClockFreq.SYSCLK_Frequency, 1000000); /* Compute the prescaler value */ LL_TIM_SetPrescaler(TIM16, __LL_TIM_CALC_PSC(RCC_ClockFreq.SYSCLK_Frequency, 1000000)); /* Set the auto-reload value to have an initial update event frequency of 10000 Hz */ InitialAutoreload = __LL_TIM_CALC_ARR(RCC_ClockFreq.SYSCLK_Frequency, LL_TIM_GetPrescaler(TIM16), 10000); /* Time base configuration */ TIM_TimeBaseStructure.Autoreload =InitialAutoreload; /* TIM16 is a 16bit timer */ TIM_TimeBaseStructure.Prescaler = PrescalerValue; TIM_TimeBaseStructure.ClockDivision = 0; TIM_TimeBaseStructure.CounterMode = LL_TIM_COUNTERMODE_UP; LL_TIM_DeInit(TIM16);LL_TIM_OC_Init(
TIM16,&TIM_TimeBaseStructure
); TIM_OCInitStructure.OCState=LL_TIM_OCSTATE_ENABLE; TIM_OCInitStructure.OCPolarity=LL_TIM_OCPOLARITY_HIGH; TIM_OCInitStructure.OCMode= LL_TIM_OCMODE_PWM1 ; TIM_OCInitStructure.CompareValue=((LL_TIM_GetAutoReload(TIM16)/2)); TIM_OC1Init(TIM16,&TIM_OCInitStructure); LL_TIM_EnableCounter(TIM16); /*Enable the interrupt for the CC1 chanel*/ LL_TIM_EnableIT_CC1(TIM16);