Skip to main content
Eugenia Suarez
Associate III
April 19, 2017
Question

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

  • April 19, 2017
  • 35 replies
  • 8976 views
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
This topic has been closed for replies.

35 replies

roseanne qiu
Associate III
June 25, 2018
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 III
June 25, 2018
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

roseanne qiu
Associate III
July 12, 2018
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