Sometimes you have to proceed to time-measurements which must be more precise than the RCX is able to. In such cases you require digital counters. Of course the information needs to be transmitted to the RCX. This is not an evident task, since the RCX has only analog inputs. The LEGO Mindstorms community (have a look at the web-sites of Andreas Peter or the one of Philo ) has developped several serial interfaces.
We worked on the idea of converting the digital information to an analog signal. The first appearance of this device may be found at the Phase sound sensor's page. A real hybrid between serial and D/A-converting systems can be seen at the Infrared-ultrasonic beacon's pages.
The following device is an extended version of those prototypes. The main idea is to create a resistor-net which is a mathematical base to convert a binary 8-digit-number to a single resistor-value. This may be done by placing the resistors either in a serial or a parallel net. It is important that the different values of the net are multiples of 2i , otherwise you will not get an unambiguous result.
1. SERIAL NET
Note that open switch = 1; closed switch = 0;
|S4 = 0||S3 = 0||S2 = 0||S1 = 0||0|
2. PARALLEL NET
Note that this time closed switch = 1; open switch = 0;
Attention: because the inverse of ri is considered, the order of ri and Si must be changed. Note the decreasing R-values.
|S1 = 0||S2 = 0||S3 = 0||S4 = 0||0||#DIV/0!|
3. THE INTERFACE WITH A PARALLEL NET
Beside the low-cost-target we want to provide a galvanic separation, in order not to injure the RCX in any way. The easiest way is to use opto-couplers.
Note that the polarity has to be respected! +V to x1-1.
Because of the RCX-internal 10k pull-up resistor, the conversion to the raw-values follows the formula:
RAW = 1023 * R / (10000 + R) have a look at the book Extreme Mindstorms, Mike Gasperi, USA, 2000
By transforming the formula you get the R-value back:
R = 10000 * RAW / ( 1023 - RAW)
We have R = f(X) = A / X, where X is the initial digital value
So we get back f -1(R)= A / R = X
In our case :
Note that there is a non-neglectable error due to part tolerance! The net has been chosen among standard resistor-values in order to provide as much as possible unambiguous RAW-values. Note that the 10-bit A/D-converter within the RCX gives 1024 different integer values. But the curve being hyperbolic, the function decreases at the rate of -1/x2. So the real function may be surjective for the higher x-values. Of course the result can be improved by changing the net as close as possible to multiples of 2i.