2020-01-21 10:39 PM
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.
Copy&paste code?
I set TIM2:
Prescaler:0
Period:65535
Trigger output: update event
TIM4:
Prescaler:0
Period:65535
Trigger input:TRG0
Then I start timer4, then timer2, tried hal_tim_start_it(&htim2); and hal_tim_base_start_it(&htim2);
Thank You :)
Solved! Go to Solution.
2020-01-21 11:53 PM
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
2020-01-21 10:48 PM
What MCU are you using? What libraries, HAL?
2020-01-21 10:52 PM
Im using HAL and stm32f103c8, Im setting channel 1 of tim2&4 as outut compare no output
2020-01-21 11:53 PM
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
2020-01-22 02:00 AM
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.
2020-01-22 11:52 AM
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 !!