cancel
Showing results for 
Search instead for 
Did you mean: 

Choosing a timer and what mode for only counting time periods.

Posted on April 19, 2017 at 12:06

I'm using HAL_TIM library for my timer proposal. I would like to count 100 us. My idea is starting to run a MCU timer in free run mode and having and interruption every this timer period. I have read there are several timers in my st used (stm32L476), and every timer has 3 or 4 channels: pwm, output mode, input capture, compare, etc.. But I don't know which will be the best for my proposal. I guess I can discard PWM modes or input capture mode, cause I only want to be internally counting time being passed, I don't want to be outputing any signal or reading an input pin. 

Which is the channel or mode I must choose in order to have an interruption every 100us, 10us, or Xus? (of course I know I must handle the interruptions by sw but first I need to count period in the correct channel/mode)

  • input capture
  • output compare
  • pwm generation
  • one pulse mode output.

Any help will be appreciate. Thanks in advance.

#timer-channels #hal #stm32l4-timer #hal_tim
35 REPLIES 35
roseanne qiu
Associate II
Posted on June 25, 2018 at 23:16

Dear Dhenry and Elkin:

Thanks for both help.

I did tries Dhenry's method, It does not work

:(

I just got Elkin answer, My channels pulse is really less than period, 

Inside the interrupt routine, I also use signal by gp pins. still  could not work any interrupt signal

but I found my channel config is 'channel compare output', your is 'channel compare no output'.

I do not know what's different. I am to try your 'channel compare no output ' to see whether there are different.

from codes, I could not see the difference.

brb

thanks

rosea

roseanne qiu
Associate II
Posted on June 25, 2018 at 23:45

Dear Elkin:

Thanks for your great help. 

by reading your setting, I found my problem. it works now.

yes, I need to check both timer and channel in callback interrupt routine

thanks again for all of you. 

this is great community .

have a great holiday to all of you.

thanks

roseanne

Posted on June 25, 2018 at 22:27

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6ZK&d=%2Fa%2F0X0000000bqt%2FmaV4RCHtvnPluey7mLa6SVyL8sWVoiOhgiMvTzPv9mo&asPdf=false
Posted on June 26, 2018 at 00:28

'

there is just one callback function for all timer'

Any software framework that imposes that kind of restrictions on it's users is fatally flawed.

Posted on June 26, 2018 at 01:21

'

which allows to trigger an interruption in different 'periods','

I don't think the code does what you think it does: producing different periods for individual channels. Instead, all of them will interrupt at the same period, but at different times.

take Ch 1 for example, its first interrupt arrives at tick 0xa001. then the counter is reset at 0xc004; and the Ch 1 interrupts at 0xa001 (which is really 0xc004 + 0xa001 since the very beginning). this leads to the ch1 to interrupt every (0xc004 + 0xa001) - 0xa001 = 0xc004 ticks.

the same holds for other channels.

the key here is not to reset the counter and let it overflows; instead, in the ISR increment the match points by the desired periods for individual channels.

roseanne qiu
Associate II
Posted on July 12, 2018 at 18:04

Dear Sir/Madam:

I would like to continue the questions.

with all of your help, I could make timer2 and timer3 channels interrupt enable. they work good.

but when I try to turn on timer4 and timer5 interrupts for STM32F401RETx LQFP64,

both of them do not work, and make system stuck(watchdog set as 4 seconds)

and I checked the interrupt routine for both timer4 and timer5 , none of them are triggered.

I am wondering why this happen?

timer4 and timer5 have the same configure as timer2 and timer3

any clue ?

thanks

rose