cancel
Showing results for 
Search instead for 
Did you mean: 

How to toggle GPIO using the "PWM Generation No Output" Timer mode ?

ARaj.4
Associate II

I have a use case where I need to toggle a GPIO based on a PWM waveform. Since the GPIO chosen doesnt fall in the PWM timer pins, I have to toggle the GPIO in some other way. I came across the timer mode "PWM Generation No Output" mode. I am thinking of generating the desired PWM using this timer mode and then toggling the GPIO on PWM interrupts. I have tried using the "HAL_TIM_PWM_PulseFinishedCallback" and "HAL_TIM_PWM_PeriodElapsedCallback", but am unable to produce the desired result.

Could you tell me which interrupts to be used to get the PWM going high and low based on the duty cycle and period set in the timer ? Any sample code would be great :D

2 REPLIES 2
KnarfB
Principal III

You need

HAL_TIM_PWM_PulseFinishedCallback and

HAL_TIM_PeriodElapsedCallback

it's a bit tricky with HAL, because "pulse finished" is for one particular timer channel, but "period elapsed" is for the basic timer. So you have to init both irq handlers correctly in the .ioc config and in the code:

HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);

hth

KnarfB

Mhida.1
Associate

Hi Raj,

how about your problem, solved? please share to us. currently i want to drive the non pin timer as clock synchronize with other GPIO using DMA to drive hub75 led matrix.

thanks

Emha