cancel
Showing results for 
Search instead for 
Did you mean: 

TIM16 PWM signal generation please help!!

Posted on January 24, 2018 at 19:23

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);
5 REPLIES 5
Posted on January 24, 2018 at 19:43

>>

LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_6, LL_GPIO_AF_14);

A range Pin 8 thru 15 probably NOT appropriate for Pin 6

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 24, 2018 at 19:50

Hi Clive

    I did this and still do not see the PWM signal.... 

     LL_GPIO_SetAFPin_0_7(GPIOA, LL_GPIO_PIN_6, LL_GPIO_AF_14);

Regards

Bala

Posted on January 24, 2018 at 20:10

Check strapping of SB16

http://www.st.com/content/ccc/resource/technical/document/user_manual/e3/0e/88/05/e8/74/43/a0/DM00231744.pdf/files/DM00231744.pdf/jcr:content/translations/en.DM00231744.pdf

 

Not going to replicate from incomplete code fragments.

Initialize TIM_TimeBaseStructure and TIM_OCInitStructure with ' = { 0 }; ' to ensure all fields are valid.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 24, 2018 at 21:09

Reading out and checking the relevant TIM and GPIO registers never can be a bad thing to do.

JW

Posted on January 31, 2018 at 15:04

I got the solution to the  issue that I did not see the PWM output on TIM16,,, The solution is to turn on AOE bit in the TIMx_BDTR register...