Reading a pin and increasing a counter, Finally done!!!!
mosquito56
Posts: 387
I have a subroutine running in another cog which turns on a led every 5 secs. The cog is started first and sets dira and outa. This is in my main program and does not work. Any ideas?
· if outa[noparse][[/noparse]27]==1
····· outa[noparse][[/noparse]27]:=0
····· counterx++
This code works when I turn on the pin in the main program but for some reason it doesn't when the pin is turned on in another cog.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/24/2008 5:05:24 AM GMT
· if outa[noparse][[/noparse]27]==1
····· outa[noparse][[/noparse]27]:=0
····· counterx++
This code works when I turn on the pin in the main program but for some reason it doesn't when the pin is turned on in another cog.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/24/2008 5:05:24 AM GMT
Comments
What makes outa[noparse][[/noparse]27] high? What will stop that making outa[noparse][[/noparse]27] high again before the if statement it next read. That is the sort of thing you need to ask yourself.
Graham
if outa[noparse][[/noparse]27] == 1
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/24/2008 5:07:17 AM GMT
?
Mosquito, you have often been asked to not only post a small part of your problem programs. You are not yet in a position to decide where an error can be, so if you want efficient help we need the FULL code.
I think you are aware that "== 1" is redundant in cases as those!?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/21/2008 10:55:55 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Here is the code, I hope this explains the proplem
Pinon below
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/22/2008 12:36:43 AM GMT
if ina[noparse][[/noparse]pin]==1
·outa[noparse][[/noparse]pin]:=0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 2/21/2008 11:44:21 PM GMT
Your "cognew(pinon.go,@stack)" won't work. You're not allowed to start a Spin method in another object. It's not documented in the manual yet, but has been described many times in the "Tricks and Traps" document and others. I can't see why you'd need it anyway since pinon.go just does a COGNEW again. You probably should just do a "pinon.go" call in the main object.
You've still got an "ina[noparse][[/noparse]pin] := 0" for some reason. It doesn't do anything useful since INA is a a read-only register. When you attempt to change it, you're just modifying the "shadow RAM" value. There are actual RAM cells for all 512 longs in the cog memory even if there are physical registers corresponding to them. For read-only registers like INA and CNT, any attempt to change the register actually stores the value in the shadow RAM cell.
The expression "outa[noparse][[/noparse]pin] := 1" always is true because you're assigning the value 1 to the output pin, then that value (1) is being used by the IF statement and is considered true. The IF statement will always succeed no matter what the output pin value becomes.
When I'm programming I find most of the problems I come across are exactly "that simple". I was trying to help, in future I won't bother.
· Not sure about the cognew not working as it seems to be working fine. The first cognew was a mistake and shouldn't be there. I will switch it and see if it works. I switched it and the video dies.
·Paul suggested that
if ina[noparse][[/noparse]pin]==1
·outa[noparse][[/noparse]pin]:=0
no luck
If someone could fix the post so it works, I would be eternally grateful. I have been working on this problem for 2 months now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
Post Edited (mosquito56) : 2/22/2008 12:44:50 AM GMT
Mosquito
There are so many issues with your code,·its difficult to be sure, but is this what you are trying to achieve ?
I can't figure out why you would want to do this, but I can't fit the broken bits together in any otherway, so I am really shooting from the hip.
I·took the liberty of removing a few lines of code. I·started to·get a headache.
Not sure·if it was·from reading your code or trying to keep up with the·Code Protect, DOL, Javalin, Forth·threads··here in PROP Land.
I've·been·AWL for a month·or so·and have a bit of reading to catch up on, looks like.
Seriously though, pin_num:=27 is being toggled at a fixed rate and pin_num_status is being sampled at a diferent rate, the sample frequency being dependent upon the code in the sample loop,·so what is cntrr(BYTE) telling us about pin_num activity anyway ?· I still don't think we know enough about your objectives to be of much help.
Ron
A seperate cog keeps a timer going and turns on a led.
The main program sees the led, turns off the led and cntt++. Thats it.
Yes the x++ loop was to keep the counter going as the second cog will turn on the pin every x seconds
·It must be in a seperate cog as I am using tv and for some reason when I start the cog from main the video doesn't work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
So here is how to use it..
Post Edited (deSilva) : 2/22/2008 9:58:42 PM GMT
Start a seperate cog that turns a pin high, led on.
Read the pin in MAIN program, increase counter and turn light off.
P.S. I sent you a msg a while back asking you not to respond to my posts. Since I don't speak German and you have some problems with English, "I am putting you on ignore" Your attitude is making me nuts'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
My posting was not meant for you but for other interested readers!
There is really no need to start any COG or whatever...
Sorry you felt highjacked :-(
Post Edited (deSilva) : 2/23/2008 12:04:28 AM GMT
deSilva, don't worry I don't think this is a very popular view
Cheers,
--fletch
·I emailed parallax about this gentlemen months ago and sent him a private msg asking him not to respond to my msgs.
I informed him today that I was putting him on ignore and yet he still insists on hijacking my threads. I would think a gentleman would take a hint. In my culture, ignoring is the biggest offense.
· ·I am positive he dislikes me, "He would have to be an idiot not to". Everytime he chimes in everyone else stops. If he continues, I will have to take it up the chain as we said in the military.
· I have asked him privately to ignore me, yet he continues. Now it is public by his choice.
I never said it was garbage, just rude.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
Mosquito
This forum as brought together some of the best computer PPL around
They come from different backgrounds and cultures so its not surprising
That misunderstanding will occur from time to time.
This is a classic example of what I mean.
I think deSilva·feels I am leading you in the wrong direction. I am sure that’s why he posted.
@deSilva
I though it was obvious that I had just reworked Mosquitoes own code. Taking into account the issues which Mike, Graham, Paul and you had raised with Mosquito earlier. Changing course to an optimal solution, (to an unknown problem) I think would have been helpful at this stage.
Yes, in fact I saw you tried well to come to the ground of the problem and then had to stop....
The reason - mostly likely - that there were no problem at all...
I tried to post code that should show that, as always a little bit "over-educated"
That was good, as we now have come to the ground of it: Setting a Pin in one COG and reading it in another. This generally works fine, though it is sometimes forgotten to set the DIRA in the writing COG.
So I should suggest that mosquito just assembles all those information here, simplifies his code, and tries again, which should then most likely work...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stan Dobrowski
I was tempted to suggest that Mosquito re visit Page 26 of the Prop manual, Rules A. B and C, in particular. Decided to take it one step at a time.
Maybe we can get his TV problem sorted out whilst dealing with some of the other outstanding issues here.
1. Private msg
2.?
3. Parallax for official complaint. I have put him on ignore and only ask he do the same to me. Since I am no longer reading his posts I will not be bothered again but he has a condesending attitude and I have had enough.
Ron, I tried you code and for the life of me can't understand why it doesn't work. The counter just counts up. Light never goes off. Sorry.
I think you have to connect an led to see the problem. I don't know what·D is saying anymore.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
I am going to prepare something for you to-nite, and will probably ask you a few questions later.
Does my code work if you change driver to tv_text instead of PC_interface ? It should just display the value of cntrr and CR nothing else and forever.
I saw your post in another thread referring to TV Problems when starting a new cog. My guess is that TV will be Ok using the code I posted.
If I am right and it works Ok then we will go from there and look at your code again line by line and see iIf we can get it sorted.
Ron
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
Each cog has an INA, OUTA and DIRA register. If a bit is set (ie set to 1, clear is set to 0) in the DIRA register and the same bit is set in the OUTA register then then the pin will go high (logic state 1 or on). Where you are running into problems is that every cog has its own INA, OUTA and DIRA register. They are not global. So if one cog sets a pin high than the only way to clear it is to either stop the cog that is setting it or to have the same cog that is setting it high to clear it.
This is all in the propeller manual. Have look where Ron suggested. It goes to great lengths to explain it.
I'm pleased to hear that. I will get back to you.
RON