Shop OBEX P1 Docs P2 Docs Learn Events
programming problem — Parallax Forums

programming problem

ArchiverArchiver Posts: 46,084
edited 2001-10-24 03:38 in General Discussion
If input 1 goes back low immediately, I'd tie it to the Stamp's RESET
pin. The first thing your Stamp program would do is check inputs 2
and three to decide if it's running due to initial power application
or input assertion. Then set the outputs to match the input and
start a 20 second PAUSE followed by deactivating the outputs and
END, or simply END if no inputs are active. If input 1 goes low
again during or after the 20 seconds the whole process repeats.

If input 1 stays low you'll need to turn it into a pulse with some
hardware to use this approach.

This problem almost sounds like it was thought up to be solved by a
Stamp.

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-02-26 01:44
    [font=arial,helvetica]hi Guys,
    ·········I'm working on a project that call for me to monitor three inputs,
    the inputs are lable 1,2 and 3. Input 1 Is held high constantly until one of
    the other two input go high. ·There is also three output that reflect what on
    the input...... for example if input 2 goes high, output 2 must go high for
    twenty seconds, unless within that time some other input is triggered and the
    twenty seconds is canceled and the selected output is sent high....... My
    question is how can I start a specify timing cycle and have it canceled on
    demand....

    thank you for your help
    wendell
    [/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-02-26 17:40
    >hi Guys,
    > I'm working on a project that call for me to monitor three inputs,
    >the inputs are lable 1,2 and 3. Input 1 Is held high constantly until one of
    >the other two input go high. There is also three output that reflect what on
    >the input...... for example if input 2 goes high, output 2 must go high for
    >twenty seconds, unless within that time some other input is triggered and the
    >twenty seconds is canceled and the selected output is sent high....... My
    >question is how can I start a specify timing cycle and have it canceled on
    >demand....
    >
    >thank you for your help

    Hi Wendell,

    The program must be constantly running in a loop, and the time
    intervals are determined by counter that decrement every time around
    the loop. I don't understand the relation between input 1 and the
    other two inputs, but it would go something like this. Read the
    inputs. Detect a change from low to high on an input. If there is a
    transition preset the counter for that channel for a 20 second
    interval, and zero all other existing counters. Wait for next time
    tick. Redo the loop. This kind of program is called a "state
    machine". The time tick can come from the program itself using pause
    commands and careful tailoring of the program code, or it can come
    from an external clock generator.

    -- Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com/BS2fsm.htm <-- some examples of state machines

    P.S. Please post messages in plain text. (I find large blue italic
    lettering, distracting!)
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-05 04:00
    [font=arial,helvetica]In a message dated 2/26/01 9:54:12 AM Pacific Standard Time,
    tracy@emesystems.com writes:


    >hi Guys,
    > ········I'm working on a project that call for me to monitor three inputs,
    >the inputs are lable 1,2 and 3. Input 1 Is held high constantly until one
    of
    >the other two input go high. ·There is also three output that reflect what
    on
    >the input...... for example if input 2 goes high, output 2 must go high for
    >twenty seconds, unless within that time some other input is triggered and
    the
    >twenty seconds is canceled and the selected output is sent high....... My
    >question is how can I start a specify timing cycle and have it canceled on
    >demand....
    >
    >thank you for your help

    Hi Wendell,

    The program must be constantly running in a loop, and the time
    intervals are determined by counter that decrement every time around
    the loop. ·I don't understand the relation between input 1 and the
    other two inputs, but it would go something like this. Read the
    inputs. ·Detect a change from low to high on an input. ·If there is a
    transition preset the counter for that channel for a 20 second
    interval, and zero all other existing counters. ·Wait for next time
    tick. ·Redo the loop. ·This kind of program is called a "state
    machine". ·The time tick can come from the program itself using pause
    commands and careful tailoring of the program code, or it can come
    from an external clock generator.


    Hi tracy,
    ············Thank you for your help, keep up the good work
    Wendell
    [/font]

  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 00:36
    hey guys,
    got a problem here. I'm trying to control this servo off of my bs2-
    sx. Here's the problem:
    The servo will move ccw and cw but i have to load the program into
    the stamp everytime i want it to move.
    Here's the program:input 8
    input 11

    again:

    if in8 = 0 then cw
    if in11 = 0 then ccw

    goto again

    cw
    pulsout 7, 500
    pause 20
    goto cw

    ccw
    pulsout 7, 2500
    pause 20
    goto ccw

    Any ideas if i'm missing a statement here? Should i write it any
    other way so that i don't have to load the program everytime. Thanks
    for any help.
    Jon
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 00:55
    At 11:36 PM 10/23/2001 +0000, you wrote:
    >hey guys,
    >got a problem here. I'm trying to control this servo off of my bs2-
    >sx. Here's the problem:
    >The servo will move ccw and cw but i have to load the program into
    >the stamp everytime i want it to move.
    >Here's the program:input 8
    >input 11
    >
    >again:
    >
    >if in8 = 0 then cw
    >if in11 = 0 then ccw
    >
    >goto again
    >
    >cw
    >pulsout 7, 500
    >pause 20
    >goto cw
    >
    >ccw
    >pulsout 7, 2500
    >pause 20
    >goto ccw
    >
    >Any ideas if i'm missing a statement here? Should i write it any
    >other way so that i don't have to load the program everytime. Thanks
    >for any help.
    >Jon
    >
    >Jon -

    Once you get INTO either routine (cw or ccw) you are in an infinite loop.
    You need to provide from some exit mechanism - probably back to again

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 00:59
    At 19:36 10/23/01, jhtoolman2000@y... wrote:

    >hey guys,
    >got a problem here. I'm trying to control this servo off of my bs2-
    >sx. Here's the problem:
    >The servo will move ccw and cw but i have to load the program into
    >the stamp everytime i want it to move.
    >Here's the program:
    >input 8
    >input 11
    >
    >again:
    >
    >if in8 = 0 then cw
    >if in11 = 0 then ccw
    >
    >goto again
    >
    >cw
    >pulsout 7, 500
    >pause 20
    >goto cw
    >
    >ccw
    >pulsout 7, 2500
    >pause 20
    >goto ccw
    >
    >Any ideas if i'm missing a statement here? Should i write it any
    >other way so that i don't have to load the program everytime. Thanks
    >for any help.

    You provide no way to get out of either the CW or CCW goto loops, thus
    after making either pin 8 or pin 11 active, and going to the appropriate
    loop to activate the servo, you are stuck there. Rethink the logic
    flow. Maybe put a means of escaping each loop inside each loop itself? In
    the meantime I think you can get by with pressing reset to restart the
    program instead of reloading it.


    Jim H
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 01:55
    Yeah, you have an endless loop in each one of your code segments that moves
    the servo. You need to perform the loop a certain number of times, then exit
    to the outer loop. Usually doing a loop 25-50 times will give the servo time
    to move from one end to the other.

    Original Message

    > got a problem here. I'm trying to control this servo off of my bs2-
    > sx. Here's the problem:
    > The servo will move ccw and cw but i have to load the program into
    > the stamp everytime i want it to move.
    > Here's the program:input 8
    > input 11
    >
    > again:
    >
    > if in8 = 0 then cw
    > if in11 = 0 then ccw
    >
    > goto again
    >
    > cw
    > pulsout 7, 500
    > pause 20
    > goto cw
    >
    > ccw
    > pulsout 7, 2500
    > pause 20
    > goto ccw
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 03:05
    At 20:55 10/23/01, Rodent wrote:
    >Yeah, you have an endless loop in each one of your code segments that moves
    >the servo. You need to perform the loop a certain number of times, then exit
    >to the outer loop. Usually doing a loop 25-50 times will give the servo time
    >to move from one end to the other.

    But a servo loop with a specific number of executions defeats the idea that
    the servo will respond to pins 8 & 11 *when* they are activated vs X
    iterations of a loop later. Bruce had the right idea with putting "goto
    again" inside each loop. With that change if a given pin (8 or 11) stays
    activated the motor will continue to move in that direction. It looks like
    it is free to be pushed around by whatever load it is driving if neither
    pin is activated. I hope that's acceptable for the application. If not,
    another loop to center the servo (or whatever) could be made to be executed
    when neither pin is activated. Many variations on this idea are possible.

    Note that if *both* pins are activated, the servo will turn CW because the
    "if in 11 = 0 then CW" line will never execute.

    JimH


    >
    Original Message
    >
    > > got a problem here. I'm trying to control this servo off of my bs2-
    > > sx. Here's the problem:
    > > The servo will move ccw and cw but i have to load the program into
    > > the stamp everytime i want it to move.
    > > Here's the program:input 8
    > > input 11
    > >
    > > again:
    > >
    > > if in8 = 0 then cw
    > > if in11 = 0 then ccw
    > >
    > > goto again
    > >
    > > cw
    > > pulsout 7, 500
    > > pause 20
    > > goto cw
    > >
    > > ccw
    > > pulsout 7, 2500
    > > pause 20
    > > goto ccw
    >
    >
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-10-24 03:38
    I got the impression he wanted to move the servo all the way one way or the
    other. If he wants to use the value of the pins to change positions on the
    fly he would be best to use the pin decision to set the pulsout variable
    rather than to jump to a section of code.

    If I'm reading inputs from multiple pins, I OR them with a nibble or byte
    variable, then check to see if the variable value is > 0. If so, I know one
    of the pins is high and then I jump to another code segment and figure out
    which one was pressed.


    Original Message

    > >Yeah, you have an endless loop in each one of your code segments that
    moves
    > >the servo. You need to perform the loop a certain number of times, then
    exit
    > >to the outer loop. Usually doing a loop 25-50 times will give the servo
    time
    > >to move from one end to the other.
    >
    > But a servo loop with a specific number of executions defeats the idea
    that
    > the servo will respond to pins 8 & 11 *when* they are activated vs X
    > iterations of a loop later. Bruce had the right idea with putting "goto
    > again" inside each loop. With that change if a given pin (8 or 11) stays
    > activated the motor will continue to move in that direction. It looks
    like
    > it is free to be pushed around by whatever load it is driving if neither
    > pin is activated. I hope that's acceptable for the application. If not,
    > another loop to center the servo (or whatever) could be made to be
    executed
    > when neither pin is activated. Many variations on this idea are possible.
Sign In or Register to comment.