Sequencer?

tmack

Member
I am looking to build what I believe is a sequencer. I would like to be able to hook up a momentary push button switch to one input of a 18x. I would then turn the output pins on to control relays to change between cameras in a remote location.For example ,when the switch is pressed once , relay 1 only is activated. When the same switch is pressed again relay 1 is deactivated and relay 2 is activated. When the same switch is pressed a third time relay 1 and 2 are now off but relay three turns on. Is this possible with the picaxe? If so can someone point me in the right direction? Thanks for any help.
 

MORA99

Senior Member
Its fairly simple, you can use a interrupt to handle the keypress, then loop there till released to avoid bounce, and then switch the relays.

Etiher with a few ifs or set a var to the relays and use high/low.
 

Tom2000

Senior Member
Sure you can do it. And it looks like it's simple and goof-proof, too. Your code might look something like the example below.'

Also - if you don't need any other functions, you can easily do this on the humble 08M. You don't need the 18X.

Good luck!

Tom


Code:
#rem

   Sequencer.bas
   
     Camera sequencer for the 18X
   
   
      PB to ground on Input 1 (leg 18), pulled up to +V with a 10k resistor
      
      Cam1 output, active high, on Out0 (leg 6)
      Cam2 output, active high, on Out1 (leg 7)
      Cam3 output, active high, on Out2 (leg 8)
      
      
#endrem


  symbol  PB     = pin1
  symbol  Cam1   = 0
  symbol  Cam2   = 1
  symbol  Cam3   = 2
  
  symbol  state = b0
  
  
  
  
Main:   

  high Cam1
  low Cam2
  low Cam3
  
  state = 0
  
  do
  
  
    'wait for button press
  
    do
    loop until PB = 0
    
    
    'debounce PB
    
    do
      pause 5
    loop until PB = 1
    pause 5
    
    
    inc state
    
    if state > 2 then
      state = 0
    endif
    
    
    on state gosub Cam1Up,Cam2Up,Cam3Up
    
  loop
  
  
end


Cam1Up:

  low Cam2
  low Cam3
  high Cam1
  
return


Cam2Up:

  low Cam1
  low Cam3
  high Cam2
  
return


Cam3Up:

  low Cam1
  low Cam2
  high Cam3
  
return
 
Last edited:

hippy

Technical Support
Staff member
Even simpler, and should work on any PICAXE, but might need tweaking.
Code:
Do
  Do : Loop While pin1 = 0
  Do : Loop While pin1 = 1
  b0 = b0 + 1 // 3
  LookUp b0,(%001,%010,%100), pins
Loop
 

tmack

Member
awesome

Awesome, thanks for the help. I am trying to run it on my basicchipsim and it keeps saying that the do,loop and inc are syntax errors. Is that because it s just on the simulator and not into the real chip? Thanks again for your help.
 

hippy

Technical Support
Staff member
Yes, that a simulator issue. Try running it through the Programming Editor simulator and you should be okay.
 

Michael 2727

Senior Member
Dippy if you had code you would only blow your
pocket money on Parts n Picaxe chips and that
would get you in trubble with the Missus. :p
 

kevrus

New Member
Although its not using a picaxe, this could easily be done using a 4017 decade counter which gives upto 10 outputs that are sequentially incremented on recieving a clock pulse (switch press)...but that takes away the fun of picaxe and the obvious versatility
 

Michael 2727

Senior Member
The only thing wrong with the 4017 is that you
must switch through every stage to get to
where you want.
With the Picaxe you could have a delayed key
entry time using COUNT /e.g. 3 Sec to hit the
exact exit point in the code you needed.
 

hippy

Technical Support
Staff member
The only thing wrong with the 4017 is that you
must switch through every stage to get to where you want.
Nah, just route Output 3 to Reset and it will cycle 0, 1, 2, 0 etc.

You'd likely also need de-bouncing and a PICAXE may actually be cheaper than getting a 4017 if one isn't to hand. The nice thing about PICAXE's (indeed any processor replacing logic ) is that it's so very easy to tailor its operation without changing hardware, and often with minimal hardware. In this case, the step can occur as the button is pushed, or after it is released depending upon preference. Short pushes and accidental double pushes can be ignored for example. It can even be driven by a PC, PDA or IR remote.
 

kevrus

New Member
Hippy, you are right about switch de-bouncing, and thats where the versatility of devices like the picaxe come into there own, often no alteration with the electronics is needed, just code. Maybe i'm still living in the dark ages of specific components for specific tasks
 

Dippy

Moderator
If you've a couple of spare legs you might think about using a 74HCT238.
This could give you some options on your sequences.

Michael: I'm hiding a number of things from the old trout right now. So don't post too loudly or she might hear. In fact I'm off to Ascension in November just to escape!
 

Michael 2727

Senior Member
Nah, just route Output 3 to Reset and it will cycle 0, 1, 2, 0 etc.
Hippy I meant you still have to go through 0 and 1 to get to 2 every time.
If the UN had a control panel with 8 outputs (0 to 7, 8 to reset) and relay
7 was aid to China, relay 5 was launch ICBMs, Oppps :(
 

hippy

Technical Support
Staff member
@ Michael 2727 : I guess I misunderstood. Proves I'm <click> <whir> Exception 009 <bzzt> <ding> human.
 

tmack

Member
Thanks Alot!

Both codes worked awesome! Better yet I even figured out why they work and how to add or delete pins. Great! Thanks alot, Its like magic when stuff works.
 

Tom2000

Senior Member
OUTSTANDING!!!

Now you can work on some enhancements:

1. If you decide to use an 18X with its extra inputs and outputs, add two more switches so you have separate buttons for each camera.

2. If you hold a button down for x seconds, start automatically scanning through the cameras.

3. This space reserved for the idea(s) you'll undoubtedly come up with after you've built the unit and start using it.

Have fun!

Tom
 
Top