Putting robotics at your service™

Free shipping on orders over $200

BS2 Stamp TOGGLE problem

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 4 posts ]

New ( offline )
Posts: 2
Posted: 2010-09-19 15:53 
 Post subject: BS2 Stamp TOGGLE problem
Electronics has been my hobby for over 50 years but I do not have any microprocessor experience.

I have written the following simple program for a Parallax BS2 Stamp. I would like to add a third Pin that would TOGGLE to flash an LED to indicate the microprocessor is turned on. My problem is that I do not know how to write the TOGGLE part of the program so that a Pin TOGGLES at the same time (concurrently) with the DO LOOP running. I would be very great full for any help that you can give me in getting the two functions to run concurrently.

Code:
' {$STAMP BS2}
' {$PBASIC 2.5}


DO

 LOW 14
 PAUSE 500
 HIGH 14
 PAUSE 100



 LOW 15
 PAUSE 65000
 HIGH 15
 PAUSE 3000
 LOW 15
 PAUSE 65000



  LOOP


Thanks!

Dennis


User avatar
Guru ( offline )
Posts: 4904
Posted: 2010-09-19 17:27 
Hi and welcome Dennis,

My BS2 stuff is a a bit rusty, but will try to help.

Not sure of what you mean by toggle a third pin to show the processor is turned on. For now assume pin 13 is the third pin. If you simply want to turn it on when the program is running. You could do either a high 13 or a low 13 at the start of your program, depending on how you have the LED wired in.
If you wish for the third LED to toggle on and off, at one speed do you wish for it to toggle?

If I am reading your code correctly it looks like LED 1 comes on after a half second and stays on for a long time (something like 133+ seconds), before it goes low again for maybe a half second... LED 2 comes on after LED 1 by about 65 seconds and stays on for maybe 3 seconds before it goes off for about 130 seconds... Is this correct. Note: On/Off may be reversed...

Kurt


New ( offline )
Posts: 2
Posted: 2010-09-19 20:17 
You are correct about the way the circuit operates. I can use any pin, that could be turned on and off, as the third pin for the LED. I would like a flash rate of about 500 mS on and 500 mS off. My problem is that I cannot design the program to flash the LED on and off while the other part of the program is active. In other words the only way that I have been able to configure a third pin to flash is after Pins 14 and 15 have timed out. The third pin wants to act serially with Pins 14 and 15 and not in parallel with them. I need the LED to flash continuously while the other part of the program is in the DO LOOP.

Thanks for your interest in helping me.

Dennis


User avatar
Guru ( offline )
Posts: 4904
Posted: 2010-09-19 21:18 
Hi Again. On a Basic Atom Pro 28, I could easily do this by setting up a timer with an interrupt that toggles the pin. But I don't know if that is available on the BS2. I rather doubt it.

So another approach would be to break up the code into a loop that loops sleeping by the minimum time each step takes and do something at the appropriate time in the loop.

I am not at all proud of this quick and real dirty approach. Note: I did not try this at all and my timings may be slightly off, but maybe something like:
Code:
cnt VAR Word

DO
  LOW 14
  FOR cnt = 0 TO (5 + 1 +650+3+650)
    PAUSE 100
    IF cnt = 5 THEN
      HIGH 14
    ELSEIF cnt = 6 THEN
      LOW 15
    ELSEIF cnt = (6+650) THEN
      HIGH 15
    ELSEIF cnt = (6+650+3)THEN
      LOW 15

    ENDIF
  IF cnt // 5 = 0 THEN
    TOGGLE 13  ' this assumes that pin 13 is new pin for LED...
  ENDIF

  NEXT
LOOP

I would be much happier with the code if I built a table with a time value and an indicator of what to do, but...

I hope this helps
Kurt


 

All times are UTC - 5 hours [ DST ]. It is currently 2014-09-15 22:56
Feedback Form
Feedback Form