BNC 630 User Manual

Page 78

Advertising
background image

73

'------------------------- Send ASCII Hex data to 630 ----------------------
' This format sends the same two's complement data that Binary format uses,
' except that each nibble (4 bits) of the hex value is represented by
' an ASCII character.

'

' Each point is a 16 bit word which is sent to the 630 with 4 characters.
' Each character represents 4 bits of the 16 bit value:

'

' 0000 to 1001 - Represented by an ASCII "0" to "9"
' 1010 - Represented by an ASCII "a" or "A"
' 1011 - Represented by an ASCII "b" or "B"
' 1100 - Represented by an ASCII "c" or "C"
' 1101 - Represented by an ASCII "d" or "D"
' 1110 - Represented by an ASCII "e" or "E"
' 1111 - Represented by an ASCII "f" or "F"

'

' For example, the 16 bit value 1101 0011 0101 1111 is sent as "d35f"

'

' The 16 bit value is in "two's complement" format, which represents a number
' from -1.0 to +1.0 as follows:

'

' 8000 ---- E000 ---- FFFF,0 ---- 4000 ---- 7FFF
' -1.0 -.5 0.0 +.5 +1.0

'

' Although a 16 bit value is sent to the 630, the Arbitrary Waveform system
' uses a 12 bit D/A converter, so not all 16 bits are used. Only the uppermost
' 12 bits are used to form the arbitrary waveform point.

'

' Rules for Hexadecimal format:

'

' 1. Each Hexadecimal value may have 1 to 4 characters. Negative values require
' 4 characters since the most significant bit of the value (bit 15)
' must be a 1 for negative values. If there are fewer than 4 characters the
' value is interpreted as positive. Characters are not case sensitive.

'

' 2. To separate each number, you may use commas, tabs, spaces, carriage returns
' and/or linefeeds, semicolons, colons or basically any character that is not
' among the following:
' 0 1 2 3 4 5 6 7 8 9 a A b B c C d D e E f F

'

' 3. The most significant nibble character is the first that is sent to the
' 630. For example, to send the value 1234, the 1 is sent first, then
' the 2, etc.

'

' 4. The SYNC Out output is controlled by bit #3 in the low byte. If this bit
' is set to 1, SYNC Out is set high. If this bit is set to 0, SYNC Out
' is set low.

'

' Examples of ASCII hex numbers, SYNC Out is set high on point #3:

'

' 0, 4000, fed8 4570 8000 fff0 E6D0, 10 FF,C06
'------------------------------------------------------------------------------

SendHex:
IF PointNumber = 1 THEN PRINT #1, "WH" ' Put header before 1st data point

' Convert the value in PointVal to two's complement hex
j = 32767

IF PointVal < 0 THEN PointVal = PointVal + 2: j = 32768!
a = INT(PointVal * j) ' Get a number 0 to 65535

a = INT(a / 16) ' Mask off lower 4 bits ($FFF0)
a = a * 16

IF PointNumber = 2 THEN a = a OR &H8 ' Set SYNC Out bit for second point
a$ = HEX$(a) ' Convert the integer to hexadecimal

' For negative values, the HEX$ fctn will return a 32 bit value, ie $FFFF FFD8,
' so chop off all but the last 4 chars

IF a < 0 THEN a$ = RIGHT$(a$, 4)
PRINT #1, a$ ' Send hex point to 630
RETURN

Advertising