Applications Note
Interfacing to the ST-4

This note describes the operation of the ST-4 from a remote control standpoint. First of all some general points of interest about the camera are:

* The ST-4 camera consists of a 192 (h) by 165 (v) element CCD, with readout electronics, an 8 bit A/D converter, and a microcomputer with image storage buffers for two images (light and dark frames). Although the CCD has more horizontal elements than vertical elements, the size of each pixel is such that the overall CCD array has an aspect ratio of 1:1.

* The ST-4 can be run stand-alone as a star tracker, controlling the relays associated with the telescope drive to keep a star positioned at a fixed position in the CCD array.

* The ST-4 can be controlled remotely over a three-wire serial interface (Transmit Data, Receive Data and Ground) at various baud rates. Upon power-up the camera starts at 9600 baud and can be switched remotely to higher or lower baud rates. In our software we commonly use 57.6K baud, but 19.2K, 9600 and 1200 are also supported for installations with longer runs between the ST-4 and the computer. To communicate with the camera you need 8 bits of data, even parity, and 1 stop bit.

* Instructions are sent to the camera and data is received from the camera in packets, with each packet containing a checksum. Instructions sent to the ST-4 are acknowledged by the ST-4 in different ways depending on the type of instruction sent.

* Each packet contains a single checksum byte at the end to allow detection of corrupted packets. The checksum byte is the sum of all the byte values in the packet, excluding the checksum itself. Since it is a single byte, the checksum wraps around to 0 at 256. For users computing the checksum you would want to use an unsigned char type or the least significant byte of an unsigned int.

* The majority of the remote control of the camera is achieved by setting bits or writing bytes to memory inside the ST-4. The ST-4 then interprets those bits and bytes and acts accordingly.

* Image data and image data alone sent from the ST-4 to the remote computer can be compressed if the remote computer enables data compression in the ST-4. The image data is sent as compressed data only if the compressed data is shorter than the uncompressed data would be.

* The ST-4 has a special half-frame mode where an image in the lower half of the CCD (83 lines) can be transferred to the top half at a high speed (avoiding streaking due to integrating while reading out) and then those 83 lines are digitized as a half-frame image.

With these items in mind, below is a description of the instructions you can send to the camera. There are only three instructions the camera can understand:

Write Memory Command

Use this command to write data to the ST-4's memory locations (discussed below) to start commands, set options, etc.

Byte Value  Meaning
  1     01   Command for Write Memory
  2      N   Number of bytes that follow, excluding the checksum
  3    0/1   0 = External ram, 1 = Internal ram
  4   LSAD   Starting address, least significant byte
  5   MSAD   Starting address, most significant byte
  6   DATA   Data to write to ram
  .      .   .
  .      .   .
  .      .   .
5+N-3 DATA   Last data byte
6+N-3   CS   Single byte checksum of all bytes, including command

Response
ACK ($06) if valid and accepted or nothing if dead

Request a Row of Image Data Command

Use this command to download rows of image data from the ST-4 after an image has been acquired. Note that two variables discussed below (50 & 51) determine which pixels in the row are sent down and the data can be compressed or uncompressed based upon the setting of bit 1 in the Mode flag.

Byte  Value  Meaning
  1  64-228  Command to send line = 64 + Line# (0 - 164)
  2      CS  Single byte checksum

Response

Byte  Value  Meaning
  1  64-228  Command acknowledgement
  2       N  Number of data bytes following
  3    DATA  First data byte.
  .       .  2nd data byte
  .       .
 2+N   DATA  Last data byte
 3+N     CS  Checksum of entire packet

Read Ram Command

Use this command to read non-image data from the ST-4's memory. Note that data read from RAM is never compressed.

Byte Value  Meaning
  1     02  Read ram command
  2      N  Number of bytes to read
  3    0/1  0 = External, 1 = Internal
  4   LSAD  Address of RAM, Least significant byte
  5   MSAD  Address of RAM, Most significant byte
  6     CS  Checksum of entire packet

Response

Byte Value  Meaning
  1     02  Command acknowledgement byte
  2      N  Number of data bytes that follow
  3   DATA  Data from ram, never compressed
  .      .  .
  .      .  .
 2+N  DATA  Last data byte
 3+N    CS  Checksum

With these three commands you can control the camera remotely by writing bytes into internal memory locations in the ST-4. The table below shows the internal addresses that are important and the meanings of each byte and bit.

Internal Ram Locations

The Internal RAM locations shown below are used to control the operation of the ST-4. The locations are shown in Decimal.

Location 45 - The last key hit on the keypad

Codes are hexadecimal as follows:

24 = TAKE DARK
25 = FIND & FOCUS
26 = CALIBRATE
27 = TRACK
2C = UP ARROW
2D = LEFT ARROW
2F = MODE
35 = RIGHT ARROW
36 = DOWN ARROW
37 = SELECT
3D = INTERRUPT
3E = MENU
3F = ADJUST

Location 46 - Mode Flag

Set of bits as follows:

b7 - 1 for full exposure (165 lines), 0 for half-frame (83 lines).
b6 - 1 for reference light array, 0 for dark array.
b5 - Set to 1 to start exposure, at end of exposure b5 and b4 below will be cleared (see b4 below).
b4 - Wait till exposure done, processor will write a 1 to b4 and a 0 to b5 when exposure is in progress, then write 0s to both b5 and b4 when done.
b3 - Set to 1 to have ST-4 do a compression of the image in memory to 1/4 it size by averaging 4 pixels into 1. The ST-4 will clear this bit when it is done.
b2 - Set to 1 to subtract dark frame in memory from light frame in memory, leaving result in light frame buffer. ST-4 clears this bit when done.
b1 - Enable data compression on transmission to host of lines of image data when 1.
b0 - Set to 1 to smooth image in memory by replacing each pixel by the sum of itself and its eight neighbors. ST-4 will clear this bit when it's done.

