Lynxmotion Tech Support

www.lynxmotion.com
It is currently Wed May 22, 2013 7:08 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: BS2 Stamp TOGGLE problem
PostPosted: Sun Sep 19, 2010 2:53 pm 
Offline
Roboteer

Joined: Sun Sep 19, 2010 2:36 pm
Posts: 2
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


Top
 Profile  
 
PostPosted: Sun Sep 19, 2010 4:27 pm 
Offline
Robot Guru
User avatar

Joined: Sat Apr 15, 2006 1:42 pm
Posts: 4414
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


Top
 Profile  
 
PostPosted: Sun Sep 19, 2010 7:17 pm 
Offline
Roboteer

Joined: Sun Sep 19, 2010 2:36 pm
Posts: 2
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


Top
 Profile  
 
PostPosted: Sun Sep 19, 2010 8:18 pm 
Offline
Robot Guru
User avatar

Joined: Sat Apr 15, 2006 1:42 pm
Posts: 4414
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group