2
\$\begingroup\$

I am trying to configuring one of the timer inputs on a STM32 to behave as a frequency counter for an external signal. The STM32 datasheet describes a "input capture mode" in section 17.3.6 (page 342)

My understanding of this mode is that whenever an input comes in on the selected TIMx_CHx input, the processor captures the value of a free-running internal counter. Frequency can then be calculated using the counter value and the frequency of the internal counter.

I am trying to enable this in CubeMX and am having difficulties correlating the datasheet explanation to the settings in CubeMX. This is what I currently have configured. Is is this correct?

Also, can I run multiple independent inputs into separate channels on the same timer to capture timing simultaneously?

enter image description here

asked Jun 4, 2019 at 14:53
\$\endgroup\$
1
  • \$\begingroup\$ You've found the detailed description of what to do, what value goes to which register bit. There are even code examples there. Why are you struggling with CubeMX then? \$\endgroup\$ Commented Jun 4, 2019 at 15:08

1 Answer 1

2
\$\begingroup\$

Frequency counters can get complicated quick depending on the bandwidth you want and the clock speed of the internal clock as well as the size of the registers holding the clock ticks and the input ticks.

I mean it looks like it'll work but you should make sure that (1) the clock counter and the frequency counter are refreshed at the end of the sample (2) that neither will overflow during the sample (3) that the setup will give you the resolution you want and (4) that the MCU will make adjustments if the bandwidth is large enough where it'll overflow some of the time and/or dip very low. The first of which would cause incorrect results and the second of which would drastically reduce the accuracy at low Hz.

answered Jun 5, 2019 at 3:22
\$\endgroup\$
4
  • \$\begingroup\$ Thanks for the insight. I'm measuring an engine RPM in the ranges of 1k to 6k Hz \$\endgroup\$ Commented Jun 5, 2019 at 14:56
  • \$\begingroup\$ @user8908459 How are you measuring the rpm? Reluctance sensor? \$\endgroup\$ Commented Jun 5, 2019 at 14:59
  • \$\begingroup\$ Yes using a MAX9926 \$\endgroup\$ Commented Jun 5, 2019 at 18:04
  • \$\begingroup\$ In that case keep in mind that you're reading the frequency of tooth passes on the gear, not the frequency of the gear. You'll need to divide by the number of teeth, that means your ticks on the input capture will be significantly higher than 6k. If you have a 16 bit timer register you should be good though unless theres a crazy number of teeth on the gear. \$\endgroup\$ Commented Jun 5, 2019 at 18:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.