PDA

View Full Version : Can my BS2 do this or do I need another chip?



ERM
08-23-2005, 05:37 AM
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

Chris Savage
08-23-2005, 05:49 AM
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 (mailto:csavage@parallax.com)

metron9
08-23-2005, 06:36 AM
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.



[/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
[code]

Chris Savage
08-23-2005, 06:43 AM
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 (mailto:csavage@parallax.com)

metron9
08-23-2005, 07:09 AM
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 Savage
08-23-2005, 08:36 AM
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 (mailto:csavage@parallax.com)

metron9
08-23-2005, 10:02 AM
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 Savage
08-23-2005, 10:09 PM
·· 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 (mailto:csavage@parallax.com)