3. D/A conversion

It's a pitty that you may only interface RCX inputs in an analog way. Deadly for digital devices. But here's the new idea. The PIC should measure the time-delay between the impact of the IR and ultrasonic pulses. The value should be one byte large! The resistor-net combined with the opto-couplers is the easiest way (not the best) to get a D to A conversion AND the desired galvanic separation of the RCX input from the rest of the device. We first tried an eight-resistor-net, but the result was not convincing, because of the difficulty to distinguish the small raw-values from each other. The program-trick here is to send first the low-byte then the high-byte of the time-delay.

• At 4MHz the PIC's internal TMR0-timer is incremented every microsecond (at 1:1 prescale)

• at a prescale of 1:128 it is incremented only every 0.128 millisecond

• x = c * t, where c is the sound-velocity =343 m/sec

• so we get a 4.39cm resolution

• a TMR0-overflow occurs after 0.128 * 256 = 32.77 msec, which corresponds to a sound-distance x = 343 * 0.03277 = 11.24 m, which is above our maximum distance of a 5 x 5m room: sqrt(2)*5=7m

Here once again the value list:

RAW = 1023 * R / (10000 + R)

 8,2k 15k 33k 56k B3 B2 B1 B0 R RAW 0 0 0 0 - 1023 0 0 0 1 56k 868 0 0 1 0 33k 785 0 0 1 1 20,8k 690 0 1 0 0 15k 614 0 1 0 1 11,8k 554 0 1 1 0 10,3k 519 0 1 1 1 8,7k 476 1 0 0 0 8,2k 461 1 0 0 1 7,2k 427 1 0 1 0 6,6k 406 1 0 1 1 5,9k 379 1 1 0 0 5,3k 354 1 1 0 1 4,8k 334 1 1 1 0 4,6k 321 1 1 1 1 4,2k 304

The special messages:

 1 1 1 1 1 809 77 START,PAUSE,STOP 1 0 0 0 0 1k 93 ERROR

These values may differ from one RCX and one receiver to some other due to part tolerance and probably battery level.