Shop OBEX P1 Docs P2 Docs Learn Events
independant codes? — Parallax Forums

independant codes?

ERMERM Posts: 34
edited 2005-07-09 19:14 in BASIC Stamp
Can a stamp operate two seperate codes independantly?· i.e., can you write into memory a set of flash patterns, have a button or switch as an input to flash one pair of led's and another switch to flash a second set of led's.· Keep in mind the two sets of led's will each be on their own flash pattern (One double flash and one quad flash).· You can turn on one or both pair by the flip of either switch or both switches.· Can the BS do this?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 20:17
    The BASIC Stamp is single threaded, so it can only do one thing at a time. That said, you may be able to do what you want with a specific coding strategy that sets up tables for the flash patterns, and adds the table values together if needed based on inputs. I could write you a simple demo if you show me what the flash patterns are and the timing required.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Steve JoblinSteve Joblin Posts: 784
    edited 2005-07-07 21:01
    I could swear that I remember seeing a creative programming technique that somehow was one program with two parts.· Each time the Stamp would power up, it would run only one part (i.e. turn it on, it would run "A", turn it off then back on and it would run "B", turn it off then back on and it would run "A" again, and so on.)

    I just spent over an hour trying to find it, but I can't.· Does anyone have any idea what I am talking about?· I hope I am not just imagining it.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-07-07 21:22
    Tony -

    All of the PBASIC Stamps other than the BS-1 and plain BS-2 support multibank programming. Each of the program banks can contain up to 2 K in program code. There are a total of 8 banks in most of the Stamps.

    One simple scheme would be to write a switch bit in EEPROM and alternate it on each execution of the program. For lack of a better terminology, call it even and odd. On even excursions, banks 2,4,6,and 8 are used and on odd excursions, banks 1,3,5, and 7 are used. It could just as easily be "split" as 1-4, and 5-8 if that's easier to understand. In all cases, bank 0 is used for the main program which decides which of the program banks to use.

    Even with that all said, no multiple program execution occurs simultaneously as you seemed to want. Program execution can be concurrent (during the same time period), but not simultaneous (at the same time). That's just the nature of single tasking processors.

    I can only guess that's what you'd been reading.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 21:23
    You could easily program for two different things; I believe that Tony wants to be able to do those thing separately or together depending on inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-07-07 22:00
    You could have the 'appearance' of multiple threads running- for LEDs flashing couldn't you view the entire device as a state machine?

    Just a thought.

    Ryan
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-08 00:20
    That was my thought too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ERMERM Posts: 34
    edited 2005-07-08 04:48
    Hey guys,
    Thanks for the response. I drew a diagram of what I am trying to do. From what you are telling me, it is not possible with the BS2. As you can see, I wanted to have three switches controlling three pairs of outputs. The two lines from each output represents an output going to an led, so two leds per output. I wanted switch 1 to turn on a flash pattern for output 1, switch 2 and 3 to turn on their respective outputs and all three of them to have seperate flash patterns. Is this possible with the BS2 or do I have to get another chip that can do this and do you know what chip?


    parallax.jpg
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-07-08 06:41
    Tony -

    Your question still lacks a good deal of clarity, but the diagram does help somewhat. Is the following logic what you want the Stamp to do, based on the condition of the input pins:

    1. Any time an output pin is turned on, apply power to two devices connected to that pin.

    If so, you need a drive transistor on the output pin. The drive transistor is turned on by the Stamp, when appropriate, and it in turn supplies the power to one or more external LEDs. This prevents overloading of the Stamp pin by the current requirement of the output device(s) (LED or otherwise).

    2. If Input pin one is ON (logical 1) then Output Pin one is turned ON or set to logic 1.
    If so, you are looking to do this:
    IF IN1 = 1 THEN
    OUT1 = 1
    ENDIF

    3. If Input pin two is ON (logical 1) then Output Pin two is turned ON or set to logic 1.
    If so, you are looking to do this:
    IF IN2 = 1 THEN
    OUT2 = 1
    ENDIF

    3. If Input pin three is ON (logical 1) then Output Pin three is turned ON or set to logic 1.
    If so, you are looking to do this:
    IF IN3 = 1 THEN
    OUT3 = 1
    ENDIF

    There was never a need for simultinaity, or concurrency, nor for any fancy considerations. This is simple, straight line, sequential logic, pure and simple, if I'm understaning your requirements correctly.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-08 12:10
    Tony,

    Yes, it's possible to do what you want. Show me the respective patterns and I'll show you the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-07-08 18:17
    This is what I (and I think Jon) was talking about. Consider the device as a state machine. Here are your states:

    000
    001
    010
    011
    100
    101
    110
    111

    Each bit representing a state of one of the switches. This project may be a fun excuse to practice doing some work in Octal (base 8 [noparse];)[/noparse]

    Each state will have an associated 'pattern' - the patterns are derivatives of the mixing of the individual patterns you wanted.

    Ryan
  • ERMERM Posts: 34
    edited 2005-07-09 18:43
    My intentions are to have three seperate flash patterns, 1: single flash 2: double flash 3: variable speed double flash.· Each one will be assigned to the respective switches.· When a switch is turned on, the respective flash pattern will run.· Their are two outputs per one input pin so one pattern will flash leds on pins 2+3 when switch 1 is turned on. The same goes for the rest.· Input on pin 4 and out to pins 5+6 (yada yada yada).· Can pins 2+3 and pins 5+6 and pins 8+9 flash independantly of each other?· Meaning, can I have three seperate codes running at one time or user selected by the switches?
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-07-09 19:14
    You are going to 'interlace' the PWM/power for flashing the LEDs.

    Possible pseudo code:

    Scan switches-
    Set 'patterns' by switch pattern
    Flash 'cycle'
    Rescan switches- if unchanged go back to flash cycle- if changed, update 'patterns'

    (I am oversimplifying- I'm heading out the door)-

    Ryan
Sign In or Register to comment.