Example: Simple read and display using SPice10209
This sample program provides a very simple read-and-display function for one channel of the SPice10209. In effect it makes an MMi99/200 into a basic thermometer. By an easy change you can set the program to read in °C or °F.
This is a single task program which fully occupies the SPLat processor. Most of the time it is just waiting for the TSP interface to complete its previous task. The program listing is interspersed with detailed comments to explain what is going on. The file is also located in the examples supplied with SPLat/PC, file name TC-1.SPT.
;TC-1.SPT: A minimal SPice10209 program for MMi200 (or MMi99).
;The SPice10209 thermocouple interface is a Tiny Serial Peripheral (TSP).
;TSP uses a serial data protocol to communicate between the SPLat controller
;and an add-on (SPice) board.
;============== I/O allocations for MMi99/200 ==============
iFault10209 iEQU 17 ;This SPice pin is a direct hardware fault flag
oWaitSignal oEQU 15 ;Front panel LED, signals waiting for TSP
oActivity oEQU 14 ;Activity monitor
oFault10209 oEQU 10 ;Front panel LED, signals SPice10209 fault
oFaultyTSP oEQU 9 ;Front panel LED, signals TSP fault
;============== Initialize the UV interface ==============
;Only those pins used by the SPice10209 need be configured.
;Leave others as defaults, which is the safest policy
setu 2,2 ;set all as inputs
setu 3,2
setu 4,2
SpiceConfigU ;Configure the SPice pins according
; to nonzero values in U
;============= Initialize the TSP interface ==============
;The Tiny Serial Peripheral (TSP) interface on the controller uses 2 of the SPice pins.
;The TSPReset instruction configures those pins correctly (irrespective of any
;previous configuration) as well as sending a reset instruction to the SPice10209 board
TSPReset ;Enable TSP interface driver and pins
;All further TSP communication with the SPice10209 goes via the U register.
;As with all TSP transfers for byte, word and long data types, all data is
;right justified in U0 through U3. Address 8 in the SPice10209 is the
;filter time constant register.
SetU 3,4 ;Set up filter time constant 1=min, 4=max
TSPPutByteL 8 ;Send filter Time Constant to the board
;==== End of initialization ==============
;===== Main loop ==========================
;The main loop of this program does just two things endlessly. It reads
;one channel of the SPice10209 thermocouple board and it displays the result
;on the onboard LCD (OBLCD).
Loop:
GoSub ReadTC ;Subroutine to get one TC reading to W
OBLCD_SetCur 0,0 ;Position LCD cursor
OBLCD_fDispW 8,2 ;Display number in W
OBLCD_SpclChar 223 ;Degree sign
OBLCD_Text "C" ; C or F
InputO oActivity ;Activity indicator
NOT
Output oActivity
GoTo Loop
;============== End of main loop ==============
;============== Subroutines ==============
;Read SPice10209 Ch 1, return the result converted to degrees in W. Uses Q and UV.
ReadTC:
TSPGetWordL 0 ;Instigate a reading from SPice10209
;You can patch the address for ...
; 0 Ch 1 unfiltered
; 2 Ch 2 unfiltered
; 4 Ch 1 filtered
; 6 Ch 2 filtered
;Executing TSPGetWordL sends a data request to the SPice10209 board.
;We then have to wait for the data to become available.
;TSPBranch tests the status ...
ReadTCWait:
ON oWaitSignal ;Signal waiting for TSP
TSPBranch ;Test TSP status
Target ReadTC ;0 Idle .. strange
Target ReadTCWait ;1 Still busy
Target ReadTCGotData ;2 Have data
Target ReadTCFault ;3 Fault in TSP interface
;When TSPBranch returns 2 (got data) the data requested in the preceding
;TSPGet is automatically transferred to the U register bytes U0-U3.
;The TSPBranch is absolutely neccessary in order to trigger that data transfer.
;After the data is transferred the SPice10209 will drive SPice pin 6
;(input 17 on MMi99/200) ON if there is a channel fault.
ReadTCGotData:
Off oWaitSignal ;diagnostic
Input iFault10209 ;SPice10209 fault input
Output oFault10209 ;display
floatFromU 0 ;Convert reading to FP
fLoadQ 0.25 ;Scale factor. 0.25 for deg C, 0.45 deg F
fMul
fLoadQ 0 ;Offset. 0 for Deg C, 32 for deg F
fAdd
Return
;If the TSP interface returns a fault we could have a serious problem.
;(Don't confuse with a fault from the SPice10209, which could be a simple
;open thermocouple or non-existent channel).
;In this example all we can do is display it then soldier on.
;You can induce this fault by simply removing the SPice10209 board (power down first!)
ReadTCFault:
Off oWaitSignal ;diagnostic
On oFaultyTSP ;Signal fault
Pause 50 ;Show for 500mS
Off oFaultyTSP
GoTo ReadTCWait