2013-07-15 09:52 PM
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-tools2013-07-16 02:35 AM
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.
2013-07-16 04:13 AM
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...
2013-07-16 10:52 AM
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.
2013-07-17 01:24 AM
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...
}
}
2013-07-22 12:53 PM
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?2013-07-23 01:56 AM
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.2013-07-23 10:38 AM
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!2013-07-23 01:56 PM
Have you considered using TIM2 for this?
2013-07-24 01:40 AM
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.