ShiftIN and ShiftOUT help

Started by chicoisl August 4, 2004
Hello,
Is there more information about the ShiftOUT and ShiftIN commands,
more then the System_Library.pdf provides? I am trying to use these
commands in a similiar fashion to how they are used in the Basic
Stamp Language to controll the coprocessor on a TAB Build Your Own
RobotKit. I seem to be running into a timing issue between sending
information out of the BX24 and recieving information in the co-
processor.

I have been able to send somthing to the BYORK through ShiftOUT. I
can get the motors to stop by sending byte 0. I can get the led on
the robot to do some random activity (and motor twitch) when i send
byte 9. So I seem to be sending data but not the right kind and/or
at the right time.

Is there more to the ShifOUT and ShiftIN commands then the System
Library describes?
Does anybody have a particular code example were these commands are
used to shift data in and out?

ThankYOU for your time
MattB

PS here is the code...if it helps

Option Explicit
Public Const RobotStop As Byte = 0 ' Stop the Robot
Public Const RobotLEDOn As Byte = 9 ' Turn on the Robot's LED
Public Const RobotLEDOff As Byte = 10 ' Turn off the Robot's LED
public const numberofbits as byte = 8 ' number of Bits shiftedout
public robotdata as byte
'----------------------------
Public Sub Main()
call putpin(19, bxoutputhigh) 'clockpin
call putpin(20, bxoutputhigh) 'datapin

do
robotdata = 9 'setup to turn led on
call robotsend() 'call sub to send byte 9 to coprocessor
loop

End Sub
'----------------------------
public sub robotsend()

dim flipdata as byte
flipdata = flipbits(robotdata) 'mirror bits to match LSB first
'Debug.Print "flipdata is "; cstr(flipdata)

call putpin(19, bxoutputlow) 'tells coprocessor to read 8 bits
call shiftout(20, 19, numberofbits, flipdata)'shift 8 bits
call putpin(19, bxoutputhigh) 'tells coprocessor to stop reading bits
end sub
'----------------------------



--- In , "chicoisl" <chicoisl@y...> wrote:
> Hello,
> Is there more information about the ShiftOUT and ShiftIN commands,
> more then the System_Library.pdf provides? I am trying to use
> these commands in a similiar fashion to how they are used in the
> Basic Stamp Language to controll the coprocessor on a TAB Build
> Your Own RobotKit. I seem to be running into a timing issue
> between sending information out of the BX24 and recieving
> information in the co-processor.

You may be having difficulty with the fact that the BasicX ShiftIn()
function samples the data line after the clock edge. There is no way
to tell it to sample before the clock as there is in PBasic. If this
is indeed the problem, you may be able to work around it by inverting
the clock sense (starting with it high instead of low or vice versa)
or inserting an inverter between the BX-24 and the other circuitry.

An oscilloscope or logic analyzer is helpful for determining the
exact signals that are coming from and going to the BX-24. In order
for this to be useful, of course, you do need to know what the
signals should look like. Often, the datasheets for devices will
illustrate or describe them.

There may also be a timing issue. The BX-24 is faster than the Basic
Stamp and may be shifting data faster than the device can provide or
consume it. If this is the case, you can implement your own shift
in/out routines (which will be quite a bit slower). Again a 'scope
or logic analyzer would be useful if you know what the device's
specifications are.

My measurements indicate that a BX-24 shifts data out at about 20
microseconds per bit. This was too fast for one of my applications
so I implemented it myself. The fastest that I could get it was
about 130 microseconds per bit. This was with a fully unrolled loop
(see code below). Using a For loop was slower still.

Private Sub shiftOutSlowly(ByVal dataPin as Byte, ByVal clkPin as
Byte, ByVal b as Byte)
Call PutPin(dataPin, GetBit(b, 7))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 6))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 5))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 4))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 3))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 2))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 1))
Call PulseOut(clkPin, 1, 0)
Call PutPin(dataPin, GetBit(b, 0))
Call PulseOut(clkPin, 1, 0)
End Sub


I looked at your code and there are some things I don't understand.
Why do you have the "Do" statement. It appears as though you are trying to
send an endless command to light the LED.
You also forgot the "Loop" statement that goes with the "Do" statement.
As a test you could setup a "For/Next" loop and send the data that way.
Something like:

Set clock pin
Set data pin
For x=1 to 8

Switch clock state

Select case x

case 1
Set data bit.

case 2
Set data bit.

case 3...

case 8

end select

Switch clock state Next

This allows you full control of the data bits and in the case of a byte with

The value of "9" the sequence would be 10010000. Assuming you want to send
LSB first.
You could even put in a delay and watch the pins with a volt meter.
Harry

