The PAK-XII is a powerful math coprocessor that also adds analog input capability to your microcontroller. The latest version of the PAK-XII also adds a powerful macro capability that lets you define up to 10 macros that can perform repetitive computations more efficiently.

Since the PAK-XII works with so many different processors, I'm going to demonstrate the PAK-XII connected through a MAX232 to a PC using Hyperterminal. Although it doesn't make much sense to add a math coprocessor to a PC, this is an excellent way to develop PAK-XII code since you can just type in expressions and immediately see the results. Of course, you might want to use the PAK-XII's analog capabilities on the PC, but that's not really the subject of this article!

If you want to hook a PAK-XII to your PC, you can use an RS-I or GPMPU40 board. Or you can rig your own MAX232 converter, if you prefer. You do need to ground pin 15 of the PAK (unless you are really using handshaking, which is not really necessary on a PC).

Once you have your PAK connected to the PC's COM port (I'm using COM 1, but you'll need to adjust my instructions to match your port) you need to create a Hyperterminal session. Use COM1 (or the port you've selected) and set the parameters to 9600, 8 bits, 1 stop bit, and no parity. Set the handshaking to none.

In addition, you'll want to select the Properties menu item from the File menu. Select the Settings tab and click ASCII setup. You should select options so that the dialog that appears looks like this:

Now you are ready to go. Try something simple just to make sure you have everything hooked up correctly:

1 3 /= 0.3333333

(I've put the PAK's response in red italics to set it off from the commands you issue via Hyperterminal).

Now, suppose that your program wants to read from A/D converter 0 and multiply it by .00488 (this gives you voltage instead of counts). Further, suppose that you've used an op amp to offset the voltage by .75V (so that a 0 reading is really .75V and a 5V reading is really 5.75V. You could define a macro:

{a0.00488*.75+
OK

I'd usually use some spaces to make the equation clearer, but since there is a limited amount of macro space (511 bytes) you should try to remove any unnecessary spaces. The "a0" reads the A/D converter. The numbers and math operators perform the calculation. The result will wind up on the top of the stack when the macro runs. Note that the PAK replied OK (followed by a carriage return). If there was an error (no more macro space, for example) it would have sent ## and a carriage return.

Now, when you want to use the macro, you use the } command followed by the macro number. Since this was the first macro defined, it is macro 0:

}0=
4.2250000

That's it! The macro definition ends with a carriage return. Otherwise it is just what you would send to the PAK anyway.

Let's define another macro to compute 5*x*x + 1.1x - 16.4 (a polynomial). In this case, x will be the top of the stack when the macro runs:

{@@*5*~1.1*+16.4-
OK

The @ operators create copies of the top of the stack. The first * multiplies x by x (squares x) and then the 5* multiplies by 5. The ~ operator swaps 5*x*x with the original copy of x. Then the macro multiplies by 1.1, adds the two terms, and subtracts 16.4. Here's the result:

2 }1= 5.8000011

Notice that since this was the second macro defined, it is macro 1. In this case, x is 2.

You can define up to 10 macros (0-9). Once defined, they can't be edited or deleted without resetting the PAK. However, you can delete all the macros at once. Send {{ and a carriage return. The PAK replies OK, and deletes all macros. The next macro you define will be macro 0. If there is a chance that your program might reset without the PAK resetting, you should always clear macros when your program starts. This prevents you from using macros from the last time your program ran.

Here's a macro that uses a PAK-XII variable:

{]01+[0=
OK
}3 1.0000000
}3 2.0000000
}3 3.0000000

This is like a mini program that keeps a count in register 0.

You might be tempted to try using a macro from within another macro. In fact, you can do this. However, when you transfer control to the second macro, you'll never return to the first macro. For example, suppose that the counting macro above is macro 3 and you write macro 4 like this:

{1}3+=
OK

This is an acceptable macro, but the += part will never execute since macro 3 will take control and never return.

You can even use macros to define customized "commands". For example, here is a macro that provides an average A/D reading:

{a0a0+a0+a0+4/

This macro reads channel 0 4 times, sums the readings, and divides by 4 to provide an average.

Macros are a powerful addition to the PAK-XII's repertoire. You don't have to use them, of course, but they can make your program much simpler to construct. Also, since they minimize the amount of data sent between the processor and the PAK, macros can greatly increase your program's efficiency.


Site contents © 1997-2014 by AWC, 310 Ivy Glen, League City, TX 77573    (281) 334-4341