cancel
Showing results for 
Search instead for 
Did you mean: 

Timer trigger timer - example?

oeliks
Senior

Hi! Im having trouble with setting timer2, when it overflows I want to add+1 to timer4 in slave mode =) to use timer2 as prescaler to timer4.

Can I ask for am example of this? Or some hints how to o this.

​Im trying to follow timer cookbook. Synchronization.

Cop​y&paste code?

I set TIM2:

Prescaler:0

Period:65535

Trigger output: update event

T​IM4:

Prescaler:0

Period:65535

Trigger input:TRG0

Then I start timer4, then timer2, t​ried hal_tim_start_it(&htim2); and hal_tim_base_start_it(&htim2);

Thank You :)​

1 ACCEPTED SOLUTION

Accepted Solutions

In the slave timer, you want to set its slave-mode controller to External clock mode 1, see description of TIMx_SMCR.SMS bitfield in the RM.

I don't use Cube/HAL, an example e.g. here. You can try it without writing any code, just by writing into the registers in the debugger.

JW

View solution in original post

5 REPLIES 5
KnarfB
Principal III

What MCU are you using? What libraries, HAL?

oeliks
Senior

Im using HA​L and stm32f103c8, Im setting channel 1 of tim2&4 as outut compare no output

In the slave timer, you want to set its slave-mode controller to External clock mode 1, see description of TIMx_SMCR.SMS bitfield in the RM.

I don't use Cube/HAL, an example e.g. here. You can try it without writing any code, just by writing into the registers in the debugger.

JW

berendi
Principal

HAL functions are rather poorly documented, you can waste a lot of time trying one function or another.

The timer cookbook contains some advanced examples, but I think you need a more basic example first.

Search for "Using one timer as prescaler for another timer" in the reference manual, there is a step-by-step description of what should go into which register, doing exactly what you want to do, but with another timer. Refer to the register descriptions later in the chapter to adjust it to your timers.

Another example in this thread.

oeliks
Senior

It works, changed in slave External clock mode 1 and trigger from trg0 to tr1 (dont know why it works), also both timers base_start(&htim), and not base_start_IT(&htim).

Thank You ALL !!​