-----Original Message-----
From: chicoisl [mailto:]
Sent: Wednesday, August 04, 2004 7:27 PM
To:
Subject: [BasicX] ShiftIN and ShiftOUT help

Hello,
Is there more information about the ShiftOUT and ShiftIN commands, more then
the System_Library.pdf provides? I am trying to use these commands in a
similiar fashion to how they are used in the Basic Stamp Language to
controll the coprocessor on a TAB Build Your Own RobotKit. I seem to be
running into a timing issue between sending information out of the BX24 and
recieving information in the co- processor.

I have been able to send somthing to the BYORK through ShiftOUT. I can get
the motors to stop by sending byte 0. I can get the led on the robot to do
some random activity (and motor twitch) when i send byte 9. So I seem to be
sending data but not the right kind and/or at the right time.

Is there more to the ShifOUT and ShiftIN commands then the System Library
describes?
Does anybody have a particular code example were these commands are used to
shift data in and out?

ThankYOU for your time
MattB

PS here is the code...if it helps

Option Explicit
Public Const RobotStop As Byte = 0 ' Stop the Robot
Public Const RobotLEDOn As Byte = 9 ' Turn on the Robot's LED
Public Const RobotLEDOff As Byte = 10 ' Turn off the Robot's LED
public const numberofbits as byte = 8 ' number of Bits shiftedout
public robotdata as byte
'----------------------------
Public Sub Main()
call putpin(19, bxoutputhigh) 'clockpin
call putpin(20, bxoutputhigh) 'datapin

do
robotdata = 9 'setup to turn led on
call robotsend() 'call sub to send byte 9 to coprocessor loop

End Sub
'----------------------------
public sub robotsend()

dim flipdata as byte
flipdata = flipbits(robotdata) 'mirror bits to match LSB first 'Debug.Print
"flipdata is "; cstr(flipdata)

call putpin(19, bxoutputlow) 'tells coprocessor to read 8 bits call
shiftout(20, 19, numberofbits, flipdata)'shift 8 bits call putpin(19,
bxoutputhigh) 'tells coprocessor to stop reading bits end sub
'---------------------------- Yahoo! Groups Links


Sorry about that I screwed up the clock signal. Try this instead.

Something like:

Set clock pin
Set data pin
For x=1 to 8 Select case x

case 1
Set data bit.

case 2
Set data bit.

case 3...

case 8

end select

Pulse clock Pin Next

This allows you full control of the data bits and in the case of a byte with
The value of "9" the sequence would be 10010000. Assuming you want to send
LSB first.
You could even put in a delay and watch the pins with a volt meter.
Harry

-----Original Message-----
From: chicoisl [mailto:]
Sent: Wednesday, August 04, 2004 7:27 PM
To:
Subject: [BasicX] ShiftIN and ShiftOUT help

Hello,
Is there more information about the ShiftOUT and ShiftIN commands, more then
the System_Library.pdf provides? I am trying to use these commands in a
similiar fashion to how they are used in the Basic Stamp Language to
controll the coprocessor on a TAB Build Your Own RobotKit. I seem to be
running into a timing issue between sending information out of the BX24 and
recieving information in the co- processor.

I have been able to send somthing to the BYORK through ShiftOUT. I can get
the motors to stop by sending byte 0. I can get the led on the robot to do
some random activity (and motor twitch) when i send byte 9. So I seem to be
sending data but not the right kind and/or at the right time.

Is there more to the ShifOUT and ShiftIN commands then the System Library
describes?
Does anybody have a particular code example were these commands are used to
shift data in and out?

ThankYOU for your time
MattB

PS here is the code...if it helps

Option Explicit
Public Const RobotStop As Byte = 0 ' Stop the Robot
Public Const RobotLEDOn As Byte = 9 ' Turn on the Robot's LED
Public Const RobotLEDOff As Byte = 10 ' Turn off the Robot's LED
public const numberofbits as byte = 8 ' number of Bits shiftedout
public robotdata as byte
'----------------------------
Public Sub Main()
call putpin(19, bxoutputhigh) 'clockpin
call putpin(20, bxoutputhigh) 'datapin

do
robotdata = 9 'setup to turn led on
call robotsend() 'call sub to send byte 9 to coprocessor loop

End Sub
'----------------------------
public sub robotsend()

dim flipdata as byte
flipdata = flipbits(robotdata) 'mirror bits to match LSB first 'Debug.Print
"flipdata is "; cstr(flipdata)

call putpin(19, bxoutputlow) 'tells coprocessor to read 8 bits call
shiftout(20, 19, numberofbits, flipdata)'shift 8 bits call putpin(19,
bxoutputhigh) 'tells coprocessor to stop reading bits end sub
'---------------------------- Yahoo! Groups Links