2013-06-03 08:01 AM
I have a timer configured to interface an encoder.
Basically what I want to do is to create a trigger event at every encoder pulse, which resets another free running timer's counter value to 0.What I have now, is that I configured the encoder timer as master, the other timer as slave. TIM_TRGOSource_OC4Ref is set as output trigger. But now I obviously have to set the Capture/Compare 4 register of the encoder timer manually right after the capture happens.The problem with this is, that at very fast encoder speed the CCR4 register has to be changed very often, resulting in a very high CPU usage.What I've come up with is to set the Auto Reload Register of the encoder timer to 1, to be able to use the TIM_TRGOSource_Update for event generation. The obvious flaw of this method is, that I would loose the direction information of the encoder rotation.If you are wondering why I would need to have a trigger at every encoder transition, then please see this paper: Section III. MIXED MODE FREQUENCY/PERIOD MEASUREMENTI also modified a picture from the paper for clarity on my method to implement the speed measurement:http://imageshack.us/photo/my-images/211/speedmeasurementalgorit.png/
If anyone has ideas, regarding the problem of the encoder transition triggering, or how to implement the mixed mode measurement, I am more than happy to hear them. #encoder2013-06-03 08:33 AM
Strikes me that you could use an input capture mode, use that to snap shot a higher frequency timebase, and then do a delta measurement of the CCRx register samples of successive CCx interrupts.
More crudely you could use an EXTI interrupt on the pin, and a counter via SysTick. Generally you wouldn't need to zero things, if you know the starting value and ending value the delta is cheap to compute.2013-06-03 09:54 AM
Thanks for the fast response, I'll consider this.
And BTW I forgot to mention the used uC, it is the STM32F373RC2013-06-04 09:23 AM
Thanks clive1 !
I did what you said, I've set up an EXTI interrupt for both encoder channel inputs.In the interrupt I just save the actual timer value. When the encoder speed measurement timer fires, I can subtract the time when the last encoder transition happened.Just what I needed.I always forget that you can set up an interrupt to a pin, even if it used as an alternate config pin. Pretty neat!