Shop OBEX P1 Docs P2 Docs Learn Events
Can my BS2 do this or do I need another chip? — Parallax Forums

Can my BS2 do this or do I need another chip?

ERMERM Posts: 34
edited 2005-08-23 15:09 in BASIC Stamp
Hello all,

I'm going to be real basic about this.· How can I do both these programs below at the same time without any interuption.


Led 1:

high 1
pause 50
low 1
pause 50
high 2
pause 50
low 2
pause 50

goto Led 1

and

Led 2:

high 1
pause 50
low 1
pause 50
high 1
pause 50
low 1
pause 50
high 2
pause 50
low 2
pause 50
high 2
pause 50
low 2
pause 50

goto Led 2

Any ideas or will I need another chip that can put these commands seperately into the different slots on the EEPROM?· Thank in advance

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-22 22:49
    Tony,

    ·· It's not possible since both programs use the same I/O pins.· If there were different pins being used, this might be possible.· But two programs or tasks cannot access the same pin at the same time.· Now, while the BASIC Stamp is a single-tasking micro, it is possible to turn on/off multi pins at the same time.· But they need to be on different pins first.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • metron9metron9 Posts: 1,100
    edited 2005-08-22 23:36
    Actually you only need one loop, This code will do the same thing as if both loops were running at the same time
    as the first high low combo is trying to turn on the same pin you only need 1 of the loops to do it

    Chris, I don't know but when you say " it is possible to turn on/off multi pins at the same time" is true on a micro scale of time would not each instruction to turn on each pin take a few clock cycles? Is there a way to flip all pins on/off from the pbasic code? or would you have to have direct access to the latching bits on the PIC? I was reading some assembler code for the atmel chips and that's where I saw the latching register I think it was called that.



    [noparse][[/noparse]/code]
    Led 1:

    high 1
    pause 50
    low 1
    pause 50
    high 2
    high 1
    pause 50
    low 2
    low 1
    pause 50

    high 1
    high 2
    pause 50
    low 1
    low 2
    pause 50
    high 2
    pause 50
    low 2
    pause 50
    goto Led 1
    [noparse][[/noparse]code]
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-22 23:43
    Okay,

    ·· Say you want to turn on P0 and P3 at the same time, and a half second later turn those off and turn on P1 and P2.· As long as your DIRS register was already setup with the appropriate pins made an output, the you could do the following...

    Main:
      OUTA = %1001
      PAUSE 500
      OUTA = %0110
      PAUSE 500
      GOTO Main
    

    ··This technique can work for all 16 I/O pins.· Likewise groups of pins can be read at the same time.· If you still don't understand, let me know and I will post a better example.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • metron9metron9 Posts: 1,100
    edited 2005-08-23 00:09
    Very cool , so many ways to skin a cat....
    Set all pins high would be...
    OUTS = %1111111111111111
    
    'set pins 5,6,7 and 8 high
    OUTB = %1111
    
    ' Revised code for above example would be
    Led 1:
    
    high 1
    pause 50
    low 1
    pause 50
    OUTA = %1100
    pause 50
    OUTA = %0000
    pause 50
    OUTA %1100
    pause 50
    OUTA %0000
    pause 50
    high 2
    pause 50
    low 2
    pause 50
    goto Led 1
    
    
    
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-23 01:36
    Yes,

    ·· But you must first have the corresponding direction register setup properly.· If you run the following program...
    OUTS = %1111111111111111
    

    You'll notice nothing will happen...However, if you run the following...
    DIRS = %1111111111111111
    OUTS = %1111111111111111
    

    Then you get the desired results.· It works the same way for inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • metron9metron9 Posts: 1,100
    edited 2005-08-23 03:02
    Ahhh yes good point.

    if you are working with just 2 or 3 pins 0-2 for example and you wanted to leave pin 3 in its current state you would have to either read its state (in or outupt mode) and set the bit to the same if using the DIRA=%1111 or use three statements DIR0=%1 etc...

    Is it common practice when using OUTS and OUTA etc to use the direction register once at the start of a loop or section of code or just plug both in every time. I guess what I am saying is can anything from outside your code change the direction register once you set it?

    EDIT on above post bits 5,6,7, and 8 should read bits 4,5,6 and 7
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-23 15:09
    ·· You only set the DIRS once, typically in a program...Rarely would they need to change, but it could be possible.· In this application the DIRS could bet set at the beginning and not be changed.· Sometimes it is desirable to preset the states of the output lines prior to making them outputs, so that when they switch from input they are already HIGH or LOW.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.