Dear all,
Finally got some time for my little line follower again. I am now trying to optimise the code and one thing that was supposed to be easy is to rewrite the code so, that it would find the edges on the fly, without pixel data in memory first and retrieving for analysis later.
I have written the following piece of code which finds the leftedge correctly, but fails to find the rightedge. I cannot find a fault with the code, I think it should do what I intended it to, so I'm suspecting doing this between the CLK pulses varies the timing between the pulses too much and sensor just responds with garbage. Can you take a look and see if I'm missing something obvious? Suggestions for making this quicker are, of course, very welcome, too .
Thank you for your time,
Edmunds
Finally got some time for my little line follower again. I am now trying to optimise the code and one thing that was supposed to be easy is to rewrite the code so, that it would find the edges on the fly, without pixel data in memory first and retrieving for analysis later.
I have written the following piece of code which finds the leftedge correctly, but fails to find the rightedge. I cannot find a fault with the code, I think it should do what I intended it to, so I'm suspecting doing this between the CLK pulses varies the timing between the pulses too much and sensor just responds with garbage. Can you take a look and see if I'm missing something obvious? Suggestions for making this quicker are, of course, very welcome, too .
Code:
Collect_data:
adcsetup = 0
'/*Used to be a procedure call for read_data, now replaced with code for speed BEGIN
high SI : pulsout CLK, 10 : low SI 'Pulse SI to end the scan/start the next scan
pwmout CLK, 1, 4 'Clock out some fast pulses (8MHz @ 64MHz clock speed
pauseus Tint 'Allow for sufficient integration time
pwmout CLK, OFF 'Stop the clock
high SI : pulsout CLK, 10 : low SI 'Pulse SI to end the scan/start the next scan
'/*Used to be a procedure call for read_data, now replaced with code for speed END
leftedge = 0 : rightedge = 0 'Set both edges to zero
for counter = 0 to 127 'Read 128 pixels ...
dat0 = pinAO 'Set dat0 the state of the pin - 1 for white, 0 for dark
pulsout CLK, 10 'Pulse the clock to go to next pixel
if leftedge = 0 then 'In case line has not been found yet, look for set pixels for white
if dat0 = 1 then '... if the previous pixel is seeing the line (=1) ...
dat0 = pinAO '... set dat0 the state of the pin again ...
if dat0 = 1 then '... and check the new, neighbouring pixel ...
leftedge = counter '... in case two consecutive pixels are set, consider the left edge of the line
endif
endif
else 'If the left edge of the line is known, look for the right edge (set to clear transition) ...
if dat0 = 0 then '... do nothing about all the set pixels after finding leftegde, but stop for clear ...
dat0 = pinAO '... set dat0 the state of the pin again ...
if dat0 = 0 then '... and check the new, neighbouring pixel ...
rightedge = counter '... in case two consecutive pixels are clear, consider the right edge of the line
endif
endif
endif
; put counter, dat0 'Store the value in scratch pad as one byte per pixel (to be changed to bits later)
next counter '... continue until done with all pixels
return
Edmunds
Last edited: