I have written a program that is positioning an onbject by driving a conveyor motor and reading the distance to the object from a laser sensor with a serial output.
It works, but the issue im having is that i cannot get it to run quite fast enough. Currently i am using the below code to read from the serial port until i encounter a CR (termination of lasers measurment).
while (temp != CR && timeout < 50) {
if (aascReadChar(Laser,&temp)) {
laserresult[count] = temp;
count++;
}
else {
timeout++;
}
}
I trigger the measurment and wait 200ms as this is the quickest the laser will ever respond. This allows some time for the display and control costatements to run. Ideally i would like to have an interrupt routine run every time something new was received on the serial instead of wasting time waiting for the result. I cannot just wait a fixed time because the sensor takes a different amount of time to send its result from 200ms to 1000ms.
Any suggestions? Whole Source is attached.