This code communicates between a BX-24 and a PAK-VII coprocessor. Since the PAK-VII uses the same protocol as the PAK-I, II, III, IV, VIII, and IX, the same code should work with these coprocessors also. Only the commands (and possibly the bit length of the response) would be different.

This nicely commented code is courtesy of Mark L. Newell. Thanks Mark!

' This is PAK-VII code for the BX-24
' Courtesy of Mark L. Newell m_l_newell@yahoo.com
' This code issues PAK-VII resets and then reads the TICK register
' With changes to the commands (and the number of bits read), this should work
' for PAK-I, II, III, IV, VII, VIII, or IX
' (PAK-V and VI use RS-232)

dim result as integer ' 16 bit result of shiftin
const pak7outputpulse as integer = 4 ' (in 1.085 usec units) about 4.34usec 
'********************* Main Program ************************************************* 
public Sub Main()
const PAK7OneSecTimer as byte = bx00110001 '
const PAK7Reset as byte = bx11111111 '
const PAK7CLK as byte = 10 ' BX-24 pin for Clocking
const PAK7Sin as byte = 11 ' BX-24 pin for sending bits to PAK7
const PAK7Sout as byte = 11 ' BX-24 pin for receiving bits from PAK7
'********************* Issue a PAK7 comm sys reset *************************************
call PutPin (PAK7Sin, bxoutputlow) ' make sure sin is low
call PutPin (PAK7CLK, bxoutputhigh) ' set clock high
call PulseOut (PAK7Sin, pak7outputpulse, bxoutputhigh) ' pulse PAK7Sin
call PutPin (PAK7CLK, bxoutputlow) ' set clock low 
call delay(0.001) ' let it settle down
'********************* Issue a PAK7 FRESET *********************************************
call PAKShiftOut(PAK7Sin,PAK7CLK,PAK7Reset)
call delay(0.001) ' let it settle down 
'********************* Loop to track seconds *******************************************
do
call PAKShiftOut(PAK7Sin ,PAK7CLK, PAK7OneSecTimer) 'use project watch widow
result=PAKShiftin (PAK7Sout ,PAK7CLK) 'to track result
loop
End Sub

'******************** Procedure to shift a 8 bit cmd to the PAK7 **********************
sub PAKShiftOut(ByVal Dpin as byte, _
ByVal Cpin as byte, _
ByVal CMD as byte)
dim lpctr as integer
dim pinstate as byte
for lpctr = 7 to 0 step -1
if (getbit(cmd,cbyte(lpctr)) = 1) _ 
then
  pinstate = bxoutputhigh ' it is a one
else 
  pinstate = bxoutputlow ' it as a zero
end if
call PutPin(Dpin,pinstate) ' set data line appropriate
call PulseOut(Cpin,pak7outputpulse,bxoutputhigh) ' pulse the line for next bit
next
end sub 
'********************* Integer function to get 16 bits from PAK7 ***********************
function PAKShiftIn(ByVal Spin as byte, _
ByVal Cpin as byte) as integer
dim idx1 as integer
dim idx2 as integer
dim pakreturn as integer
dim pak7outbit as byte
for idx1 = 0 to 1 ' the low byte comes in first
  for idx2 = 7 to 0 step -1 ' get eight bits
    pak7outbit = GetPin(spin) ' get the value on Data pin
    call PulseOut(Cpin,pak7outputpulse,bxoutputhigh) ' pulse the Clock
    call putbit(pakreturn,cbyte((idx1*8)+idx2) ,pak7outbit)' insert bit in return
    next
  next
PAKShiftIn = pakreturn
end function 

To adapt this to different PAKs you'd probably want to change the PAKShiftIn call so it only reads a byte at a time. Just remove the "for idx1" line and replace it with idx1=0 (be sure to remove the corresponding "next" command). Or, rewrite the putbit call to not refer to idx1 at all. Then you could read single bytes easily and assemble them as necessary for the particular PAK you are working with.


Site contents © 1997-2018 by AWC, Houston TX    (281) 334-4341