cancel
Showing results for 
Search instead for 
Did you mean: 

PWM, interrupt and call-back

LVara.1
Associate II

Hello,

I am studyng (first time) PWM using a Nucleo_401RE, STMCubeIDE, and HAL drivers;

I write some example using interrupt TIM2 and its TIM2_CH1 and PA5 to control the green led LD2.

The counter count UP, in the TIM2_IRQHandler , for the moment , I do nothing.

The signal is correct, but I have some question about HAL_TIM_OC_Start_IT and HAL_TIM_PWM_Start_IT , the first is:

where read complete documents about this Hal functions?

The user manual UM1725 say:

HAL_TIM_PWM_Start_IT

Starts the PWM signal generation in interrupt mode. (Very interesting)

HAL_TIM_OC_Start_IT

Starts the TIM Output Compare signal generation in interrupt mode. (Ah! interesting)

Why I ask this?

I want use a call back due to the interrupt call;the STMCubeIDE in NVIC have only one kind of interrupt: TIM2 global interrupt

I SUPPOSE that some differernts call back are possible only in base of the type of ____start, but what?

The famous UM1725 say, for example:

HAL_TIM_PeriodElapsedCallback

Period elapsed callback in non blocking mode. (Very interesting ...)

In details:

I want have DIFFERENTS call back when counter reach CCR and when when counter reload from ARR (I SUPPOSE there are two different IRQ calls) ;

Or recognize the two moments.

I have tryed different combination of kind of ____start and kind of call back: No valid results.

Many thanks and excuse for my english, but after Brexit ...

Luciano

4 REPLIES 4

> I SUPPOSE there are two different IRQ calls

In most of the timers, no. TIM1 is the notable exception (still merging some/many of the interrupts, and adding interrupts from other timers, at times; and maybe partially TIM8. Read the interrupt chapter in Reference Manual (RM).

> Or recognize the two moments.

You normally distinguish them (or, better, react to any of them) by reading TIMx_SR in the ISR. Note that you have to clear it (Cube/HAL does this for you if you call its internal whatnot) and that requires *writing* zeros to particular TIMx_SR bits (i.e. not RMW!)

> The famous UM1725

Read the sources, Cube/HAL is open source.

Or, way better, ditch Cube entirely and go for adult programming. RM is your friend.

JW

berendi
Principal

HAL functions are rather poorly documented, I could never figure out how these HAL_TIM_ functions are supposed to work.

Using the register interface as documented in the reference manual works without much guesswork.

https://community.st.com/s/question/0D50X0000C8fKWFSQ2/stm32l4-step-by-step-procedure-for-timer-configuration

GPIO setup would of course be different for your board.

Many thanks. I search for sources , I don't know where...

And many thanks, really I'm not adult : only 47 year old ( in Hex obviously).

luciano

Many thanks. I try ...

Luciano