There has been some interest recently in interfacing directly with the SPA100 Source Picoammeter, in this series of posts I’ll explain how to do it.
Nearly all Electron+ instruments connect via USB to a Windows based PC. Instruments send up fairly raw data as well as calibration co-efficients (more on this later), EPIC then utilises the host computer processing power to turn this raw data into calibrated data and present this to the end-user via EPIC.
This approach allows us to reduce the processing power and complexity of the instrument, reduce the size of the firmware (reducing risk of bugs!) and reduce the bandwidth of the USB datalink – this keeps the costs lower. However this does increase the complexity for 3rd parties interfacing to our instruments vs. a protocol like SCPI.
These are stored within the internal microcontroller FLASH as ‘just a bunch of numbers’, these are then drip-fed from the SPA100 to EPIC over several minutes, one 16-bit number per packet. EPIC stores these numbers into text file called “SPA_cal.txt” and uses this file to create the calibration co-efficients. This is why the first time an SPA100 is connected with EPIC it will take a few minutes to produce meaningful results. In the background, EPIC will perform a cross check of SPA100 co-efficients with the contents of “SPA_cal.txt” in-case there has been a calibration, or a different SPA100 has been connected.
To make it easier for anyone writing their own interface to an SPA100, we would suggest using the contents of “SPA_cal.txt” created by EPIC rather than working out how to download this data from SPA100, the same goes for calibrating an SPA100.
The SPA100 uses a serial<>USB bridge IC internally, this is a CH340C, made by WCH. Drivers are on our website in the software section.
Communications is 115,000 baud, 8N1.Data sent from the PC>SPA100 is always in 8byte packets.
A packet of data consists of 8 bytes (& their attendant start/stop bits).
There is to be no space between the stop bit of one byte and the start bit of the next.
|START||Bit 0||Bit 1||Bit 2||Bit 3||Bit 4||Bit 5||Bit 6||Bit 7||STOP|
A14-A0 (“ADDRESS, 15 bits): the start address of the data to be written or read
D31-D0 (“DATA”, 32 bits): this is either just the data.
CS15-CS0 (“CHECKSUM”, 16 bits): created by adding the three pairs of 16bits and 0x5555.
The SPA100 actively uses ten 32 bit sized registers to control it’s operation, there is no special requirement to write them in, or requirement on how many locations need be written – EPIC tends to write 0x001F to 0x0000 (32 locations, 256 bytes) in ‘one hit’.
|0x0001||W||Main Control Register
b12=disable STATUS LED (0=LED enabled, 1=LED disabled)
b13=reset CAL sync marker data (0=no reset, 1=reset)
b14=erase all calibration FLASH (0x001E must be 0xAA55)
b15=write data back to calibration FLASH
b16=transmit enable (0=suppress TX, 1=allow TX)
|0x0002||W||Timebase (@100KHz) e.g. 50000=2Hz, 10000=10Hz||Arbitrary||16bits unsigned|
|0x0003||W||Input Relay Range (0,1,2,3)||Arbitrary||32bits unsigned|
|0x0004||W||PGA Gain (e.g. 1,2,4,8)||Arbitrary||16bits unsigned|
|0x0005||W||Resolution (e.g.16, 18)||Arbitrary||16bits unsigned|
|0x0006||W||Zero/Short Input Relay (0=off, 1=on/short)||Arbitrary||16bits unsigned|
|0x0007||W||PWM output level (0-65535)||Arbitrary||16bits unsigned|
|0x001E||W||Calibration FLASH ADDRESS (CAL FLASH location to write)||Arbitrary||16bits unsigned|
|0x001F||W||Calibration FLASH DATA (for writing to CAL FLASH)||Arbitrary||32bits unsigned|
A ‘keep alive’ message is sent every 250ms (4Hz) to the SPA100. This consists of 8 bytes and looks like this:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55
If no message is received by the SPA100 (keep alive or general) for a couple of seconds, it will assume the USB link is broken and enter a ‘safe’ mode.
In Part 2, I’ll discuss SPA100>PC packet structure.