Shop OBEX P1 Docs P2 Docs Learn Events
Procedure with BS2 & shifters 74HC595 & 74HC165 — Parallax Forums

Procedure with BS2 & shifters 74HC595 & 74HC165

DragoDrago Posts: 24
edited 2009-07-29 04:17 in BASIC Stamp
Hello everybody,
·
No needs to say that I am new here!
Recently I discovered the BS and I am very sorry I didn’t have this opportunity 20 years ago.
It appears that we can use it in the application we already using different processor, but we do not have capabilities to change the software or preloaded process.
Now I will try to switch to BS, but I need little help in this:
Here is the application:
We have 43 “positions” and each position is connected to 2 inputs and 2 outputs (total 172 I/O).
I would like to use one BS2 with shifters 74HC595 and 74HC165.
Each “position is independent and applies the same process:
-········· Input #1 change the state (ON) = activate output #1 for time (10 seconds) next,
if input #2 change the state (from OFF to ON) it activates output #2 and deactivate output #1.
Output #2 stays ON until input #2 is ON even if the process repeats (input #1 trigger again,….).
When input #1 is triggered and input #2 is closed after time out (10 seconds) both outputs #1 & #2 should close.
·
As a beginner I wrote the code for the process, but I do not know how to implement this with the shifters for that many I/O’s?
' {$STAMP BS2}
' {$PBASIC 2.5}
·
DO
·
DEBUG ? IN5
DEBUG ? IN3
IN3 = 0
IF (IN3 = 1)· THEN
HIGH 14
·
PAUSE 10000
LOW 14
·
IF IN5 = 1 THEN
HIGH 15
ELSE
IF· (IN5 = 0) THEN
LOW 15
·PAUSE 3000
ENDIF
· ENDIF
·ENDIF
·
LOOP
·
Previously we used TPIC6B595, but I wasn’t able to make it happen. Today I order the 74HC595 and if anybody can help me with this code that will be great.
Thank you
Drago

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-07-15 18:03
    Welcome aboard!

    On the Parallax website you can download "What's a Microcontroller" which is a really good source for some of the common things we do with Stamps.

    In particular, it has some articles on the use of the shift registers you mentioned.

    I've done a couple of jobs with the expansion concept (only to 64 inputs, though) for a lumber tally system. Generally they work quite well as long as your process has enough processing time to cycle through the registers. Some experimentation may be required.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • DragoDrago Posts: 24
    edited 2009-07-15 19:22
    Thank you Tom,
    I get some samples from couple sources and the part I wrote work fine, but I wasn’t able to make happen with shifters.
    It may happen that TPIC6B595 can’t work and I have to use 74HC595, so I am now on hold until I get them.
    I am little bit older guy and it will take little bit until I swallow all info.
    Drago
  • stamptrolstamptrol Posts: 1,731
    edited 2009-07-16 16:28
    No worry, there are a lot of us "bit older" guys here.

    I think your TPIC6B595 can be made to work but it does have a couple extra inputs compared to the 74HC595. Maybe comparing both data sheets you could cross match them.

    Also, I may have steered you to the wrong resource.....have a look at the "Stampworks" document on the Parallax website.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • DragoDrago Posts: 24
    edited 2009-07-16 18:15
    Thank you for your support Tom,
    I downloaded Stamp works and it is great help.
    As I mentioned I am new with programming, but I am a veteran in electronic hardware.
    My experiment with TPIC6B595 it may work, because I implemented the code from Stamp works and I get one cycle of LED’s on (it doesn't repeat?), but I don’t know how to write my application to associate the particular inputs with outputs.
    So I taught that will be better to eliminate problem with unknown hardware and use the 74HC595 which sample is written for.
    The sample for 74HC165 also works fine each input change the state.
    ·
    Regarding your comment from yesterday each process will be executed separately, so the “traffic” should not be a problem.
    Scanning time it could be interrupted for ms until execute output, but this is not crucial.
    Thank you
  • stamptrolstamptrol Posts: 1,731
    edited 2009-07-16 20:24
    Keep at it!

    Let me know if I can help further.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • dev/nulldev/null Posts: 381
    edited 2009-07-17 01:32
    The 74HC595 and 74HC165 works very well with Stamps. Attached is a schematic for chaining 595's.

    For your project you will need 11 input and 11 output shift registers, for a total of 176 I/O.

    Attached is some code that might work for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • DragoDrago Posts: 24
    edited 2009-07-17 16:57
    Thank you dev/null,
    I am waiting to get the 74HC595 and 74HC165 and I will try the configuration and will apply the code.

    What about 74HC165? How they are connected?
    Are they using the same communication line or they should be on different pins?
    Some schematics I have require the resistor to distinguish inputs from outputs on same line.

    I can have inputs on different three pins of BS2, and:
    • Inputs 1 & 2 could be related only to outputs 1& 2 to execute my process,
    • Inputs 3&4 related only to outputs 3&4,
    • Inputs 5&6 related only to outputs 5&6, and so on.

    That way will avoid the potential communication problem?

    By the way how is in Norway?
    Have a nice weekend
    Drago
  • dev/nulldev/null Posts: 381
    edited 2009-07-17 19:02
    I am not sure excactly how you would chain 165's, but they can use the same communication lines. I suppose you can connect them excactly as you connect the 595's.

    In the code I wrote, which I post an update to here, I am assuming that you have inputs 1&2 related to outputs 1&2 of the same "position", and so on. If you didn't you'd get really confused!! smile.gif

    BTW Norway is beautiful this season. I live on the west coast, and do lots of windsurfing and robot-building!!

    I had to correct an error in the code. The attachment manager in this forum is bugged, so I post the code here.

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    iopin PIN 0
    clockpin PIN 1
    latchpin PIN 2
    
    InBits VAR Byte(11)
    OutBits VAR Byte(11)
    counter VAR Byte
    pos VAR Byte
    TempInBits VAR Byte
    TempOutBits VAR Byte
    
    ' The only reason for using Temp variables, is to address the individual bits in the code below.
    
    Main:
      GOSUB ReadBits
    
      ' Check Inputs #1
      FOR counter = 0 TO 10
        TempInBits = InBits(counter)
        FOR pos = 0 TO 8 STEP 2
            IF TempInBits.BIT0(pos) = 1 THEN TempOutBits.BIT0(pos) = 1 ' Activate Input #1
        NEXT
        InBits(counter) = TempInBits
      NEXT
      GOSUB WriteBits
    
      ' WAIT 10 Seconds
      PAUSE 10000
    
      DO
        ' Check Inputs #2
         GOSUB ReadBits
    
        FOR counter = 0 TO 10
          TempInBits = InBits(counter)
          TempOutBits = OutBits(counter)
          FOR pos = 0 TO 8 STEP 2
            IF TempInBits.BIT0(pos+1) = 1 THEN  ' Input #2
              TempOutBits.BIT0(pos) = 0   ' Deactivate Input #1
              TempOutBits.BIT0(pos+1) = 1 ' Activate Input #2
            ENDIF
            IF TempInBits.BIT0(pos) = 1 AND TempInBits.BIT0(pos+1)=0 THEN
              TempOutBits.BIT0(pos) = 0 ' Activate Input #1
            ENDIF
          NEXT
          InBits(counter) = TempInBits
          OutBits(counter) = TempOutBits
        NEXT
        GOSUB WriteBits
    
      LOOP
    
      END
    
    WriteBits:
      FOR counter = 10 TO 0
        SHIFTOUT iopin, clockpin, MSBFIRST, [noparse][[/noparse]OutBits(counter)]           ' Send the bits to 2nd HC.
      NEXT
      PULSOUT latchpin, 1                                                  ' Transfer to outputs.
      PAUSE 50
      RETURN
    
    
    ReadBits:
      PULSOUT latchpin, 5 ' Load switch inputs
      FOR counter = 10 TO 0 ' The last HC is read first
        SHIFTIN iopin, clockpin, MSBPRE, [noparse][[/noparse]InBits(counter)] ' shift them in
      NEXT
      PAUSE 50
      RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • DragoDrago Posts: 24
    edited 2009-07-17 19:11
    Thank you dev/null

    It is really easy to confuse me, because as I mentioned I am novice in software development, but you did right.
    Thanks one more time.
    As soon as I receive my IC’s I will experiment with that and let you know how it works.

    BTW: I moved from Europe here recently, and Norway was one of countries I wasn’t able to visit, but I always wish.
    Maybe when I get retired (Hi, Hi)
    Enjoy!
    Drago
  • dev/nulldev/null Posts: 381
    edited 2009-07-17 19:13
    Maybe I misunderstood a question. Just to assert: You need 3 pins for the 595's and 3 pins for the 165's, for a total of 6 pins.

    You are welcome to Norway smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • dev/nulldev/null Posts: 381
    edited 2009-07-17 19:18
    The code about might not do excactly what you want with regards to your timing issues.
    The code will:
    1) Read input #1 on all positions, and turn turn outputs #1 ON (if inputs are on)
    2) Wait 10 seconds
    3) Continously check both inputs. If input #2 is ON, turn Output #1 OFF and Output # 2 ON. If Input #1 is ON and Input #2 is OFF, turn output #1 OFF.

    You will probably have to understand the code to make it work perfectly.

    Good luck!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • DragoDrago Posts: 24
    edited 2009-07-17 19:18
    Yes, I will use three pins on BS2 for inputs and other three for outputs.
    There are enough pins, so I guess when separate the communication the application should work better and more stabile.
    Drago
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-17 23:17
    Chaining 74HC165 and 74HC595 is covered in detail in the Stamp Works manual and code is included. I often use both devices in design to save I/O pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-07-20 19:53
    Drago,
    If you would like a hardcopy of the StampWorks 2.0 book, PM me a mailing address. I picked up 5 of them a few years ago on a dirt-cheap eBay auction. Sometimes a hardcopy is easier to use than the PDF. Not sure what the differences are between Version 2.0 and the PDF online that is Version 2.1. I don't see an "change history" anywhere and a quick perusal of both turned up no differences.

    I also recently started looking into 595s for a setup that uses multiple Temp/Humidity sensors. I think this may be an easier approach than using up 2 IO pins for each of the 12 sensors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • DragoDrago Posts: 24
    edited 2009-07-20 20:28
    Hi Chris & Andrew,
    Thank you for response.
    I downloaded already Stamp works and I am fine for now.
    It may be somebody else that needs the book more than I.
    Dev/null helped me with code and now I am trying to make it work with TPIC6B595 which we already use, but in different configuration.

    This should be the same type of shift register, but it allow 150mA of continues current per output instead 35mA (74HC595).
    Will se how it will work.
    Regards,

    Drago
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-07-26 22:00
    The TPIC6B595·and the 74HC595 apparent;y work differently in that the TPIC6B595 (and similar) ICs sink an attached load while the 74HC595 sources a load.
    ·
  • DragoDrago Posts: 24
    edited 2009-07-28 17:00
    Hi ronczap,
    I am not an expert, but I believe that by setting the pin 9 (G) HIGH/LOW that could be changed?
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-07-28 19:47
    I'm no expert either but I wouldn't expect that to work.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-28 20:07
    The TPIC6B595 works just like a 74HC595 except that the outputs include an open-drain power MOSFET that sinks current (to ground).

    The 74HC595 outputs are standard "totem-pole" outputs that will either source current (from Vdd) or sink current (to ground) depending on whether the output state is high or low respectively.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-07-28 20:37
    Thanks for the info Mike.

    Are you saying that the TPIC6B595 can only sink while·the 74HC595 can both·source or sink?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-28 20:45
    Sort of ...

    The TPIC6B595 can only sink current, but can sink quite a bit of it.

    The 74HC595 can sink or source current, but not a lot of it (maybe 20mA ... look at the datasheet for details).
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-07-29 00:31
    Mike,

    · I just received some 74hc595 shift registers and set up two of them to drive 16 LEDs (per the Stamp Works experiment #23) and everthing works fine. How would I wire the LEDs if I wanted to sink the load rather than source?

    I looked up totem-pole outputs but don't grasp the way they function but apparently they can sink more current than they can source.

    It would be useful to know how to do that.

    Thanks again for your knowledge and help.

    Ron
  • DragoDrago Posts: 24
    edited 2009-07-29 04:17
    Shift register TPIC6B595 allow 150mA of continues current per output instead 35mA (74HC595).
Sign In or Register to comment.