Settimer count, problem or not a problem

edmunds

Senior Member
Dear all,

I have been toying with settimer count for my little robot car. All in all, I have mechanics/optics and software sorted and I can reliably count rotations of the main motor with Sharp GP2S60 connected to C.0 pin. I have tried three types of segmented black and white discs - one black-white-black transition, two transitions and three transitions just to see how much resolution is realistically achievable with my setup. All three work well, however, each rotation is ~0.9mm motion of the car forward or backward and I have a hard time thinking I would ever need more resolution than that. The period between low-high edges never go shorter than 2ms and the slowest the motor is capable of is about 50ms.

Then, out of curiosity, I googled the forum for other solutions using settimer count and found a lot of, hmm, controversy about missing pulses seemingly due to the chip being busy handling interrupt for timer variable overflow. Two such threads linked to below.

http://www.picaxeforum.co.uk/archive/index.php/t-28157.html
http://www.picaxeforum.co.uk/archive/index.php/t-26376.html

While I don't think I should be particularly concerned because of my longish pulses (in micro controller terms), if the problem persists, I might be better off selecting three pulses per rotation and loose one of them and one third of a rotation rather than loose a full rotation if I select to use a single pulse per rotation (?).

Is the problem still there or has there been a solution found? Would I be better off with more pulses per rotation? I.e. the problem has to do with missing a single pulse or not registering any pulses for x milliseconds and thus missing any pulses incoming during x?


Thank you for your input,

Edmunds
 

hippy

Technical Support
Staff member
The issue described seems to be that the 'timer' variable misses the first pulse then increments by two on every pulse after that.

The problem would seem to be if there are no pulses when you get to first checking the timer value. A zero may indicate none or one pulse. If there have been any pulse it's easy enough to adjust for including the first ever not-counted pulse and timer being twice as large as it should be.

For what you want to do it's probably better to use a HINTx pin, interrupt, and count those transitions.
 

edmunds

Senior Member
For what you want to do it's probably better to use a HINTx pin, interrupt, and count those transitions.
Yes, I was thinking the same by the end of it as I likely want to 'process' every pulse anyway. Thank you, @hippy.

Edmunds
 
Top