Skip to main content
MM..1
Super User
December 7, 2021
Solved

Count edge with TIM14 channel 1 ?

I use counting on TIM15 and now need change to 14 , but seems here external pulses counting dont work. FYI STM32F030

Is any setup for 14 possible?

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
December 7, 2021

TIM14 does not have the "slave-mode controller" i.e. there's no external clock possible, it's a very much stripped down basic timer.

Can't you use something else? Which 'F030 (different packages are different chips)? Which pin?

JW

13 replies

moatjon
Associate II
December 7, 2021

Hey MM,

Can you give us some more information? Are you trying to increment a counter based on an external pulse? What chip are you using?

Kind regards,

moatjon

MM..1
MM..1Author
Super User
December 7, 2021

External pulses is high speed need hw counting., this works for me on TIM15

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15,ENABLE);
	
 TIM_Initstruct.TIM_Channel = TIM_Channel_2;
 TIM_Initstruct.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
 TIM_Initstruct.TIM_ICSelection = TIM_ICSelection_DirectTI;
 TIM_Initstruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;
 TIM_Initstruct.TIM_ICFilter = 0x00;
	TIM_ICInit(TIM15,&TIM_Initstruct);
	
	TIM_TIxExternalClockConfig(TIM15,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_BothEdge,0);
	
	TIM_Cmd(TIM15,ENABLE);
	TIM_SetCounter(TIM15,1); //workaround
	lastTIM15=TIM_GetCapture2(TIM15);

moatjon
Associate II
December 7, 2021

Are you using CubeIDE / CubeMX to generate your code? If so, can you share the .ioc file or show the TIM15 configuration? Is TIM14 channel 1 connected to the relevant pin?

MM..1
MM..1Author
Super User
December 7, 2021

??? no no yes

waclawek.jan
waclawek.janBest answer
Super User
December 7, 2021

TIM14 does not have the "slave-mode controller" i.e. there's no external clock possible, it's a very much stripped down basic timer.

Can't you use something else? Which 'F030 (different packages are different chips)? Which pin?

JW

MM..1
MM..1Author
Super User
December 7, 2021

Yes i see reference TIM14 is ... , and yes if dont exist way i rearange PCB , but first ask is any possible solution to count pulses on PA4 pin.

I try count in exti but pulses is lost sometimes.

moatjon
Associate II
December 7, 2021

You have to give some more information. What setup have you tried for TIM14? Does it not work if you replace the TIM15 instances with TIM14? When you say "external pulses counting dont work" does that mean that the counter stays at 0?

waclawek.jan
Super User
December 7, 2021

I don't see any possible trick for PA4, sorry.

Maybe there's some room for improvement for the EXTI (aggressive rewrite in asm, maybe using registers snatched from the compiler if using gcc).

The timer input capture interrupt may provide the same service as EXTI. If your usage case allows it, you could use the input capture prescaler to reduce the interrupt rate thus possibly eliminate interrupt loss, at the cost of count granularity.

JW

MM..1
MM..1Author
Super User
December 7, 2021

Thanks Jan,

any interrupt seems here is slow because is delayed with other or systicks .

Maybe i can change source signal to wide coded, then TIM14 can measure width by CC hw, have you any example howto setup TIM14 input capture to measure one pulse width , optimaly one edge reset TIM and second store CC1

waclawek.jan
Super User
December 7, 2021

> any interrupt seems here is slow because is delayed with other or systicks .

Couldn't you assign highest "group" priority to the EXTI (or TIM14, if that would be used) interrupt?

> optimaly one edge reset TIM and second store CC1

It's again the slave-mode controller (which is not there) which would be used to reset counter in full-fledged timers.

Here, as there's only one channel, it would need to be set to both edges, and then you would need to be able to read out the captured value for one edge fast enough so that the other edge would not overwrite it.

JW

MM..1
MM..1Author
Super User
December 7, 2021

Can i store two or more CC values with DMA here ?

MM..1
MM..1Author
Super User
December 7, 2021

Dont DMA not exist here.