Let's Make Robots!

Picaxe Encoder wheel timing

I am using the code below to monitor 2 encoder wheels connected to (pin4 left motor QRD1114 & pin3 right motor QRD1114) on my latest 28x1 picaxe project . It works fine .

My question is :- how can i calculate how long the code takes to execute?


b5=pin4 b6=pin3                                      check the encoder pins
if b5 != b2 then inc b1 b2 = b5 endif        b1 is my incrementing encoder variable off left motor 
if b6 != b4 then inc b3 b4 = b6 endif        b3 is my incrementing encoder variable off right motor


(on the arduino there is a millis() command which can be used to give a rough guide to code execution times)

I ask this because if the encoder wheel is faster than the code (complete code loop) then i will be missing pulses, i dont want to miss my "pulses"

I started off by using setint (interrupt) command, however that led me up the garden path, so now i am stuck with monitoring the pins for any change of state.

EDIT:- The Video below is a taken with my highspeed camera (400 frames/sec) - you can see i have marked a black arrow on the wheel (opposite side has the encoder markings) . The black arrow stays pretty constant pointing at the motor pinion.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I dont have the full answer for you, because its almost 2.00AM and I am sleepy, but the word you are looking for is "timer" and the SETTIMER command. Of course: the usual picaxe limitations apply here. It will not work if you use the servo command (or the PWM command etc.etc)

After your suggestion i played around with the SETTIMER command however to limited avail.

I tried working with the timer register, but reading it was not so easy (i take it the debug has a heavy timeing payload if used in main code)


In the end i went practical........... "Car Time_ing Belt check style"  :-

My encoder has 12 segments/wheel rotation - so i rigged a bright LED to flash every 12th count - then i directed the LED at the encoder wheel as a type of Strobe light . This freezes the wheel in a flash of light (if you know what i mean) This way i can see if the encoder wheel is slipping or missing pulses.

I could then try differnt motor speed and see how reliable the code could pick up the encoder pulses.

From my findings i have to run my motors at a slower speed  :-( or else i will have to reduce my encoder markings)