Communication with 2 Different Propeller's I/Os
ryfitzger227
Posts: 99
Hello everyone,
I've came across a problem that doesn't make any sense to me.
I have two Propellers running the same code (with the exception of one line). Pin 6 of both Propellers are connected together. Basically what happens is that I have 2 pushbuttons - each connected to a propeller. The way the program is supposed to work is when the pushbutton is pressed it's supposed to check pin 6's value. If it equals 0 then the other pushbutton hasn't been pressed yet so it will set pin 6 to 1 and send a string to the computer saying that it was pressed first. If the value doesn't equal 0, then the other pushbutton has already been pressed. It works as it should the first time it is ran, but once it repeats it stops working.
Here is the code I have (remember - it's the same code for both propellers)
The / in front of the timer id just tells the computer where the start of the string is.
Does anyone see a problem that would make this stop working after the first time? If you have any questions, feel free to ask.
I've came across a problem that doesn't make any sense to me.
I have two Propellers running the same code (with the exception of one line). Pin 6 of both Propellers are connected together. Basically what happens is that I have 2 pushbuttons - each connected to a propeller. The way the program is supposed to work is when the pushbutton is pressed it's supposed to check pin 6's value. If it equals 0 then the other pushbutton hasn't been pressed yet so it will set pin 6 to 1 and send a string to the computer saying that it was pressed first. If the value doesn't equal 0, then the other pushbutton has already been pressed. It works as it should the first time it is ran, but once it repeats it stops working.
Here is the code I have (remember - it's the same code for both propellers)
repeat if t1 <> 0 and xfirst <> 0 'if Timer1 (t1) has a value and xfirst has been set to something if xfirst == 1 'if this button was pressed first serial.str(string("/1x-")) ' send value of t1 to the computer with an x to the left of the id. This designates that this button was pressed first.. serial.dec(t1) '... dira[6] := 1 'reset pin 6 (the pressed first pin).. outa[6] := 0 '... else 'if this button wasnt pressed first serial.str(string("/1-")) 'send value of t1 to the computer.. serial.dec(t1) '.. xfirst := 0 'reset the pressed first variable t1 := 0 'reset the t1 variable
if ina[6] == 0 'see if other button has already been pressed dira[6] := 1 'tell other propeller that this buttons has been pressed outa[6] := 1 '... LONG[xfirstadr] := 1 'tell computer that this button was pressed first else LONG[xfirstadr] := 2 'continue... this button didn't get pressed first.
The / in front of the timer id just tells the computer where the start of the string is.
Does anyone see a problem that would make this stop working after the first time? If you have any questions, feel free to ask.
Comments
Directly connecting I/O pins together on most CMOS chips including other microcontrollers can, if the pins are set to opposite output states, instantly destroy one or both I/O pin structures.
Thanks so much for answering this question. Now that I think of it, I really knew that. I was just trying to get that working quickly and in a hurry that I just didn't think it through very well!
I changed my idea around a little bit and here's what I've came up with. I will connect pin 7 of Propeller One to pin 6 of Propeller Two and pin 7 of Propeller Two to pin 6 of Propeller One. This way 6 is always an output, and 7 is always an input. There shouldn't be any chance of a short circuit, correct?
The only problem is that I'm getting the same results! I've done some troubleshooting and found the problem - I just can't figure out why I'm getting it. Here's the code:
The code from above actually hasn't changed much. Just a couple pin changes from 6 to 7. The code in the first post is commented a little better to understand what's going on.
I put two comments with a bunch of asterisks in two lines of code here. This is where the problem is. After the Propeller "tells" the other Propeller that it was pressed first (by setting the pin to 1) it never resets back to 0. It just stays at 1, that's why when you run the program the next time it says that neither of them was pressed first (because the value is 1 and its checking to make sure it equals 0). I hope that make sense.
Do you understand a way to make this work?
I am a bit confused.
Let's try to go through starting with your second code snipplet:
You are checking P7 to find out if a button on the other propeller was pressed.
If not you set P6 high to show that the local butten was pressed first.
In the first Code snipplet (I believe it runs on a second COG!?) you do:
Wait some t1 AND that a button on the other propeller was pressed.
If the button on the other propeller was the first one, then you reset P6
I am missing some how the button on teh propeller itself.
The other issue I see (if this is running on 2 COGS) is that you might end up with racing conditions on your variable xfirst.
I am only beginner in propeller and spin, but in paralell processing I am always curios about writing to the same variable in 2 processes.
See you around
Frank
When it says if t1 <> 0 and xfirst <> 0 all that means is if there is a value in Timer 1 and there is also a value in xfirst. If you look at the second code snippet it sets xfirst to 1 if the local button was pressed and 2 if the other one was pressed. If you don't have that extra and xfirst <> 0, then it won't catch the xfirst flag at all - it has to wait until that second code snippet to be executed (or for that variable to be set) before it can get the value of t1 to send to the computer.
It shouldn't be anything to do with the variable. If you view the pin status on another propeller after the pin gets set to 1 in the second code snippet, it never gets reset back to 0 (where it's supposed to at the 2 lines with the asterisks). Since it doesn't reset, the second code snippet (which checks if the pin equals 0) never sets the xfirst flag correctly or sets the pin of the other propeller to 1 (it assumes that the other propeller already sent that to it - meaning the other was pressed first)... It basically confuses the two propellers. Both of them thinks the other one had it's pushbutton pressed first - that leads to both xfirst flags being set to 2 and the computer thinking that neither of them was pressed first (which is impossible).
I hope this makes sense. I'm new to the propeller too, but this seems like it should be basic stuff (with setting pins) and it's proven to be really difficult. Haha.
the way you decribe it as well as the way I understand the code you are locking your self.
If I say:
P6 get set if local button is set
P7 reads Button from other Propeller
P8 is the local button
This would roughly read like:
P6 := P8
if P8 and not P7
string("/1x-"))
If P8 and P7
string("/1-")