Subject:
|
Rom sensor read routine
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Sun, 25 Apr 1999 13:51:08 GMT
|
Viewed:
|
1204 times
|
| |
| |
In writing some sensor code yesterday/today (it's 6 am), I passed over the
ROM sensor code at 14c0. The documentation has been put in the usual
place.
The rotation code is pretty simple: the expected state machine, with split
points between the four states of 1bf, 2bf, 3bf:
000 <= STATE0 < 1bf
1bf <= STATE1 < 2bf
2bf <= STATE2 < 3bf
3bf <= STATE3 < 3ff
One thing I noticed when writing sensor code is that the active sensors
(rotation, light) need to settle before you sample them. In other words,
when turning off the output to these sensors by setting a port 6 output
low, you need to wait a little while before starting the a/d conversion.
I found this code to be sufficient to allow the sensors to settle:
*(char *)0xffbb &= ~0x07; /* port 6 bits 0,1,2 low */
for (i = 0; i < 5; i++);
*(char *)0xffe8 |= 0x60; /* start a/d conversion */
In my case, since I scan all 4 a/d inputs at once, the one that really
matters is the first one, a/d input a, which corresponds to sensor 2.
Without the delay, I get raw 10-bit values for sensor 2 that are off by a
wildly varying 50-100 units compared to sensors 0 and 1. With the delay,
there are still slight differences between the three sensors, but the total
variation is a small 5 units or so. I did a comparison with the routines
in ROM, and they also show a 5 unit variation, so the delay makes
performance comparable with what is achieved by the ROM.
If you look at the ROM code, you'll see that the delay is effected by other
work - port 6 is dropped low at the start of a long routine, and the a/d
conversion is started much later, at the end of the routine.
With LegOS, it appears that the a/d inputs are scanned separately - which
is fine - but currently port 6 is dropped low immediately before the a/d
conversion is started. Somebody should fix this, I think the results now
probably vary a lot more than they need to, plus they are biased to larger
values and are therefore squeezed into a smaller range.
-Kekoa
|
|
Message has 1 Reply: | | Re: Rom sensor read routine
|
| Hi Kekoa, (...) I am fixing this right now. (...) The current legOS sensor read cycle is this (i=illuminate, c=A/D conversion) S1: iii iii iii ccc S2: ccc iii iii iii S3: iii ccc iii iii S4: iii iii ccc iii If you find your sensor 2 readings to be (...) (26 years ago, 2-May-99, to lugnet.robotics.rcx.legos)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|