I messed up.
ERM
Posts: 34
Sorry about the confusion, I was·in a hurry when I wrote it.· The correct·code is below.· How can I
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 3
pause 50
low 3
pause 50
high 3
pause 50
low 3
pause 50
high 4
pause 50
low 4
pause 50
high 4
pause 50
low 4
pause 50
goto Led 2
How can I do both these programs above at the same time without any interuption.
Any ideas or will I need another chip that can put these commands seperately into the different slots on the EEPROM?· If I need another chip, which one would I need? Thank again in advance.
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 3
pause 50
low 3
pause 50
high 3
pause 50
low 3
pause 50
high 4
pause 50
low 4
pause 50
high 4
pause 50
low 4
pause 50
goto Led 2
How can I do both these programs above at the same time without any interuption.
Any ideas or will I need another chip that can put these commands seperately into the different slots on the EEPROM?· If I need another chip, which one would I need? Thank again in advance.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Consider the following-
0101
0110
1001
1010
Think of those as states.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
Everyone was answering a question I asked incorrectly. Then, the answers went off on a tangent.
I really do appreciate everyone's help, but hint's of states when I don't really understand what a state is doesn't help. I am new at this and some of this is Chinese to me. Plus, I don't think I'm being clear what I am trying to do.
Is it possible to make one set of led's flash one pattern, while another set flashes another pattern?
If I put them all in the same loop, one pair will flash first and then the other pair will flash second. Can this be done with code in a BS2 or do I need another BS2(x) chip that can write to the different "slots" on the chip?
The code I wrote above is two simple patterns, I have a lot more complex patterns I would like to use.
Thank you for your assistance.
·· I would recommend reading our "What's A Microcontroller?" text, a free download in PDF format from our website.· A link to the page is provided for you.· The link to the download is at the bottom.
http://www.parallax.com/detail.asp?product_id=28123
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
0101
0110
1001
1010
Look at those numbers. Consider the first bit position 'pin 1' (starting with the least significant place)- the second place as being 'pin 2', the third as 'pin three', the fourth as pin 4.
The first 0101 would then represent pins 1 and 3 as being 'on'-
The second line, 0110 represents pins 2 and 3 as being 'on'-
The third line, 1001 represents pins 4 and 1 as being 'on'-
The fourth line 1010 represnets pins 4 and 2 as being 'on'-
Putting pauses between them and looping you have just accomplished your desired LED patterns, as listed in your earlier code.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
To touch on what was said in the other post, the stamp is serial in nature, this means it does one and only one thing at a time. There is no way out of this, this is a fundamental aspect of all but the newest microcontrollers. So switching to another platform will not fix this (unless you are prepared to spend $1K+ on a development platform that is capable of this, but this is like trying to drive a nail in the wall with a wrecking ball).
Placing the two programs in different run slots will not help, the run slots are used to swap out a running program with different program. This is akin to having a computer with Windows and Linux on the machine, you can choose to boot up one or the other, but you cant boot up both at the same time.
What you need to do is interleave the code, this means that the code for both·flashing sequences·are smashed together into a single program so that each flashing sequence occurs properly. You can either do this by figuring out the flash sequence for each and the pauses between the·flashes, or you can throw the concept out of the window and adopt another scheme. Since you want several different flash schemes its best if you pick the latter. Ryan's suggestion is one example of an alternate approach, known as state design. The states for your proposed interleaved LED flashing is:
0101
0000
0110
0000
1001
0000
1010
0000
the rightmost bit corresponds to your LED on pin 1, the leftmost bit corresponds to the LED on pin 4. If you print out each of your programs and duplicate the first program so there is the same number of toggling of the LEDs (8 total), you'll see the states listed above are equivalent to your code. These codes would be stored in your EEPROM to be read out then written to the pins the LEDs are connected to. There are some further optimizations possible, but I won't go into them because they would probably just confuse you.
With respect to starting another thread because the other one went off-topic, take control of your threads if you feel the topic is going astray. Just post a message stating "can we get back on topic, I still don't undertsand ____". Also its advisable to just post your corrected code to the original thread. The reason why we harp on this is to avoid polluting the forum. Frequently if I go away for the weekend, I'll come back to three full pages of unread posts. If people post multiple posts this would easily expand to 6-7 pages. If I have that many messages to read, I just skip over large swaths of posts based only on the subject line. Since many members don't use a descriptive subject line (like "Problem with my BOE-Bot" when in fact his question has to do with an IR sensor thats malfunctioning, the subject doesn't really convey the problem they are having), the likelyhood of me skipping over a post that I could have helped the member on greatly increases.
P.S. didn't you ask this question about a month ago? We aren't hiding any magic bullets from you, the stamp you have today is the same stamp you had then. If our discussion is going over your head, be assertive and ask for clarifications (and be specific on the exact thing you want to be·clarified). People of all different skill levels visit these forums, and as such most of us who provide help try to strike a balance, resulting in talking over some people's heads, while talking down to others. It is your responsibility to get us to further explain a topic you are having difficulty with, we're not mind readers and have no way of knowing what you do or don't understand.
Please don't read frustration or condecension into any of my words, because those feelings are not behind this post. I am merely trying to help you to interact with us in a way that is most productive to you learning this material.
Take care,
Paul
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/23/2005 7:08:39 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/24/2005 2:03:25 AM GMT
·· You are certainly thorough!··The forum members are certainly lucky to have the added contributions.· And you're welcome!· · To that end the forums exist to help the members/customers with their support issues.· Please feel free to ask questions.· Just be prepared to do a little work too!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
[noparse][[/noparse]code]
led1
high 1
high 3
pause 50
low 1
low 3
pause 50
high 2
high 3
pause 50
high 1
high 4
pause 50
low 1
low 4
pause 50
high 2
high 4
pause 50
low 2
low 4
pause 50
goto led1
Now if you were to change the pause time in any of the lines this method would not work.
You would also have to have intended to start both programs at the same time for this to work
But if indeed you want to simulate running both loops at the same time, and start them independently I would be happy to code an example of how to do that. It will take some time and you would need a clock pulse so you could multi thread the code, and I would do it now for an excercise in brain stimulation but I was up till 4 am last night and I should go get some sleep now.
Sorry if I hijacked your other post but I thought I nailed it down in my first post.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Here are some excellent application notes written by Dr. Tracy Allen, about how finite state machine concepts can be used with the Parallax PBASIC Stamp:
http://www.emesystems.com/BS2fsm.htm
Certainly not all possible cases are covered, but that should give you a flavor of what finite state machines are, how they work, and how they might apply to PBASIC Stamp programming.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
I would like to say it is amazing how a seemingly simple question can elicit huge amounts of other concepts about how to do a very simple task. Let me add one more.
I am new at understanding what "CHIPS" can do and connecting them to the basic stamp so let me ask a question that relates to the software problem listed here and bring it into the hardware relm. Would it not be possible to use a flip flop chip, a 555 timer and a few other pieces of hardware to allow a single threaded bs2 to do the following.
BS2
Using 7 output pins
1 pin data ready pin
2 pins select led # 0 thru 3
4 pins represent a number 0 thru 255 'Length of time to light led
Hardware flip flops timer, transistors and/or whatever else needed hooked to these 7 pins
When pin 1 goes high, voltage is sent to trigger that opens path to pins 1.2 and pins 3,4,5,6 to select led and charge a capacitor. The charge would represent the 0 thru 255 number for the time the led stays on?
Like I say, I am new at this but it seems before there was software you would have to do this with only hardware. Now that we have both, should not the discussion include hardware components that take the place of code running on the stamp?
A simple example would be a circuit thet has a capacitor and 2 pins, charge up capacitor to a voltage by setting pin 2 high for a specific time, then set the pin 0 high to flip a switch that drains the capictor voltage into the led, No need to turn it off as the led will go off when the cap drops below 1.6 volts or so.
I guess I may be hijacking this post again so if anyone has a complicated circuit design/software interface combo that would do the above it might be wise to set up a new thread that ties it al together. But ignore this post if you think it is not relative to the discussion sometimes it's a grey area for me to decide.
Adding a 555 involves another IC, wiring, power, etc. PLUS all the supporting hardware, to accomplish a relatively simple task.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
<edit> btw what version of the stamp are you using? I assume it is a newer one with run slots, since you made reference to using that feature. </edit>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/24/2005 9:13:30 PM GMT
I would suggest you start simple, and work your way up. After you are comfortable with the concepts then you can start evolving them into more complex solutions.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
·· In the interest of trying a variation on, at least what I think you're trying to do, I just sat down and punched out some code to do different flash patterns on 2 different outputs.· Each flash pattern is taken from a segment in EEPROM.· That in and of itself is not so interesting, but what IS interesting is that since you had a realtively simple task, being that the pauses were the same, my routine was able to switch to a different flash pattern by pressing a button and having a pointer read from another section of EEPROM where the flash pattern was stored.
·· To simplify things a bit what is happening in my routine is that there are 3 tables (Currently, though I could add until memory was gone) with different flash patterns.· A pointer is updated to point to an index (offset) of the start of each table as it goes through the sequence.· When the button is pressed, the pointers are changed to point to the next set of tables so now LED one flashes LED pattern 2 and LED 2 flashes pattern 3.··This could be be made to happen differently for each LED.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I am trying to build a flasher that can be multiple flashers in one. Right now, on the market, there is only a single user selectable flasher with multiple outputs flashing the same selected pattern. I am trying to make user slectable flash patterns for EACH pair of outputs.
BTW, the pause times are not all the same, some of my patterns have random pause times for different effects such as below:
'{$STAMP BS2}
reps VAR NIB
BtnWk VAR BYTE
variablespeeddouble:
for reps = 1 to 4
high 1
pause 100
low 1
pause 100
high 1
pause 100
low 1
pause 100
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 100
low 2
pause 100
high 2
pause 100
low 2
pause 100
NEXT
for reps = 1 to 4
high 1
pause 80
low 1
pause 80
high 1
pause 80
low 1
pause 80
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 80
low 2
pause 80
high 2
pause 80
low 2
pause 80
NEXT
for reps = 1 to 4
high 1
pause 60
low 1
pause 60
high 1
pause 60
low 1
pause 60
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 60
low 2
pause 60
high 2
pause 60
low 2
pause 60
NEXT
for reps = 1 to 8
high 1
pause 40
low 1
pause 40
high 1
pause 40
low 1
pause 40
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 40
low 2
pause 40
high 2
pause 40
low 2
pause 40
NEXT
for reps = 1 to 4
high 1
pause 60
low 1
pause 60
high 1
pause 60
low 1
pause 60
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 60
low 2
pause 60
high 2
pause 60
low 2
pause 60
NEXT
for reps = 1 to 4
high 1
pause 80
low 1
pause 80
high 1
pause 80
low 1
pause 80
BUTTON 0,1,255,250,BtnWk,1,off
high 2
pause 80
low 2
pause 80
high 2
pause 80
low 2
pause 80
NEXT
BUTTON 0,1,255,250,BtnWk,1,off
GOTO variablespeeddouble
off:
low 1
low 2
BUTTON 0,1,255,250,BtnWk,1,variablespeeddouble
GOTO off
Right now the off feature is to be able to turn off the led's while I edit the code and rerun the code.
I assumed there are slots seeing that when I hit the map feature in the stamp editor, it shows 16 slots. This migh not be true with my stamp.
As you can see, the code gets somewhat complex with varying pause times and light up sequences. Also, I already have the "What's a microcontroller?" text and read it. I didn't pick up where it said I can't do what I am asking of it to do.
Anyway, I hope this helps to clarify. Thanks again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
·· If you wrote your code much like my example, but broke each pattern section up into a different task then you might still be able to do this, although the results would be dependant on how many different sequences you needed running at the same time, and how often the buttons needed to be checked (The button command would not be useful at all here).
·· Two changes to my example would need to be made.· One is you would need to add a delay value byte for each pattern to the EEPROM table, reading in two bytes for each action (This could also be done with less).· The other is that instead of updating the pointers sequentially, you would divide them up into tasks that used counters (inline) to count passes through each task.
·· Each task would execute one segment of code and continue, updating it's counter then return to the task switcher.··That way each task could give the illusion of running at different speeds.· I would almost be inclined to try this just to see if it could be done with a reasonable number of LEDs/patterns on a stock BS2.
·· To explain what happpens in each task, BTW, it would turn the LED on/off according to it's current position in the EEPROM map for that sequence (Selected) and then increment a counter set by the delay byte.· The sequence counter woudn't update for this task until it's timer counter expired (to 0).· Then it's EEPROM pointer would be incremented and that task would be updated again.
·· It's kind of hard to explain, but it means that it would take several passes through each task for one to change states, but they would be able to do so at different intervals, not together.· I think Paul may know what I am getting at.· This stuff is often used in IRQ/ISR routines to allow counters that don't delay the ISR.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
·· I can do that probably later today (I did that from home), but I am also considering trying to whole kitten kaboodle (sp?) with 8 LEDs and 8 inputs just to see what happens.· We're talking about a lot of tasking going on here.· In the outside loop to break up each individual sequence and inside each sequence section to update the timing/sequence for that routine.· It could be done...The question is performance.· I'm surprised you didn't bang out some code to do this on a BS2px24!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
What have we learned from this?· Was it worth it?· Ha! Ha!
Dave
P.S.· I couldn't resist!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
·
2) Listen to your girlfriend when she says "Let the machine get it".
3) Have the backbone to say no when asked to do something you truely don't want to do.
Though I did win my match, which helped my team regain our first place standing (I beat someone 2 skill levels higher than me, the most difficult match I've played all season, I spend 3/4 of my shots playing defense trying to force a "ball in hand" situation (APA rules state if you do not strike your own ball first, resulting in your ball in a pocket or any ball striking a rail, the opponent gets to place the cue ball anywhere on the table)).
Anyways, this is off topic so I'll stop this tangent now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
·· You are correct, I didn't...My example just used a bunch of patterns stored in DATA statements, and I was hoping to implement the original poster's press a button idea.· But instead I cleaned the code up enough so that you can see easily the variables that set the table pointers and make your own code to switch patterns.·
·· This code makes my case clearly I think.· I used my PDB to do this.· I wired P0-P7 to the first 8 LEDs on the board, although I only use 6 in this example.· This code has individual patterns of varying lengths, with the on/off times of each LED totally independant of the others.· Not perfect, but gets the job done, AND on a BS2!·
Comments/Questions are welcome.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com