cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Discovery Counter

mattfox
Associate II
Posted on July 16, 2013 at 06:52

I'm working with a quadrature decoder that I set up on timer 8.  I'm having trouble because the counter on timer 8 only seems to count up to 16 bits.  I really need it to count up to 32 bits.  Is it possible to configure the counter to do this?

I tried doing this:

TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;

But it hasn't worked for me.  Any ideas?  Thanks in advance for the help!

#know-your-tools
21 REPLIES 21
Amel NASRI
ST Employee
Posted on July 16, 2013 at 11:35

TIM8 is a 16-bit auto-relaod counter.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

crt2
Associate II
Posted on July 16, 2013 at 13:13

advice is to increment integer every time the timer overflows. Also keep in mind that overflow can bite you in ass, so if you have quite constant requirement use something from 1000+ to lets say 60000, so that you have enough space on both sides to capture overflow...

mattfox
Associate II
Posted on July 16, 2013 at 19:52

Okay, I think I understand the issue a bit more.  I'm currently working on implementing a solution that would have memory of the number of times the counter under or overflowed.  Is there an interrupt that I can set for under or overflowing?  Will I be able to tell the difference between the two?  Thanks for the help. 

crt2
Associate II
Posted on July 17, 2013 at 10:24

You can count up or down, and interrupt is triggered by overflow or underflow. If you are counting down something then logical thing would be: global i=500 in

isr_handler{
if
(i>0) 
i--;
else
{
//this is what I want to do
//for example set that exact time needed after 500th overflow...
}
}

mattfox
Associate II
Posted on July 22, 2013 at 21:53

So I understand how I would handle it in an interrupt if I could generate that interrupt at underflow or overflow and I could differentiate between the two.  The problem that I'm having is finding an interrupt that will occur for both underflow and overflow and allow me to tell the difference.  I thought about having the RCR register be set at 1 and interrupt everytime that I get an event, but I still wouldn't be able to tell the difference between the overflow and underflow events (I'm worried that the counter on my motor encoder will move too fast such that it underflows and overflows in very quick succession, so I don't want to rely on the value to be able to tell which event just happened).

Does anyone have an idea about a good interrupt to use and.or a good way to differentiate between an overflow and an underflow event?

crt2
Associate II
Posted on July 23, 2013 at 10:56

I think you lost me with the motor and encoder pulses as they probably get into stream of pulses and you need a smart encoding which tells you on which side it rotates. It has nothing to do with timer over-under flow. That's why I dont think I understand the problem you are having or at least lets say you would not solve it with timer.

You can set 2 different interrupts - one for overflow and one for underflow, but again: depends on your implementation.

mattfox
Associate II
Posted on July 23, 2013 at 19:38

So I'm not particularly worried about the encoder logic itself, because i have TIM 8 configured so that it handles all of that.  The issue is that the encoder counter is located in TIM8->CNT which is a 16-bit counter.  I really want this to be a 32-bit counter because I don't want the resolution to be confined by 16 bits.

Do you know which interrupts I can set for over or underflow.  I can't seem to find any that would be able to tell this difference. I am worried about over and under flow of TIM 8's counter.

Thanks so much for the help!  

Posted on July 23, 2013 at 22:56

Have you considered using TIM2 for this?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
crt2
Associate II
Posted on July 24, 2013 at 10:40

Counter counts in one direction only and in that direction you get either overflow and underflow. If you think of swapping direction ''on fly'' you can put some kind of flag somewhere which will tell you if its counting up or down.