Shop OBEX P1 Docs P2 Docs Learn Events
Seemed easy in theory — Parallax Forums

Seemed easy in theory

Eric REric R Posts: 225
edited 2004-11-20 05:18 in BASIC Stamp
Yesterday I started what I thought would be a simple piece of BS2 code... well, that was yesterday.

IN8·was going to be my "program enable" input,
IN11·was going to be my "toggle /·step select" input
12 was going to be pulsout.

The theory was·IF IN8=1· then everytime IN11 was toggled it would advance·a "variable" stepping 1 to 8·as follows:

IF variable = 1 THEN PULSOUT 12,960
IF variable = 2 THEN PULSOUT 12, 1200
and so on...

Once IN8=0 output 12 would toggle to a input for use·as a counter later in the program and the stored variable would then become a comparator·for the counter. This counter and comparator work fine however stepping 1 to 8 and pulsing out at each step along with storing the variable upon IN8=0 has become a burden. How would you guys handle this?

··

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-11-19 17:31
    I'm not sure I understand exactly what you want to do, but this kind of problem often can be programmed as a state machine:

       nowstate VAR bit
       oldstate VAR bit
       change VAR bit
       bark  VAR word
       oldstate = in11
      DO
         nowstate = in11
         change = nowstate ^ oldstate
         oldstate = newstate   ' update state variable
        IF change THEN
          variable = variable+1
          LOOKUP variable,[noparse][[/noparse]960,1200,  etc],bark
          PULSOUT 12,bark
       ENDIF
      LOOP UNTIL in8=0
    '  come here when in8=0
    
    



    That would, if I have it right, count on both the rising and falling edge of in11. Note that the entire DO:LOOP executes over and over rapidly, but the IF clause only executes when there is a change in in11.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Eric REric R Posts: 225
    edited 2004-11-20 05:18
    You are very close! I did find a similar method with good results. I will spend a few more hours on this trying to figure out how to store the selected "variable"·and then terminate the pulsout command after the selection is made. Thanks for your help!
Sign In or Register to comment.