Expanding the BS2 Homework Board I/O
kleekru
Posts: 32
Hello all,
I need·someone·to dumb things down for me a little if you have the patience. I am a complete beginner with high hopes.
I have the BS2 Homework board and I'm enjoying my new foray into the·world of microcontrollers.
I'm expecting to run 12 servos that could each receive different instructions based on one of 5 pedals being pushed. The 5 pedals will be configurable to represent a different combinations of servo instructions based on a grid of switches.
I think I know how to program this based on the PBASIC in the book but with the high number of inputs and outputs, it is clear I'll go beyond the existing breadboard.·Someone in another thread·mentioned "74HC595 is very good for output use and the 74HC165 is good for input use." I looked them up but I don't have a clue how to hook them up to the Homework board and translate them into additional I/O pins. I suspect I need an additional breadboard and a way to link the Homework board with the expanded breadboard?? Where do the two units you mention come in and how do I address the new I/O locations in the programming? I've been looking around for a rather elementary description of how to make this work without luck. Anywhere you can point me or any quick tips?
I also expect I'll need to address how I get power to the servos.· I doubt the 9V battery will provide what·is needed (I'm also new to electronics).· Each servo needs to press about a·pound of pressure and there could be·up to·6·engaged·with one pedal push.·
Any answers that don't sound too much like "stick to your day job" will be appreciated.· Thanks for your patience!
I need·someone·to dumb things down for me a little if you have the patience. I am a complete beginner with high hopes.
I have the BS2 Homework board and I'm enjoying my new foray into the·world of microcontrollers.
I'm expecting to run 12 servos that could each receive different instructions based on one of 5 pedals being pushed. The 5 pedals will be configurable to represent a different combinations of servo instructions based on a grid of switches.
I think I know how to program this based on the PBASIC in the book but with the high number of inputs and outputs, it is clear I'll go beyond the existing breadboard.·Someone in another thread·mentioned "74HC595 is very good for output use and the 74HC165 is good for input use." I looked them up but I don't have a clue how to hook them up to the Homework board and translate them into additional I/O pins. I suspect I need an additional breadboard and a way to link the Homework board with the expanded breadboard?? Where do the two units you mention come in and how do I address the new I/O locations in the programming? I've been looking around for a rather elementary description of how to make this work without luck. Anywhere you can point me or any quick tips?
I also expect I'll need to address how I get power to the servos.· I doubt the 9V battery will provide what·is needed (I'm also new to electronics).· Each servo needs to press about a·pound of pressure and there could be·up to·6·engaged·with one pedal push.·
Any answers that don't sound too much like "stick to your day job" will be appreciated.· Thanks for your patience!
Comments
2) A single servo motor can draw up to about 1A when starting to move under mechanical load. While moving under light load, this drops to maybe 1/3A. An idle servo (just sitting there) would draw less yet. With 6 servos in motion at a time, that's 6-8A at 6V. Do you particularly want to run this off batteries? If so, how long does it have to operate before charging? How often would the pedals be actuated?
1) I realized I may have taken the other thread off on a tangent after the fact and posted here... thanks for setting me straight!
2) Regarding the power requirements, I expect to actuate the pedals roughly once every 5-10 seconds and it should be reliable for at least 30 minutes. The "What's a Microcontroller" book refers to an AC adapter that attaches to the 9V connections. Would that do the trick. I don't necessarily need batteries but having the option to run off only a battery for a period of time is nice.
From your description, there are going to be 6 servos in motion anywhere from 25% to 50% of the time. That could be an average current of 1-3A.
Something like a SLA (Sealed Lead-Acid) battery ([noparse][[/noparse]ur]http://www.radioshack.com/product/index.jsp?productId=3307865) would work well. There are all sorts of battery chargers available for something like this since they're common for motorcycle use and riding toys.
The typical AC adapters you describe wouldn't work since you need much more current than they would have available. You really do need something that can supply 6A peak.
I've incorporated 5 74hc595's and 4 74hc165's into a board. I've separately wired (and tested) a group of 18 switches and a separate board with 24 LED's. Generally, I would like the LED's to light differently based on which switches I flip...
My problem is that the status of the switches do not seem to be going through the shift registers properly. I'm getting random values without changing the switches at all (and there seems to be some pattern at first that indicates some strange shifting.
I've checked and re-checked my wiring and I'm rather confident it is following the schematic in the StampWorks experiment to tie and cascade the 595's and the 165's together (including the 4.7K Ohm resister between PIN 14 of the 595 and PIN 7 of the 1st 165).
Here's the code I'm using (leveraged mostly from the StampWorks experiment)... and I've included the results after.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates the ability to use the 74HC595 and 74HC165
' together with the fewest number of BASIC Stamp IO pins. This is
' accomplished by placing a 4.7K resistor between the data out (pin 7) of
' the 74HC165 and the data in (pin 14) of the 74HC595. The serial data
' pin from the BASIC Stamp connects to the 74HC595.
'
[ I/O Definitions ]
Clock PIN 0 ' shift clock (74hc595.11)
SerData PIN 1 ' serial data (74HC595.14)
Latch PIN 2 ' output latch (74HC595.12)
Load PIN 3 ' input load (74HC165.1)
'
[ Constants ]
DelayTime CON 1000
'
[ Variables ]
xInputs1 VAR BYTE ' external inputs
xInputs2 VAR BYTE ' external inputs
xInputs3 VAR BYTE ' external inputs
xInputs4 VAR BYTE ' external inputs
'
[ Initialization ]
Reset:
'LOW clock
LOW Latch
HIGH Load
DEBUG CLS,
"XInputs 76543210", CR,
"
", CR,
"Status ........"
'
[ Program Code ]
Main:
DO
GOSUB Get_165 ' get inputs
GOSUB Put_595 ' move to extended outputs
DEBUG CRSRXY, 10, 2, BIN8 xInputs1, BIN8 xInputs2, BIN8 xInputs3, BIN8 xInputs4 ' display current status
PAUSE DelayTime ' pad the loop a bit
LOOP
'
[ Subroutines ]
Get_165:
PULSOUT Load, 5 ' load inputs
SHIFTIN SerData, Clock, MSBPRE, [xInputs1, xInputs2, xInputs3, xInputs4] ' shift them in
RETURN
Put_595:
SHIFTOUT SerData, Clock, MSBFIRST, [xInputs1, xInputs2, xInputs3, xInputs4] ' send inputs to 595
PULSOUT Latch, 5 ' latch 595 outputs
INPUT SerData ' float data I/O line
RETURN
And the Results:
11111111111111111111111111111111
11111111111111111111111111111111
00000000111111111111111111111111
00000000000000001111111111111111
00000000000000000000000000000000
00000000000000000000000000000000
11110000000000000000000000000000
11111111111111111111000000000000
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
00000000111111111111111111111111
00000000000000001111111111111111
00000000000000000000000000000000
00000000000000000000000000000000
11000000000000000000000000000000
11111111111111111111111100000000
11111111111111111111111111111111
11111111111111111111111111111111
Any ideas what I'm doing wrong??
Also, if anyone can explain the modes in the SHIFTIN and SHIFTOUT commands (i.e. MSBPRE, etc), I would like to understand what they do.
Thanks!
Kevin
Have you experimented with driving 2 or 3 servos yet? With a BS2, you have to pulse them all together in one continuous loop. Good programming stuff. Dive right in.
Part of the problem may be a sometimes undefined clock state. Make sure that Clock is initialized to output low.
How about trying the program first with some output test data. Try doing the SHIFTOUT with known constant data or known dynamic (changing) data, like an up counter rather than trying to copy inputs to outputs.
The 5th 74HC595 is going to show weird results since the clock will cause it to shift in the 74HC165 data while you're trying to read the 74HC165s. Then, when you actually try to shift in data, the last 8 bits will get shifted to the 5th 74HC595.
Do you have the clock inhibit input to the 74HC165 tied low?
I think it's a bad plan to start off with this sort of pin "saving". It might work eventually, but you're trading ease of debugging and reliability for a single I/O pin. Get it working first with separate clock and data lines or a shared clock line, then try it with shared clock and data lines. I think you've wired something wrong or left a pin floating.
Getting better though.
Mike, you're on top of it as usual. I was also thinking I should separate the 595 chain from the 165 chain... that's my next step. I'll also remove the 5th 595... I thought that might be another problem I would hit... but based on the read of the inputs, it didn't seem to be related to the pattern above. Nevertheless, I can manage without it. I'll let you know how it goes. Oh, and I'll take a closer look at the pages you mention. Thanks again!
... one last confirmation. "clock inhibit input to the 74hc165 tied low" means putting a resistor on pin 15 to VSS? (I'm half guessing on this).
Here's the new code:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates the ability to use the 74HC595 and 74HC165
' together with the fewest number of BASIC Stamp IO pins. This is
' accomplished by placing a 4.7K resistor between the data out (pin 7) of
' the 74HC165 and the data in (pin 14) of the 74HC595. The serial data
' pin from the BASIC Stamp connects to the 74HC595.
'
[ I/O Definitions ]
oClock PIN 0 ' output shift clock (74hc595.11)
oSerData PIN 1 ' output serial data (74HC595.14)
oLatch PIN 2 ' output latch (74HC595.12)
iClock PIN 3 ' input clock (74hc165.2
iSerData PIN 4 ' input serial data (74hc165.7
iLoad PIN 5 ' input load (74HC165.1)
'
[ Constants ]
DelayTime CON 50
'
[ Variables ]
xInputs1 VAR BYTE ' external inputs
xInputs2 VAR BYTE ' external inputs
xInputs3 VAR BYTE ' external inputs
xInputs4 VAR BYTE ' external inputs
'
[ Initialization ]
Initialize:
LOW iClock
LOW oClock
LOW oLatch
HIGH iLoad
DEBUG CLS,
"XInputs 76543210765432107654321076543210", CR,
"
", CR,
"Status ................................"
'
[ Program Code ]
Main:
DO
GOSUB Get_165 ' get inputs
GOSUB Put_595 ' move to extended outputs
DEBUG CRSRXY, 10, 2, BIN8 xInputs1, BIN8 xInputs2, BIN8 xInputs3, BIN8 xInputs4 ' display current status
PAUSE DelayTime ' pad the loop a bit
LOOP
'
[ Subroutines ]
Get_165:
PULSOUT iLoad, 5 ' load inputs
SHIFTIN iSerData, iClock, MSBPRE, [xInputs1, xInputs2, xInputs3, xInputs4] ' shift them in
RETURN
Put_595:
SHIFTOUT oSerData, oClock, MSBFIRST, [xInputs4, xInputs3, xInputs2, xInputs1] ' send inputs to 595
PULSOUT oLatch, 5 ' latch 595 outputs
INPUT oSerData ' float data I/O line
RETURN
Thanks Mike!!