cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Pulse Counter

tecnico23
Associate II
Posted on March 28, 2012 at 17:29

I wonder if someone could help me.

I want to count the number of pulses occured each ''x'' time.

I could use a timer configured to generate an interrupt each ''x'' time. And the interrupt handler of this timer should read the counter value, and reset the counter. But, if the processor is executing a non-preemptive task while an interrupt will occured, the processor will execute the non-preemptive task until the end, and the interrupt handler will wait until the non-preemptive task will be completly executed. But meanwhile, some pulses can occured and will be counted.

So, I would ask if I could avoid this situation with a timer in Input capture mode. Is it possible to configure a timer in Input capture mode, using as Active input an internal periodical timer, instead of an input pin channel, and using the input pin as counter clock, instead of internal clock?

I mean, I would like to have an internal timer that generates the capture event cyclically, meanwhile an external pin clocks the counter.

After each capture I would use the DMA to store the captured value to a global variable.

If it is possible, could someone tell me how I could make it working? (procedure, configuration, registers to modify)

I would also o ask if it is possible to cascade a timer in Input Capture mode. Because, the external signal has a 1Mhz max frequency. If I will generate capture events only each second, the capture counter will overflow before one second.

Thank you very much,

Best regards,

A. Paiva

#stm32-pulse-counter
19 REPLIES 19
emalund
Associate III
Posted on March 29, 2012 at 19:05

I'm developping a controller for general applications in my company. I'm developping only the low layers,

 

I would known if there is another solution, to make this, without losing data. If there is, why should I use not accurate data? If there isn't then I must use this solution.

 

so, here is the problem

you want to develop something withoout knowing

a) if a RTOS is involved

b) if an accurate reading for time x is enough even if a few pulses are lost between slots

c) if a highest level interrupt can be allowed more than minimum cycles

there is no ONE solution regardless of everything else

Erik

tecnico23
Associate II
Posted on March 29, 2012 at 19:32

You have right.

And that is the reason why I want to know the other solutions! I want to gather as much information as I can on this step, to subsequently know which of the solutions I will apply, when I will known the process to control. At this step, I will understand how the device works, how to configure it, and find all the possibilities I have, to subsequently take the best.

Best regards,

A. Paiva

Posted on March 29, 2012 at 19:44

I think one of the problems here is that 16-bit general purpose timers are ill-suited to applications with MHz clocks, and indeterminate interrupt latency.

One would typically use specialized hardware (CPLD/FPGA) with 32-bit counter/timers, capable of latching counts at hard sample points. ie where the performance is explicitly implemented in the hardware, by design.

Now you might be able to fashion the general purpose timers to your own purposes, but it will require that you do A LOT of reading and analysis of the timer models and connectivity, and A LOT of experimentation with the hardware. I don't think you can escape doing you own due diligence here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tecnico23
Associate II
Posted on March 29, 2012 at 20:15

Thanks both of you.

And I'm sorry if I'm much currious. I'm starting right now with this devices, and maybe it is more complex then I think. I'm in a starting level.

I've written here because I think that this kind of forum is used to share experiences that aren't written in reference manuals, or other datasheets, or firmware examples. It's also a challenge, make something working in a different manner, as the traditional form. And this makes things evaluate. Am I wrong?

Clive, you have right that a FPGA would be able to make this over hardware.

But ok. Forget my application. Can someone tell me for what is, CC1s configured as ''11'', used?

Thank you,

A. Paiva

emalund
Associate III
Posted on March 29, 2012 at 20:36

maybe it is more complex then I think.

 

why do you think RM0008 is 10MB?

 

<i>Can someone tell me for what is, CC1s configured as ''11'', used?</i>

you need to be more explicit: register name and bin/oct/dec/hex, RM0008 chapter and verse would be good too

Erik

emalund
Associate III
Posted on March 29, 2012 at 20:39

you need to be more explicit:

 

also STM32 WHAT, there are differences between the STM32 families

Posted on March 29, 2012 at 20:49

Am I wrong?

Probably not, but the forums are generally full of people who really don't know what they are doing, or how to ask/pose detailed questions. ie the blind leading the blind. I'm not sure how much out-of-the-box thinking you're going to get, but I do understand what you're looking for. That's not to say there aren't some smart people here, but they are in the minority.

There are some timer example that work well, and can be clearly illustrated. However the timers are very complex, and lack a lot of examples and documentation, including HW models. Personally I wish ST would provide a far more comprehensive set of examples. Perhaps even a wizard tool where you can chain/configure timers, and supply input stimulus, and experiment with all the modes.

I also find the 16-bit model to be too limiting, and the chaining to add to many atomic access issues. They are probably fine for people dealing with a few dozen KHz.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tecnico23
Associate II
Posted on March 29, 2012 at 21:37

Thank you Clive!

''

but the forums are generally full of people who really don't know what they are doing

''

This is because much of this people don't know how to use this tool called ''forum''. It could be a powerfull tool, if people who has questions, or curriosity post questions, and people who has lot of experience, or very smart people, share knowlege.

''

There are some timer example that work well, and can be clearly illustrated. However the timers are very complex, and lack a lot of examples and documentation, including HW models

''

 

 

Yes, you have right. You have some families, but the examples are always the same, and the datasheet explain always the simple examples. Why did someone make so powerfull devices, but then explain only the simple features? (The features that a simple uC also can do)

If a device has other features, registers, and configurations, in my mind, this should be the main contents focused on documentation, and also on examples.

Thank you very much.

Best regards,

A.Paiva

tecnico23
Associate II
Posted on March 29, 2012 at 21:51

Hi Erik,

I told you before. Reference manual RM0090, September 2011, DOC ID 018909, Page 401 (for example).

I posted before that I'm refering to

TIMx_CCMR1 register. And I would to know in which kind of application, the CC1S bits is configured as ''11'' (binary).

See attached file.

Best regards,

A.Paiva

________________

Attachments :

Capture_compare_channel.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtWr&d=%2Fa%2F0X0000000aRK%2F0bwOTP7pyGyFW8S9xS0go9ggAFWl66.QqXTPtCzrPl8&asPdf=false
emalund
Associate III
Posted on March 30, 2012 at 15:41

well, I did not ask ''which manual?'' I asked ''which chip?''

Erik