SPice 10204: Programming
Once installed on a SPLat controller, the SPice10204 appears as 3 regular analog input points. The following table shows the mappings for the inputs on the board. Numbers in parenthesis are the numeric analog channel numbers used with fAnIn.
| Cnctr pin | SLXXX | MMiXXX | MS12 | ||
|---|---|---|---|---|---|
| Current transformer | 4 | AnInC (2) | AnInE (4) | AnInC (2) | |
| Potentiometer 1 | 5 | AnInD (3) | AnInF (5) | AnInD (3) | |
| Potentiometer 2 | 6 | AnInE (4) | AnInG (6) | AnInE (4) |
initializing the SPice connector
Because the pins of the SPice connector, to which the SPice10204 is connected, can be configured for different functions (analog/digital, input/output), you need to have some code in your program that configures them to the correct settings for the SPice10204.
The following section of code should be run by your program just once, at the beginning, before your program attempts to do anything else with the SPice10204.
ClrU
setu 0,3 ;set spice connector pin 4 as analog input
setu 1,3 ;set spice connector pin 5 as analog input
setu 2,3 ;set spice connector pin 6 as analog input
SpiceConfigU
Programming the current transformer
The current transformer appears as analog input C on an SL99 and E on an MMi99. It has a full scale range of 0 to 5A. The following MMi99 program will display the current on the LCD (if fitted)
ClrU ;clear U
setu 0,3 ;set spice connector pin 7 as analog input
setu 1,3 ;set spice connector pin 8 as analog input
setu 2,3 ;set spice connector pin 9 as analog input
SpiceConfigU
loop
oblcd_setcur 0,0 ;Position the LCD cursor
oblcd_text "I=" ;Show a heading
AnInE ;Read the CT
Float ;Convert to floating point
fLoadQ 1.960784E-2 ;Scale factor for 5A FS
fMul
OBLCD_fDispW 4,2 ;Display
GoTo Loop ;Repeat forever
Programming the potentiometers
There are a myriad of possible uses for the potentiometers. Once the board has been initialized, the actual act of reading a potentiometer is a simple matter of executing an AnIn instruction. The following example shows how you could perform a SPLatWare calibration of the current transformer. In this case, in an MMi99/200, potentiometer 1 is used to provide ±5% adjustment of the CT reading. This involves generating a calibration factor of between 0.95 (-5%) and 1.05 (+5%) for potentiometer readings between 5 and 250 (allowing for a few possible missing codes either end). The mid-point reading of the potentiometer is 127.
ClrU ;clear U
setu 0,3 ;set spice connector pin 7 as analog input
setu 1,3 ;set spice connector pin 8 as analog input
setu 2,3 ;set spice connector pin 9 as analog input
SpiceConfigU
loop
AnInF ;Read potentiometer 1
Float
fLoadQ -127 ;Mid-point
fAdd ;Now scaled -127 to +128
fLoadQ 4.1E-4 ; = 0.05/123
fMul ;now scaled -0.05 to +0.05
fLoadQ 1
fAdd ;now have 0.95 to 1.05 = cal factor
fLoadQ 1.960784E-2 ;Scale factor for 5A FS
fMul ;Composite scale and calibration factors
fSwap ;Save it away in Q
oblcd_setcur 0,0 ;Position the LCD cursor
oblcd_text "I=" ;Show a heading
AnInE ;Read the CT
Float ;Convert to floating point
fMul ;The scale/cal factor already in Q
OBLCD_fDispW 4,2 ;Display
GoTo Loop ;Repeat forever
| Note: For experimentation, if you don’t have a 5A AC current source handy, change the AnInE to AnInG, and use potentiometer 2 in lieu of the CT. |
Note that during debug with SPLat the SPice board may not show up correctly in the I/O window unless the board has run the initialize code. You can fix this by translating and running the above initialization sequence in the board. Add a line
a goto a
at the end to prevent translation and runtime errors.