|
Re: Ultrasonic sensors on digital ports 3-6 problems
Hmmm... it is a little hard to follow. It is possible to miss an transition because you don't check each bit every time you enter Ultrasonic_Interrupt_Routine but this is not likely to happen all that often if you are accessing one sensor at a time. This is the only thing I can see that is wrong for sure.
"I switched the if and else around and instead of getting 35 and 25 I get a much higher number." The much higher number is measuring the time between pulses I reckon, that makes sense.
Do you have enough dynamic range (in the values of timer3) to do the measurement properly? What is the max sized pulse you expect to see (looks like timer3 will only give you 52.4ms) ? What is the minimum (800ns is the min for timer3) ? In what units in timer3 counting (800ns I assume)? Are you possibly calling GetDistance before the measurement is finished?
return ReturnValue * .34029;
phasetest2++;
The second line will never execute of course. And floating point on this processor is verrrrrrry slow.
//disable ports 3-6 interrupts
INTCONbits.RBIE = 1;
I still don't get the purpose of this. If GetDistance is called with an out of range sensor number, return an error code or something.
Lastly, are you doing a controlled test? Are you doing the test with the same shaped object the same distance from you every time?
I think I'd simplify this setup. You could let timer 3 run free all the time, increment a number in the rollover ISR and end up with a 32-bit timestamp (rollover count << 16 + TMR3H << 8 | TMR3L). Then you measure the pulses on all 4 channels all of the time w/o regard to when they were triggered. You might even Ping them regularly in some particular order. Do that all the time and have a global flag that you check when you need to see if anything is close to your robot. This would reduce the interaction between the ISR and your main code. Make sense?
HTH
|