SPA100 interfacing (part 1)

SPA100 interfacing (part 1)

Someone somewhere once said "Never complain, never explain" and so the fascinating history behind the SPA100 protocol, choice of comms IC and calibration data will have to wait for another day.

Comms basics
USB serial chip in SPA100 is the CH340, drivers available from our software page, it's a pretty common and low cost USB<>serial converter IC.
Comms is setup at 115200 baud, 8N1, no handshaking.

Understanding the calibration file
Use the current version of SPA (24.001 at time of writing) to download the calibration file - it will take about a few minutes (faster with the 10Hz setting) after connecting to the SPA100 to do this (it's a background task, so will likely already have been downloaded).  This file is "SPA_cal.txt", this file contains a number on each line.  These are organised like this:

>DAC setting for +40V
>DAC setting for -40V
>unused
>unused
>Range 1 ADC positive reading (bits 15:0)
>Range 1 ADC positive reading (bits 31:16)
>Range 1 calibration current (bits 15:0)*
>Range 1 calibration current (bits 16:31)*
>Range 1 calibration current (bits 32:47)*
>Range 1 calibration current (bits 63:48)*
>Range 2 ADC positive reading (bits 15:0)
>Range 2 ADC positive reading (bits 31:16)
>Range 2 calibration current (bits 15:0)*
...etc...

>Range 8 calibration current (bits 63:48)*

A partial example of the contents of an actual SPA_cal.txt file:
5955
356
0
0
45715
65411
12128
125
31084
35078
28612
16224
31084
35078
28612
48992

This translates as:
5955 (DAC+40V)
356 (DAC-40V)
0 (unused)
0 (unused)
-8146285 (Range 1 ADC positive)
8204128 (Range 1 ADC negative)
0.00200642 (Range 1 calibration current positive)
-0.00200642 (Range 1 calibration current negative)
 
Adding slightly to the complexity, the calibration currents are stored as floating point double*, and the calibration ADC values are stored as signed integer.

How to use the calibration parameters
Assuming you now which of the 8 ranges you are currently set to then it is straightforward to apply the calibration coefficients to the incoming SPA100 data:

Scale = (calibration current positive - calibration current negative) / (ADC positive - ADC negative)
Offset = calibration current negative - (ADC negative * Scale)

Once you have Scale and Offset for the range, use the following math to calculate the actual current:

SPA actual current = (SPA raw current reading * Scale) + Offset

In part 2 I'll cover the protocol and some gotchas.

Back to blog