AduJava - Binary Basics Tutorial

 

This is a basic tutorial about binary numbers. It begins with a discussion about decimal numbers and then moves on to binary numbers. The tutorial then applies this knowledge to ADU200 boards.

Decimal

The numbers we use in daily life are based on the number 10. We call these base 10 or decimal numbers.

For instance take the number 1,111 which is spelled out as
one thousand one hundred and eleven.

The number 1,111 can be broken into a sum
formula1.jpg (4321 bytes)
Factoring the numbers gives
formula2.jpg (3541 bytes)
Expressing the value with exponents gives
formula3.jpg (3340 bytes)

Generally

To convert a four digit number "abcd" in base "y" to decimal base 10 simply plug the value for "y" into the formula.
formula11.jpg (2975 bytes)

Binary

To treat 1111 as a binary number we use the value 2 as the base. Note that we will use red to indicate a binary number and black to indicate a decimal number.
formula4.jpg (2703 bytes)

Calculating the exponents gives
formula5.jpg (2563 bytes)

ADU200 Relays

The ADU200 relays are labelled K3, K2, K1 and K0. The mk command is used to set the relays on an ADU200 board. To compose the mk command treat the desired states of K3,K2,K1,K0 as a binary number and convert it to decimal. Append the decimal value to the command.

For example: the mk15 will turn all the relays on, since as shown above, binary 1111 = 15 in decimal.

Similarly to turn on K3 and K2 with K1 and K0 off send the command mk12 since binary 1100 = 12 in decimal.
formula7.jpg (3177 bytes)
The following screen shot shows the mk4 command being sent to the ADU200. This will set relay K2 on since binary 0100 = 4 in decimal.
formula10.jpg (3015 bytes)
adujava.mk4.jpg (16410 bytes)

The response shown in the screen shot is the ADU200's reply to an rpk command to show the relay status. Each character corresponds to a relay on the board K3, K2, K1, K0. A 1 means the relay is on and 0 means the relay is off. The response of 0100 means that relays K3, K1, K0 are off and relay K2 is on.

The state of the ADU200 can be seen in this photo.
k4.on.jpg (39560 bytes)

The following screen shot shows the mk10 command being sent to the ADU200. This will set relays K3 and K1 on since binary 1010 = 10 in decimal.
formula8.jpg (3695 bytes)
adujava.mk10.jpg (17653 bytes)

The effect on the ADU200 can be seen in this photo.

 

Tabular Method

If you are uncomfortable with binary you can simply look up the relays in this table and add up the corresponding values to derive the mk command.

Relay K3 K2 K1 K0
Value 8 4 2 1

For the ADU208 which has 8 relays the table is:

Relay K7 K6 K5 K4 K3 K2 K1 K0
Value 128 64 32 16 8 4 2 1

For example to turn on relays K6 and K2 on the ADU208 send the command "mk68" (ie. 64 + 4).