SPLatco Knowledge Base

Once installed on a SPLat controller, the SPice10218 appears as one analog input and 3 digital outputs. The following table shows the mappings for all the I/O on the board. Numbers in parenthesis are the numeric analog channel numbers used with fAnIn. You should use fAnIn to get the full benefit of 10-bit resolution.

 SPice cnctr pinSLXXXMMiXXXMS12x
Analog input4AnInC (2)AnInE (4)AnInC (2)
Channel select 25DO 9DO 17DO 13
Channel select 16DO 10DO 18DO 14
Channel select 07DO 11DO 19DO 15

The SPice10218 is a multiplexer. That means it has the ability to select any one of its 8 analog input lines and route that through to a single analog input on the main SPLat controller board, where it can be read by an analog input instruction, e.g. fAnIn. The channel to be read is selected by sending a binary coded channel number to 3 “channel select” outputs. The analog input channel used, and the 3 channel select outputs, vary between SPLat controller boards according to the table above.

Channel select patterns

The following table defines the bit patterns for the 3 channel select outputs and the corresponding input channel numbers.

 Channel select out
Ch012
0OffOffOff
1OnOffOff
2OffOnOff
3OnOnOff
4OffOffOn
5OnOffOn
6OffOnOn
7OnOnOn

You may recognize this as a simply binary count, which indeed it is. Note however that the the least significant channel select bit is in the most significant of the three outputs.

Initializing the SPice connector

Because the pins of the SPice connector, to which the SPice10218 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 SPice10218.

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 SPice10218.

         ClrU
setu 0,3 ;set spice connector pin 4 as analogue input
setu 1,1 ;set spice connector pin 5 as digital output
setu 2,1 ;set spice connector pin 6 as digital output
setu 3,1 ;set spice connector pin 7 as digital output
setu 4,0 ;set spice connector pin 8 as unchanged
setu 5,0 ;set spice connector pin 9 as unchanged
SpiceConfigU
Reading an analog value (example program)

Once the SPice connector has been initialized (which you would do early in your program using the code above), reading a channel requires setting the channel select outputs to the right pattern, allowing the analog voltage to settle, and then executing an analog input instruction.

The analog settling time must be taken into account. It cannot be ignored. The settling time constant is up about 0.5mS. It takes 7 time constants to settle to 10 bits. Hence the multiplexer requires at least 3.5mS to settle to 10 bits.

The following is a MultiTrack task that will automatically scan all 8 channels. To use it copy and paste the code into your program and edit the SP218_MUXStart and SP218_AnIn constant values to match your controller type. To start it up simply LaunchTask Scan218. To access a reading load X with the required channel number 0-7 and GoSub Get218Reading. The latest reading for the required channel will be returned in W as a normalized number 0-1.

* The following equates select the base address for the MUX select lines on the
* SPICE connector based on the board type:
*
* SL99, SL100 SP218_MUXStart = 9, SP218_AnIn = 2
* MMi99, MMi200, MMi201, MMi202 SP218_MUXStart = 17, SP218_AnIn = 4
* MS12, MS120 SP218_MUXStart = 13, SP218_AnIn = 2

SP218_MUXStart equ 17 ;MMiXXX
SP218_AnIn equ 4


Ch218 defBYTE
Readings218 defFLOAT 8 ;Result holding variables

;The scanner stores readings in an array of 8 floating point numbers.
;Because of the bit reversal that takes place on the 218 board, the
;order of readings in memory will be scrambled. This gets sorted out
;by bit reversing the index used during readout, in Get218Reading.
Scan218:
Recall Ch218
LoadX 7
OutputM SP218_MUXStart
Pause 2 ;Guarantee 10mS minimum settling delay.
fAnIn SP218_AnIn
Recall Ch218
Push
XtoI
IasJ:fStore Readings218
IncX
LoadX 7
AndM
Store Ch218
GoTo Scan218

;Return the latest reading for the channel number in X
Get218Reading:
GoSub ReverseBits012
XtoI
IasJ:fRecallW Readings218
Return

ReverseBits012: ;Reverse bit order 0, 1, 2 in X
RB_X1 defBYTE
RB_X2 defBYTE

RB_Y0 SetMem RB_X2,0
Store RB_X1
GoIfSF 0,RB_X1,RB_Y1
SetS 2,RB_X2
RB_Y1 GoIfSF 1,RB_X1,RB_Y2
SetS 1,RB_X2
RB_Y2 GoIfSF 2,RB_X1,RB_Y3
SetS 0,RB_X2
RB_Y3 Recall RB_X2
Return