Location 47 - Format Flag

Set of bits as follows:

b7 - Set to 1 to remotely put the ST-4 into Find and Focus Mode.
b6 - Set to 1 to enable AntiBlooming Gate on future exposures.
b5 - Set to 1 to interrupt ST-4 from its Find and Focus, Track, and Calibrate modes. ST-4 will clear this bit after it has been interrupted.
b4 - Set to 1 to remotely put ST-4 into Track Mode.
b3 - Set to 1 to remotely put ST-4 into Calibrate Mode. ST-4 clears this bit when it has finished Calibrate Mode.
b2 - Set to 1 to have ST-4 close the relay specified by bits b1 and b0 below. The closure time is specified by the exposure time bytes below (48 and 49) and the ST-4 sets this bit to 0 when it has finished the relay closure.
b1 - See b0 below.
b0 - In conjunction with b1 above, defines which relay to close when b2 above is set. Settings for b1b0 of 00, 01, 10, and 11 correspond to right, left, up, and down relays respectively.

Locations 48, 49 - Exposure time

These two locations are the exposure time in 1/100ths of a seconnd. Location 48 is the LS byte and location 49 is the MS byte.

Location 50 - X pointer

Pixel to start on in sending lines of image data to the host. Valid range is 0 thru 191.

Location 51 - X length

Number of bytes per line to send to the host when downloading images. Valid range is 1 thru 192.

Location 52 - Additional offset constant

This value is to be subtracted from the image data when the ST-4 is instructed to do a dark frame subtraction (defaults to 0).

Location 53 - A/D Vref+ Voltage

Default = 255, Lower to have boost. For example a Boost of 4 uses 256/4 = 64 over the baseline value (location 54).

Location 54 - A/D VRef- Voltage

Default = 0, this is the same as the baseline.

Location 55 - Firmware Version

Starts at 1, current version is 4.

Location 56 - Baud rate constant

Set this to change the data communications baud rate. 255 (256-1) for 56K baud, 253 (256-3) for 19.2K baud, 250 (256-6) for 9600 baud, etc. When programmed to change baud rates, the ST-4 will send the ACK at old rate before switching. Also if the ST-4 doesn't get a valid request from the host to read from memory within 1 second after changing baud rates, the ST-4 will switch back down to the default of 9600 baud.

Location 57 - Gain for Tracking Mode

Not used remotely.

Location 58 - Instruction byte

This byte is set to 0 at power up. Writing a 1 through 255 to this byte causes the ST-4 to execute a command defined by that instruction byte. When the camera is finished with that command it writes a 0 to this location. The following commands are implemented in the version 3 and later ROMs:

1 - Scan Array and write the brightest pixel value and coordinates into locations 73 through 75 discussed below.
2 - Start an Integration of undetermined time. Ended with command 3 below.
3 - End an Integration and readout the CCD.
4 - Ignore keypresses until this command byte is reset to 0. This can be used to test the keyboard in conjunction with byte 45 described above.
5 - Activates the Alarm relay and Buzzer for the period of time specified in the Exposure Time bytes (48 and 49) described above.

Location 73 - Maximum Value

Maximum image pixel value (0 through 255).

Location 74 - Maximum X

X coordinate of maximum image pixel (0 through 191).

Location 75 - Maximum Y

Y coordinate of maximum image pixel (0 through 164).

Notes

There is a lot of detail in the previous two sections and please don't feel bad if you don't understand it. Just give us a call and we'll discuss it. Onward to the description of the image compression algorithm.

* Image data and image data alone is compressed, and then only if the ST-4 is told to do so (b1 of byte 46 is set), and the compressed data is actually shorter than the uncompressed data.

* The image compression is based on the difference between a pixels value and the value of the previous pixel.

* A compressed line of data can be detected by the fact that the 2nd byte in the received data packet (data length) is less than the requested number of pixels (setting of byte 51).

* A compressed line of data consists of a byte corresponding to the value of the first pixel (which also establishes a baseline), followed by a sequence of nibbles packed into bytes.

* In digesting nibbles, you first look at the low nibble, then the high nibble in a byte.

* If a pixel is within +7 or -7 of the baseline then the pixel is sent as a difference nibble (+7 = 0111, -7 = 1001), and a new baseline is established at the value of that pixel.

* If a pixel is not within +7 or -7 of the baseline, then the pixel is sent as three nibbles. The first nibble is a -8 (1000) which is a special value, and the next two nibbles are the pixel's value, with the 2nd nibble being the pixels ls nibble and the third nibble being the pixels ms nibble. Finally a new baseline is established at the pixel's value.

As an example the pixel sequence 4, 5, 7, 5, 25, ... would get sent as the byte 04 followed by the nibble sequence +1, +2, -2, -8, 5, 2 (byte sequence 04 21 -8-2 25 ...).

An example of what's required to take a full image is as follows:

* The desired exposure time in 100ths of a second is written to internal memory locations 48 and 49 in the camera.

* The mode flag (location 46) is set to 11100010 (Full frame, light array, start exposure, enable compression).

* You then read location 46 until both b5 and b4 are 0. * You then set location 50 to 0 (start at pixel 0), and location 51 to 192 (192 pixels per line).

* You then ask the camera to send lines 0 through 164 by requesting each of those lines individually and sequentially.


Revised: September 23, 1998 01:44:09 PM.
Copyright © 1998 Santa Barbara Instrument Group, Inc.  All rights reserved.

Please report any problems with this page directly to the Webmaster