NewBe Question, First -08M Project

Intro: 50 yrs old, masters in mechanical engineering, but I've been an electronics and amateur radio hobbyist since I was 10. I have a bench with scope and HP RF gear... plus the usual solder iron, DMM. I use to be a mad FORTRAN (don't laugh) programmer, but have not coded in decades.

So far I skimmed the three PICAXE manuals, downloaded the programmer and played a little with out much luck (I tried the flow chart). I have all the stuff on hand to program a chip and just need to buy a PICAXE-08A (Does Mouser have them? Best place to buy?).

The PROJECT... is to flash two 60 watt halogen lights (about 4-4.5 amps) alternating (50% duty, 90 cpm) AND also have them on both steady, as selected with a toggle switch. As well it should have an OFF position, so three patterns: Off, Steady (both), Alternating.

This is NOT in a car, but the power supply is automotive like, 14 volt DC. No doubt I will need some 5 volt regulator IC's (no big deal, suggestions?).

As far as switching the lights, it must be from the high side, so I am going to use to P channel MOSFETS (FQP27P06) driven by say two 2N2222.... the NPN's will trigger from a high signal and draw the MOSFET gate low to turn them on..... SO FAR SO GOOD.....

There are some more options I would like to explore, but the basic is one switch and three patterns (OFF, STEADY, ALTERNATE). The switch is a light duty (low amp) SPDT (center off) toggle switch. Not sure about what is better to switch with, Hi or Lo signal.... again keep in mind the power system is 12-14 volts.

Now the Questions: Is this even the right chip for this project? I already made a working 555 timer version. I also did it with multi-vibrator RC circuit with two transistors. I think the Microprocessor will simplify the circuit and give me far more flexibility and control.

Does any one have some canned code that I can copy to start with, save some time? Even if it is not exact it will be good to see how others do it.

Can the LOW direct from the PICAXE-08A pull a P-MOSFET down to trigger it direct, with out going through a bipolar signal transistor?

The baseline: OFF, STEADY (both) ,ALTERNATING (both, 50% at 90 cpm or 1.5 Hz), seems to be doable... but how much can I add? I figure with TWO OUT and THREE IN, I can have at least 7 patterns? I will need to use a rotor switch or more than one switch. The other patterns I would like to add to the baseline three is: STEADY (left only), STEADY (right only), ALTERNATING (at faster or slower rate**)

** Is there a way to add a momentary push button to
cycle through choices of ALTERNATING speeds.

Thanks for your help.... I am not expecting detailed help, but I don't want to re-invent the wheel. It seems like all this is doable from what I read. The coding will be the trick of course. Is there a good book or database on existing code to look at for ideas?
 
Last edited:

techElder

Well-known member
Why not step up to an 18M2 and make your switches TOUCH switches? You can carve them out of PCB material.

Then you can have more ways to input your pattern preference.

Why not use pulse-width-modulation (PWM) and give those lights dimming capability? Or use a light sensor input to determine how bright the light should be?

Be sure and consider the 'full-on' gate voltage on those MOSFETS. You might not be able to achieve 'full-on' with the 5 vdc supply, so you'll be level shifting and must use appropriate current limiting.

BTW, if you must use an 08 then you'll be using an 08M.
 

eclectic

Moderator
Welcome to the Forum gmcjetpilot.
This section is only for Finished projects.

Perhaps the moderators could move this thread
to the Active Forum,
where the question will be read by more participants.

e
 
Why not step up to an 18M2 and make your switches TOUCH switches? You can carve them out of PCB material.

Then you can have more ways to input your pattern preference.

Why not use pulse-width-modulation (PWM) and give those lights dimming capability? Or use a light sensor input to determine how bright the light should be?
FANTASTIC IDEAS.... BUT... We need conservative and conventional.... This is going in an experimental aircraft and toggle switches are common and give a visual indication of what is selected..... PWM is not needed either.

Be sure and consider the 'full-on' gate voltage on those MOSFETS. You might not be able to achieve 'full-on' with the 5 vdc supply, so you'll be level shifting and must use appropriate current limiting.

BTW, if you must use an 08 then you'll be using an 08M.
Right I am going to use NPN's to drive P - MOSFETS (low gate). I can't use N-MOSFET's because I want and need high side switching of the lights. It will not take much to turn on a 2N2222.

-08M is the preferred part number, got that. I read that in the manual. Appreciate it. This is really simple and trying to KISS.
 
Last edited:
Welcome to the Forum gmcjetpilot.
This section is only for Finished projects.

Perhaps the moderators could move this thread
to the Active Forum,
where the question will be read by more participants.

e
Doha! Thanks for the tip.... Yes please move Mr Moderator, sorry.
 

lbenson

Senior Member
As a fellow former FORTRAN programmer, I would suggest that you would find coding in PICAXE Basic to be not difficult to master, and more powerful and flexible than flow chart programming. In addition, most participants on this forum code in Basic and would be less likely to be able to help with flow chart problems.

The Program Editor has a very powerful simulator which will allow you to develop and test fairly complex code without any hardware.
 
As a fellow former FORTRAN programmer, I would suggest that you would find coding in PICAXE Basic to be not difficult to master, and more powerful and flexible than flow chart programming. In addition, most participants on this forum code in Basic and would be less likely to be able to help with flow chart problems.

The Program Editor has a very powerful simulator which will allow you to develop and test fairly complex code without any hardware.
Yep I have some of the old knack back, kind of (in a rusty sorta way). I just sat down for an hour or two (pretty sad but I am rusty) and flow charted it with Logicator. I could not get the analog inputs panel to work in simulation with Logicator, so I worked around that. I saved the BAS file.

Then I opened up the BAS file in the PICAXE program, which does have a good simulator, works like a charm. A little fine tune, the Beta version is not half bad. Once I get it where I want, I'll post it for a laugh. I used 121 bytes out of 256... pretty sad. I can reduce that I am sure, but for now I am thrilled. It was easy. I still want to code direct, but the flow charting is nice.

I have to work on a scheme to "poll" the switches (inputs). With the simulator, it takes forever to go through the main routine to POLL the input (switches). I am sure the chip, even at a slow 4 Mhz will not be as noticeable. When I get a chip on the breadboard, I can see how "efficient" the code needs to be. Right now I am polling the switches (inputs) in each sub-routine so it does not have to run through all main routine each time. However even after changing the input it has to loop though the IF a few times before going back to the main routine.... Again simulator is very slow. But if it is relative and proportional the code can be better.

I am using LOW input switching, which seems better?
OFF = HI HI HI (inputs 1 2 3)
On (both steady) = LO HI HI
FLASH (normal) = HI LO HI

I could add (if I have enough program and memory)
On left only steady = LO HI LO
On Right only steady = LO LO HI
FLASH (faster) = HI HI LO

The only down side is how to do this with a switch. It gets to the point I need a rotor switch....

BTW How do you program a BUTTON push to change a pattern? Once you do that can you save that into memory so when it powers up it will remember what routine to use?
 

lbenson

Senior Member
As a programming example, try the following in the simulator. It should do what you have specified (to the degree that I understood). I used "symbol" definitions to try to make the program clearer.

Code:
#picaxe 08m
let dirs = %10001   ' set pins 0, 4 output; 1,2,3 input

symbol blinkRate = w6 ' (made up of b12 & b13)
symbol pinState = b11
symbol LED1on = bit0  ' binary value 0/1 = off/on
symbol LED2on = bit1

symbol LED1 = 4    ' pin for LED1 (left)
symbol LED2 = 0    ' pin for LED2 (right)

symbol fastBlinkTime = 200
symbol slowBlinkTime = 500

symbol offSignal = %111
symbol onSignal = %110
symbol flashSignal = %101
symbol rightOnSignal = %100
symbol fastFlashSignal = %011
symbol leftOnSignal = %010
symbol unused1Signal = %001
symbol unused2Signal = %000

blinkRate = 0

main:
  do
    pinState = pins / 2 ' shift to low 3 bits
    select pinState
      case offSignal       ' both off
        low LED1, LED2
        LED1on = 0
        LED2on = 0
        blinkRate = 0
      case onSignal        ' both on
        high LED1, LED2
        LED1on = 1
        LED2on = 1
        blinkRate = 0
      case flashSignal     ' both flash slow
        LED1on = 1
        LED2on = 1
        blinkRate = slowBlinkTime
      case leftOnSignal    ' LED1 on
        LED1on = 1
        LED2on = 0
        blinkRate = 0
      case rightOnSignal   ' LED2 on
        LED1on = 0
        LED2on = 1
        blinkRate = 0
      case fastFlashSignal ' both flash fast
        LED1on = 1
        LED2on = 1
        blinkRate = fastBlinkTime
      case unused1Signal, unused2Signal
    end select
    if LED1on = 1 then 
      high LED1
    else low LED1
    endif
    if LED2on = 1 then 
      high LED2
    else low LED2
    endif
    if blinkRate > 0 then
      pause blinkRate
      low LED1, LED2
      pause blinkRate
    endif
  loop
I'm not sure what you mean by the slowness of the simulator. By machine standards, it is very slow, of course. By human brain standards (at least for this human brain) it is fast, and it is necessary to pause it and use single stepping to see exactly what the program is doing.

The command, "pinState = pins / 2" gets the values of pins 3,2,1 into the lower 3 bits of the variable. This is then used to determine the signal state to set the LEDs with the "case" statement. I use the bit variables bit0 and bit1 to retain the on/off state of the left and right LEDs. Note that bit0-bit7 constitute variable b0, which combines with b1 to make up the word variable, w0.

Note that a 4mHz PICAXE will run approximately 2,000 to 4,000 Basic instructions per second.
 
Last edited:
As a programming example, try the following in the simulator. It should do what you have specified (to the degree that I understood). I used "symbol" definitions to try to make the program clearer.

I'm not sure what you mean by the slowness of the simulator.... Note that a 4mHz PICAXE will run approximately 2,000 to 4,000 Basic instructions per second.
Very dumb comment on MY part. Ha ha! Yea the simulator is slow so you can see it. That is the purpose and handy. The Logicator program lets you speed it up, I discovered. Disregard. It was just in a flashing routine of 50% duty, it took so long to loop back it was flash flash (off) pause. In my program below I loop each pattern and "poll" the inputs for that one switch logic; verses going to the top to check all of them input patterns. In a the processor -08M I would not notice the pause I am sure, even at 4 Mhz. Disregard.

Your CODE is brilliant, appreciate (very much) your effort. You customized it. I spent time watching it on the simulator, BRILLIANT! :) I need to sit down and read the manual more. I like defining variables or assigning labels to constants. Just for grins this is my first PIXAXE code (don't laugh).

Code:
'BASIC converted from Logicator for PICAXE flowsheet:
symbol varA = b0
symbol varB = b1
symbol varC = b2
symbol varD = b3
symbol varE = b4
symbol varF = b5
symbol varG = b6
symbol varH = b7

let dirs = %00010001

main:
label_314:	low 0
		low 4
		if pin1 = 0 and pin2 = 1 and pin3 = 0 then label_307	'Decision command right 
		if pin1 = 0 and pin2 = 0 and pin3 = 1 then label_316	'Decision command left
		if pin1 = 0 and pin2 = 1 and pin3 = 1 then label_309	'Decision command both
		if pin1 = 1 and pin2 = 0 and pin3 = 1 then label_311	'Decision command flash
		goto label_314

label_311:
		do while pin1 = 1 and pin2 = 0 and pin3 = 1	' repeat flash
		high 0
		pause 333	'Wait command
		low 0
		high 4
		pause 333	'Wait command
		low 4
		loop		'End of repeat loop 

		goto label_314

label_309:
		do while pin1 = 0 and pin2 = 1 and pin3 = 1	' repeat steady both
		let pins = 17	' %00010001
		loop		'End of repeat loop 

		goto label_314

label_316:
		do while pin1 = 0 and pin2 = 0 and pin3 = 1	' repeat steady left
		let pins = 16	' %00010000
		loop		'End of repeat loop 

		goto label_314

label_307:
		do while pin1 = 0 and pin2 = 1 and pin3 = 0	' repeat steady right
		let pins = 1	' %00000001
		loop		'End of repeat loop 

		goto label_314
One thing that is obvious with a toggle switch, I can only get three positions, OFF, BOTH, FLASH... since most standard toggle switches, at most, have three "THROWS". I could use a 3 pole ROTARY Switch... That would access all 6 patterns (OFF, LEFT, RIGHT, BOTH, FLASH SLOW, FLASH FAST). Not a bad option.... but I want to explore momentary BUTTON pushing to access all patterns..

To get all 6 patterns with one TOGGLE I could use a center off, momentary UP and DOWN switch .... (On)-Off-(On). Where initial state is OFF (output 1, 2 low):

1st UP Both
2nd UP Left
3rd UP Right
4th UP OFF (repeat)

1st DN Flash Slow
2nd DN Flash Fast
3rd DN Flash Fastest
4th DN OFF (repeat)

The Down side:
Switch position does not tell me what is selected?
To turn Off you must cycle the momentary switch several times?
You really never know how many times to push to get to OFF? **
** Of course at night you can see the lights flashing or on steady.
However these may be used during the day as well for safety, and you
can't see them. So switch position is the only indication. Not really
acceptable. The following switch option seems best because it has a
hard OFF.


The BETTER (BEST) OPTION is the standard three position double pole toggle switch (OFF, STEADY BOTH, FLASH FAST) switch. Then have a push button (optional) to cycle through the STEADY and FLASH patterns.

Pins 1 and 2 would be used for basic modes (OFF, STEADY BOTH, FLASH FAST) and Pin 3 would be a "COUNTER" to determine what Sub to use:

(X is memory = 1, 2 or 3 based on button push pin 3, resets to 1 if over 3)

OFF : HH + (X = any) or LL + (X = any) The default is off if you will, resets X=1.
BOTH : LH + (X=1)
LEFT : LH + (X=2)
RIGHT :LH + (X=3)

FLASH : FAST HL + (X=1)
FLASH : SLOW HL + (X=2)
FLASH : FASTEST HL + (X=3)

(7 patterns, add FLASH FASTEST to keep button pushes equal for steady and flash.)
(After two button pushes it cycles back to 1 as long as the toggle is not OFF.)

The above is ALL to simplify switching. I'd still have some "MYSTERY" as to what
was selected, but OFF would be OFF and would reset it. To access the basic three:
(OFF, STEADY BOTH, FLASH FAST), you don't NEED the button.

To get at the other other patterns you select STEADY or FLASH and push the
button once or twice (third time cycles back). The default (X=1) gives the most
desired "EXTRA" pattern, so ONE PUSH will be all that is needed, normally. To
get at the other pattern, push button twice.

Example: FLASH FASTEST - toggle to FLASH and push button twice. To turn off
just select OFF with the toggle.

I searched the forum for BUTTON pushing and NOT sure how to handle memory and
IF statements yet.... The flow chart method to "auto code" is somewhat limited
(and not perfect I found). However it is a nice tool to learn and get started (again).

They did not have any of these tools when I was coding for MAIN FRAMES! You
used pencil and paper to flow chart, code, run, failed, repeat.... until you got it
right.

You already did enough, I thank you, but can you give me some subroutine ideas
how to do latter switch logic? The momentary "button pushing" seems to take
"technique" and some experience to get to work right. The "BUTTON" command
may not be the right choice as I read it.


PS: I am not sure on INPUT, low switching. How do I tell the inputs (pins 1, 2, 3)
to be normally at high state. Do I need to provide +volts and pull down RESISTOR?
Do I need a PNP transistor to pull the Pin down? They must have this integrated?
 
Last edited:

lbenson

Senior Member
A 6-position rotary switch would work, but you would need more inputs than the 08M provides. The 14M would give you everything you need. Appendix C of Manual 1 shows the advanced features of the 14M, including the use of port C to give you 6 inputs.

I've never used a rotary switch, but I assume that a 6-position one would have 7 pins--one common and 6 output. With typical picaxe pin switch connections, you would put a current-limiting resistor of, say 1K, between the common pin and 5V, and pulldowns to 0V of, say, 10K on each of the positions which are connected to pins C0-C5 (the pulldowns prevent false triggering from floating pins).

Unfortunately, you can't read the state of Port C on the 14M (no "pinState = pinsc"--see this thread for reference: http://www.picaxeforum.co.uk/showthread.php?t=11809 ). On a real chip you can work around this with "peek $07,pinState".

To simulate here, I used pin3 as a pushbutton to cycle through the 6 pinState values. You have to push pin three on, and then push it again to off to change pinState. Again, on a real chip, you can use "peek $07,pinState".

Code:
#picaxe 14m
let dirsc = %000000 ' set the 6 portC pins to input

symbol blinkRate = w6 ' (made up of b12 & b13)
symbol pinState = b11
symbol LED1on = bit0  ' binary value 0/1 = on/off
symbol LED2on = bit1

symbol LED1 = 1    ' pin for LED1 (left)
symbol LED2 = 0    ' pin for LED2 (right)

symbol fastBlinkTime = 200
symbol slowBlinkTime = 500

symbol offSignal = %1
symbol onSignal = %10
symbol flashSignal = %100
symbol rightOnSignal = %1000
symbol fastFlashSignal = %10000
symbol leftOnSignal = %100000

blinkRate = 0
pinState = 1

main:
  do
'    pinState = pinsC ' see where rotary switch is set
'    Peek $07,pinState " see: http://www.picaxeforum.co.uk/showthread.php?t=11809
    if pin3 = 1 then ' for simulation: toggle pin3 on and off
      do while pin3 = 1: loop
      pinState = pinState * 2 ' shift left one bit
      if pinState > leftOnSignal then: pinState = 1: endif
     endif
    select pinState
      case offSignal       ' both off
        low LED1, LED2
        LED1on = 0
        LED2on = 0
        blinkRate = 0
      case onSignal        ' both on
        high LED1, LED2
        LED1on = 1
        LED2on = 1
        blinkRate = 0
      case flashSignal     ' both flash slow
        LED1on = 1
        LED2on = 1
        blinkRate = slowBlinkTime
      case leftOnSignal    ' LED1 on
        LED1on = 1
        LED2on = 0
        blinkRate = 0
      case rightOnSignal   ' LED2 on
        LED1on = 0
        LED2on = 1
        blinkRate = 0
      case fastFlashSignal ' both flash fast
        LED1on = 1
        LED2on = 1
        blinkRate = fastBlinkTime
    end select
    if LED1on = 1 then 
      high LED1
    else low LED1
    endif
    if LED2on = 1 then 
      high LED2
    else low LED2
    endif
    if blinkRate > 0 then
      pause blinkRate
      low LED1, LED2
      pause blinkRate
    endif
  loop
On a real chip, you would probably want to time how long a rotary switch stayed on so that you didn't flash incorrectly as you were turning to the position desired. Alternatively, perhaps there is a rotary plus momentary which would obviate that need (turn to desired position and press button).

You could also do this with two pushbutton switches--one to cycle through the options as in this program (perhaps shown by LEDs), and the other to select/activate.
 
Last edited:

lbenson

Senior Member
Regarding your code, I assume it is based on what Logicator outputs. That's fine, but if you want to understand it at a later time, you might want to change some things.

The labels look generated--it would be best to change them to something meaningful.

The defined symbols, ArgA through ArgH, are never used. You might want to delete them. If you do define symbols, give them meaningful names--ArgA is no more significant than b0.

Indentation of code is a personal preference. I personally don't like deep indentation as in the program shown. I find that two spaces is sufficient, and more get in the way if deep levels of conditions are needed (not typical in a picaxe program, and certainly not on the smaller chips). There should also be indentation of code within control structures (if...then...endif, do while...loop, for..next).

Some people like to align comments. I tend not to, because there will always be statements too long to get the comments in the intended place. Then do you go back and change the others? I just let the comments fall where they may (but use plenty of them so that you can understand your own code if you go back to it in two weeks).
 

westaust55

Moderator
A 6-position rotary switch would work, but you would need more inputs than the 08M provides. The 14M would give you everything you need. Appendix C of Manual 1 shows the advanced features of the 14M, including the use of port C to give you 6 inputs.
You can use a 6 posiiton rotary switch and stay with the 08M.

Just set up a potential divider with say the 6 positions as:
pos6 = Vcc
pos1 = 0V
then across the contacts from pos1 to pos2, from pos2 to pos3, etc, connect a 2k2 Ohm resistor.

Then feed the common contact into an ADC enabled pin and read of the value with READADC which is then used as a selection for the mode of operation.

READADC pinNo, bytevar

mode = bytevar / 50 ; mode = 0 for pos0, 1 for pos1, etc to 6 for pos 6
might need to change that divider value (50) down slightly depending upon resistor accuracy to accound for slight voltage drift at the switch posiitons
 
Last edited:

lbenson

Senior Member
With westaust55's hardware solution, the code for my program for determining pinState would be something like this:
Code:
  readADC 1,pinstate
  pinState = pinState + 25 / 51
This will result in pinState values between 0 and 5, and should account for slight variations in the voltage dividers (testing is advisable). offSignal, etc. would have to be redefined to reflect those results, 0-5. Nothing else in the program would need to be changed.

The manipulation of the result of the ADC readings would be the following:
0-25 -> 0
26-77 -> 1
78-127 -> 2
128-178 -> 3
179-229 -> 4
230-255 -> 5

The results of the voltage divisions (the ADC readings) should fall in about the middle of the ranges. You don't need to worry that a reading of 255 + 25 will overflow a byte variable, because intermediate values in a calculation are kept as words, and the division by 51 brings the result back down to a value suitable to the variable in which it is stored.
 
Last edited:
I've never used a rotary switch, but I assume that a 6-position one would have 7 pins--one common and 6 output.
Right! The rotary switch would have THREE POLES, one for each input pin. The common is connected to one of the 6 position contacts, so there 3 x 6 = 18 pins. In any of the six positons I can signal (ground) any pin or none at all.

If I used a second ON/OFF toggle, I could get by with a 4 position (2 pole) rotary switch, much cheaper. So when the toggle is ON it grounds the rotary switch. This gives me four positions, L, R, STEADY, FLASH. The toggle would take care of OFF. The on off switch could also be DPDT and cut power off to the LIGHT MODULE and turn the PICAXE off, and also turn off the power to the MOSFET power transistors, verses having the program just run to keep the lights off.

With typical picaxe pin switch connections, you would put a current-limiting resistor of, say 1K, between the common pin and 5V, and pulldowns to 0V of, say, 10K on each of the positions which are connected to pins C0-C5 (the pulldowns prevent false triggering from floating pins).
Thank you that makes sense! My intent is to have all input pins at something like 3-4 volts.... The switch will pull it down with a resistor to ground...

Unfortunately, you can't read the state of Port C on the 14M (no "pinState = pinsc"--see this thread for reference: http://www.picaxeforum.co.uk/showthread.php?t=11809 ). On a real chip you can work around this with "peek $07,pinState".

To simulate here, I used pin3 as a pushbutton to cycle through the 6 pinState values. You have to push pin three on, and then push it again to off to change pinState. Again, on a real chip, you can use "peek $07,pinState".
I was thinking of a MEMORY COUNTER, up one each push of button. The program would need to "poll" pin 3 (for example). As long at it's HI nothing... the IF statement just does nothing. This would be a subroutine peppered all over to monitor pin 3. There would be a need to do some pause or interrupt when it sees Pin 3 go LO, it adds one per push. This will cause the program to run different sub-routines for different light patterns, based on the other two pins (1 and 2) being HI or LO and the count of the memory.

On a real chip, you would probably want to time how long a rotary switch stayed on so that you didn't flash incorrectly as you were turning to the position desired. Alternatively, perhaps there is a rotary plus momentary which would obviate that need (turn to desired position and press button).
The other switch work around is a two pole, three position rotary, 1, 2, 3, PLUS a toggle switch, OFF, STEADY, FLASH. The toggle will control ONLY pin three. Think of it as a multiplyer. Pins 1 and 2 give me 4 patterns. With pin three that is 4 x 2 or 8 patterns...

With toggle in OFF nothing happens. With it in steady and the "LOGIC" from the rotary switch you get steady L, R, BOTH. With the toggle in Flash, you get FLASH SLO, MED, FST, based on rotary switch. Two pins gives us 4 patterns: 11, 00, 01, 10 PLUS pin three we get:

111, 001, 011, 101 Steady
110, 000, 010, 100 Flash

The program logic (pins 1, 2, 3) would be:
111 or 110 = Off
001, 011, 101 = Steady: L, R, Both
000, 010, 100 = Flash: Slow, Med, Fast

With the toggle in the off position it disconnects the rotary from ground. So the rotary switch is inactive. It is a secondary selector and can be left or "PARKED" in any of the position. The toggle will give you two favorite light patterns one STEADY one FLASHING. So when the toggle is turned from OFF to either FLASH or STEADY you get what the rotary switch is set to. If you want something different you move the rotary switch. To turn off, it just one toggle throw. To turn on to flash or steady one toggle throw.

Then there's just being happy with one toggle OFF, STEADY and one FLASH (as I originally had). :D: :rolleyes: (I am having microprocessor inflation, just because you can does not mean you should, ha ha.)

Seriously the most useful is OFF, LEFT, RIGHT, BOTH, FLASH (alternate). That could be done with a three pole, 5 position rotor switch. High quality ones get expensive as the poles and positions increase. It is going into an airplane, so I don't want a $2.95 toy switch. It has to be understood by the pilot with out a PhD in "SWITCHOLOGY".

The fact of life if I want absolute control over many functions or patterns, the switching will get more involved, to where one toggle is not going to hack it. Two toggles three pole double three throw toggles could "LOGICALLY" be made to give 6 positions, but then you get into SWITCH LOGIC. In a plane if you want to select landing lights, you don't want to throw have have to figure it out. How many times to push this, push that? You want OFF to be one step not three, ideally. Some "HUMAN FACTORS" to think about.

You could also do this with two pushbutton switches--one to cycle through the options as in this program (perhaps shown by LEDs), and the other to select/activate.
That is another option. What do you think about using "BUTTON PUSHING" to control a memory count to control the program?
 
Last edited:
These are the choices.... which one do you like best. Option one is less capable. Options 2 through 4 are equal. Option 5 is the Christmas tree,
full of options. None of these use button pushing. I like the idea of button pushing cycling through the "menu" of options, like option five, but the button replacing the rotary selector.

 

techElder

Well-known member
I don't know ... there's just something wrong about rotary switches, toggle switches and microprocessors.

Perhaps it's due to my experience for 50+ years with corrosion, switch-bounce and noise.

I don't know ... :D
 

lbenson

Senior Member
I can't really comment on the mechanics of it, much less on the advisability of putting such a circuit in an airplane (all the safety precautions for automotive use and more would apply, I would suppose).

If you wanted to be able to flash right and left independently, then perhaps a rotary switch with RIGHT, LEFT, BOTH, OFF, and a toggle with STEADY, FLASH or STEADY, FLASH, FAST FLASH.

Or perhaps three toggles--LEFT/OFF, RIGHT/OFF, STEADY/FLASH/FAST FLASH (but then you're talking 4 or 5 picaxe pins--14M time).

You would certainly need to address switch bounce and momentary activation as you turned a rotary switch.

I don't understand about the 18-pin, 3-pole rotary switch--a diagram would help there.
 
Last edited:

hippy

Technical Support
Staff member
I don't know ... there's just something wrong about rotary switches, toggle switches and microprocessors.

Perhaps it's due to my experience for 50+ years with corrosion, switch-bounce and noise.

I don't know ... :D
When it comes to real world products - and this is a fine example - there's often no choice as its the ergonomics which are the key feature, the microprocessor is secondary in many respects.

Personally I reckon the entire design should be driven from the ergonomic perspective; what's most logical for a pilot and what do they actually need. Some of the drawn options seem poor; not clear or not logical ( left not on the left ).

The problem perhaps is that there's no easy combination which can be represented by a simple switch or a rotary switch which gets from one setting to another without undesirably going through some other setting. I'd personally build a joystick-type switch in a slotted-"plus" style ...

centre - both off
left - left on, right off
right - right on, left off
up - both on
down - both alternatively flashing

Maybe swap up and down function. Put LED's to the left and right so you can see what's happening and selected, and add a flash rate rotary pot.

A latching mechanical switch would I think be best as it gives visual feedback as to its setting. Some some bias springs and catch brackets might allow an analogue joystick to be used. You could use a return to centre biasing or even replace the centre and four points with momentary push buttons.
 
I don't understand about the 18-pin, 3-pole rotary switch--a diagram would help there.
It would look like this in a schematic..... this is a three pole, 6 postion switch.
3 x 6 position is 18 contacts or "pins". The three poles, plus the 18 contacts
is 21 total terminals on the back (side) of the switch. This is what it looks
like in a schematic.



Three toggle, simple ON OFF switches would be "standard" aircraft switching.
 
Last edited:

eclectic

Moderator
It would look like this in a schematic..... this is a three pole, 6 postion switch.
3 x 6 position is 18 contacts or "pins". The three poles, plus the 18 contacts
is 21 total terminals on the back (side) of the switch. This is what it looks
like in a schematic.
Do you have a datasheet link?

e
 

lbenson

Senior Member
I'm with eclectic. I'm afraid that drawing didn't help me any. Is this rotary switch also an 8-to-3, or 6-to-3 encoder? Are you relying on "weak pullups" in the chip to overcome floating? (Are there weak pullups on the 08M?)
 
Do you have a datasheet link?e
Standard stuff on das google land. Just google X pole X position rotary switch. Or 3P5T
for example for 3 pole 5 throw...

They typically come from cheap ($5) to very expensive ($125). The amp rating is
typically under an Amp at 125 VAC, but we are talking under a 1mA draw. They have
other rotary switches with higher amp ratings, BIG industrial things. Being a plane small
and light and reliable is needed. I am leaning to the THREE SPST (single pole, single
throw) toggles. See the picture I updated my last post in this thread.

The down side is ideally I need a 3 Pole, 6 position switch. I can't find that except
surplus. I can find 4 pole 6 throws. I can find 3 poles 4 throws. They make a 3P6T
switch, but finding one at a good cost, that is not huge or heavy is the trick. I found
a nice surplus ceramic 3P5T switch for $20, but I am not sure about using a rotary
switch at all. I can use three relatively robust toggles to switch this. The idea of just
having OFF, STEADY (both), FLASH (both alternating) is good enough. That can be
done with one DPDT toggle....
 
Last edited:
I'm with eclectic. I'm afraid that drawing didn't help me any. Is this rotary switch also an 8-to-3, or 6-to-3 encoder? Are you relying on "weak pullups" in the chip to overcome floating? (Are there weak pullups on the 08M?)
You lost me as well. Seems we have disconnect. Lets see if we can reconnect.
Sorry I can't make the switch schematic any simpler.... let me see if I am missing
something, so excuse the very basic explaining. It is for me. It seems very simple
to me, but I could be missing something. Lets go to basics.

I'm doing a PULL DOWN to trigger the inputs, as I explain below.The rotary switch
I show, in the picture, previous post, depending on what position, 1 through 6 will
either keep one of the three POLES, OPEN or GROUND (though 1K resistor). This is
based on how you wire the switch. Leave a postion open it is open. Wire a postion
to ground it is to ground. When you select that postion you will make three
connections, three poles. It will be either open or ground. Obviously I can put postive
power on these postions. There will be no floating since the inputs are at 5 volts.
(See discription below)


As far as the switch, it just GROUNDS (through a 1K resistor) pin 1, 2 or 3.
That is it, easy, simple nothing complicated. All three input pins 1, 2, 3 are fed
with a ~5 volt signal, from the voltage regulator via a 10K resistor.
The two
resistors 1K and 10K is just a simple voltage divider....

Normally OFF (pins high) is ~5 volts
5 volt-----10K-----Picaxe pin (1)-----switch is OPEN
5 volt-----10K-----Picaxe pin (2)-----switch is OPEN
5 volt-----10K-----Picaxe pin (3)-----switch is OPEN

Normally ON (low) is going to be ~0.45 volts
5 volt-----10K-----Picaxe pin (1)-----1K-----ground though switch
5 volt-----10K-----Picaxe pin (2)-----1K-----ground through switch
5 volt-----10K-----Picaxe pin (3)-----1K-----ground through switch

With a solid 5 volt on the input there is no ambiguity/float.
When I pull the pin to low, I don't know about bounce, but
it should not affect the operation? If there is some transient
thing, might a capacitor fix it, so the switching is a buffered,
slower change from Hi to Lo. This is the easiest way to do
this in my way of thinking. Once I prototype it I can tell how
it will work.... am I driving off a cliff?


It's just a voltage divider. The total current V=IR :: I = V/R
5 volts /11K = 0.00045 amps or 0.45 milliamps! If I make the
1K, 500 ohms the current does not go up much and voltage
at pins is about half, 0.23 volts. I don't know the trigger
thresholds but I can make it even lower. A 100 ohm resistor
to ground would be 0.49 milliamps and and Lo of 0.05 volts.

A 5 volt LM1117 regulator is good for 800 mA. With all three
pins on low we are talking about 1.5 mA~ This seems to be
easy.... again this is for me. I don't know how the PICAXE-08M
handles it's analog inputs but assume it is a voltage, and that
it is programmable? By the way I assume I have 3 analog inputs
available as well. There are 5 I/O pins with some restriction, like
pin 0 always has to be OUT and pin 3 is always IN. The other
three pins are are Vcc, Vo, RXD.....

The program has "If statements" based on pin 1, pin 2 and pin 3
being High or Lo. Based on that it runs different routines that will
turn ON or OFF pins 0 and 4 as I programed.
 
Last edited:

lbenson

Senior Member
Ok, your schematic didn't show the 10K pullups, so I thought the inputs might be floating when not switched low.

By a rotary switch "encoder", I meant something like a mechanical version of the 74LS148 8-line to 3-line encoder, and it seems to me that your use of the rotary switch implies that (perhaps that is standard). In plain language that means you have 6 binary values encoded into three lines--just what the 74LS148 does electronically for up to 8 values.

There is no problem in doing so, but just for the sake of information, why do you choose low switching rather than high (0V means the option is selected)? Perhaps this has some historical grounding.

As with eclectic, a reference to an appropriate part might enlighten me further on how this rotary switch works.
 
Please, can you say
Exactly
what the switch is?
I told you to google it. Did you even try?

I have no clue what you mean, "Exactly". It's like asking can you explain a
sunset exactly. There are all kinds of sunsets. There is no one kind of switch.
There are slide switches, toggle switches, rocker switches and rotary switches
(to name a few of 100's of types). In the end they are switches.

You really should just google rotary switch, but to explain it, it's a switch;
it opens and closes an electrical circuit with a mechanical switch. There are
contacts the open and close. Some contacts move apart, some contacts slide.
Rotary switches typically use sliding contacts, but you could have a cam,
opening and closing microswitches or plungers....

I can't explain it any more than I can explain "What is love"? :D It's just a
switch my friend, with a two contacts to MANY. Some can handle one circuit
at a time, other rotary switches handle many circuits in parallel at the same,
depending in the design. Sky's the limit! I did the google for you. Here are some
links I hope it helps.

http://en.wikipedia.org/wiki/Rotary_switch
http://en.wikipedia.org/wiki/Switch

This is typical of a "wafer" switch.


Some switches use a wafer (phenolic) or ceramic for insulators. Some use plastic or
nylon... This is an open frame where there is no housing, you can see the contacts.
Good for leaning, bad for getting dirty. They have sealed ones as well, or "closed
frame". They all feature some kind of shaft you turn with a knob. There are usually
detents for each position, "click, click, click". The above picture show a one deck and
two deck version. You can have two poles or more per deck.

These are closed frame versions where the insides are shielded. This one
has military or aerospace not coast limit written all over it, may be $1000's?
(The spelling in the pic is some one else's... whats a "Rotarty"? ha ha.)



This one is made of plastic, including the shaft... would not put it in a toy,
about $4.00 on eBay. However it will be light and may last a long time. It's
not rated for AMPS. Again google image "rotary switches". Cheers

 
Last edited:

lbenson

Senior Member
Sorry if I seem obtuse, but I think the question is, at least my question, not "What is a rotary switch" in general, but "What is the part number of a switch which has the characteristics you are looking for--6 (or 8) positions and output encoded in 3 lines?" And one hopes that an informative data sheet would be available (unlike for the rotary switches found at Jameco).

But this is obviated if you want to go with toggles.
 

lbenson

Senior Member
For instance, here is a Mouser 6-position, 3-deck, 1-pole-per-deck rotary switch--the only one ($127.23 with 4-week lead time).

http://www.mouser.com/ProductDetail/Electroswitch/D7C0306N-60/?qs=vmaJ%2bUOuvax%2bBWGuk/Uuvw==

It has an awful lot of pins. If it's encoded, then with pullups/downs, why would you need more than 4 pins--common, outputs 0, 1, 2? The data sheet doesn't show any truth table for it--maybe it's obvious--0=000, 1=001, etc--but which are the output pins.

This is a case where they assume that you already know what you are getting.

I'm not a hardware person, so I have no idea from the data sheet how this part would work, or which different part you would be looking at.

Sorry if this is a diversion into older technology which has mostly been phased out. Hey, how about a GLCD screen with capacitative touch? (kidding)
 
Last edited:
Sorry if I seem obtuse, but I think the question is, at least my question, not "What is a rotary switch" in general, but "What is the part number of a switch which has the characteristics you are looking for--6 (or 8) positions and output encoded in 3 lines?" And one hopes that an informative data sheet would be available (unlike for the rotary switches found at Jameco).

But this is obviated if you want to go with toggles.
Sorry, I was having fun ranting.... yea no particular part number has been spec'ed..... I googled the heck out of it, looked at Mouser, Digikey, Newark. The manufactures that keep coming up are C&K, Electroswitch...

Panel mount $22
http://www.electro-nc.com/rotaryus/c4.pdf
PCB mount $40
http://www.electro-nc.com/rotaryus/d2.pdf

C&K down load the rotary switch catalog
http://www.ck-components.com/a/rotary,10517,en.html

The frustrating part is they don't have much in three pole. What they have is 4 position at max. There is a lot of double pole 6 position switches.

I am kind of over using a rotary switch. I am going to use ONE toggle, OFF, BOTH, FLASH.... That is it. I am not going to worry about Left and Right. If I want I can use the one DP3T toggle or use three simple SPST on-off toggles... LEFT, RIGHT, FLASH. Simple and impossible to confuse by the pilot. With three switches I get all 8 combinations, but it would take a CHART to figure it out. No thanks.... I think the one switch will work for the basic three functions. That's it NO TO ROTARY! Ha ha!

These are not my panels, but it will give you an idea of an experimental (kitplane) panel. This is for a RV-7. You can see toggles or rocker switches are the norm. However the Boeing 757, 767 has lots of rotary switches in the over head (which I fly). A rotary would work, give positive indication of operation, if the panel is labeled well.... LIGHTS? ON-OFF, UP-DOWN, dumb simple, no need to figure out what switch. Having more switches looks cool. ;) Since I am not switching the actual +4 amp lamps with the switch, I can use mini switches. It's not going to save much weight. You tend to match the switches so they look the same, but the option is there.



This one has more toggles... so it looks cool! :rolleyes:


Typically 8 to 12 switches gets the job done for a small plane... less is more.
 
Last edited:
Ok, your schematic didn't show the 10K pullups, so I thought the inputs might be floating when not switched low.

By a rotary switch "encoder", I meant something like a mechanical version of the 74LS148 8-line to 3-line encoder, and it seems to me that your use of the rotary switch implies that (perhaps that is standard). In plain language that means you have 6 binary values encoded into three lines--just what the 74LS148 does electronically for up to 8 values.

There is no problem in doing so, but just for the sake of information, why do you choose low switching rather than high (0V means the option is selected)? Perhaps this has some historical grounding.

As with eclectic, a reference to an appropriate part might enlighten me further on how this rotary switch works.
I get it, he was asking for a PART NUMBER.... Why did he not say that? :p

There is no need to get into a part number, really trust me. They are all the same, all of them.... You have to believe me, it's moot to SPEC out the exact model, it does not change the electrical switching. What is the difference between a 3 pole 6 position rotary switch made by C&K and one made by Electroswitch? Yes they may look different, have different ratings, but they work the same. The drawing I showed you is for three poles 6 positions.... there is no variation unless they are "shorting" type, which the schematic did not indicate.

But this is obviated if you want to go with toggles.
Yea I know. This is a work in progress and you all want me to have final drawings and manufacturing started. Ha ha. It's in the planning stage and things change, for the good. Like the PUSH BUTTON brain storm we passed through. This is the nature of design. "Thought Experiments", think of different things and imagine how they work (or don't), but again as usual KISS wins.


The word ENCODER means a totally different thing to me... In a plane there is a piece of avionics that you set a CODE in so radar can identify you positively. I never called a rotary switch ab ENCODER.

Why PULL DOWN or low signal? The aircraft is a NEG ground system. It is easy to ground the switch than route positive power to it. That is a PIA, and you have to watch voltages. You have to supply the switch with voltage. With the ground approach you just need a ground for the switch. keep in mind the switch is in the panel and the controller is in a different place. This is not all in one box. Lights are 20' away, the switch or switches are a few feet away. It all is living in a metal plane (common ground) and 14 volts DC.

The "PULL UP" is not shown, true. That is in the box of magic I labeled LIGHT CONTROLLER! Ha ha. Again we get bogged down in terminology, and based on our conversation before I thought that was clear. If I am PULLING DOWN, there is assumed some voltage to pull down..... "PULL UP" indicates you are triggering with a HIGH SIGNAL (like a NPN transistor), which can be more of a PIA... I can see some one feeding the signal with 15 volts... OUCH!

That reminds me, I am debating how much protection, fuses, diodes, over voltage, MOV's... to put into it. The module will be fused. The lights will be also fused (actually CB's).
 
Last edited:

techElder

Well-known member
You don't need a computer to do that ... just some relays.

I am kind of over using a rotary switch. I am going to use ONE toggle, OFF, BOTH, FLASH.... That is it. I am not going to worry about Left and Right. If I want I can use the one DP3T toggle or use three simple SPST on-off toggles... LEFT, RIGHT, FLASH. Simple and impossible to confuse by the pilot. With three switches I get all 8 combinations, but it would take a CHART to figure it out. No thanks.... I think the one switch will work for the basic three functions. That's it NO TO ROTARY! Ha ha!
 
You don't need a computer to do that ... just some relays.
Well NO!
A relay is $20*
Don't last as long
Not as rugged or reliable
Takes more power (trust me)
To get it to do what I want takes complicated (high amp) switching, diodes, barf.

Google: http://www.ehow.com/facts_5814616_electronic-vs_-mechanical-flasher-relay.html

* Can make a solid state "computer" Light Controller for less than $15! **
-08M ($3), two NPN's ($0.20/ea), two MOSFETS ($1.00/ea), LM1117T-5 ($1.00),
handful of resistors and caps (~$2), box & connectors ($5). Taa Daa!

** Making it yourself, priceless~!

To get, off-both-flash with a RELAY takes mechanical
switching; that means many toggle switches, to get what
I can do in one switch. I already went down the mechanical
relay road. The "computer" will give me more options a "relay"
can't. I am curious do you yell out at weddings and funerals,
"we're all going to die some day!" :p

All the Police interceptors with the flashing head lights? All
sold state.... Join me in the 21st century! :D You can do it!

PS all modern cars have solid state flashers for turn signals.
You need to write them and say, DO IT WITH RELAYS! Ha ha!
 
Last edited:

hippy

Technical Support
Staff member
By a rotary switch "encoder", I meant something like a mechanical version of the 74LS148 8-line to 3-line encoder, and it seems to me that your use of the rotary switch implies that (perhaps that is standard). In plain language that means you have 6 binary values encoded into three lines--just what the 74LS148 does electronically for up to 8 values.
By simply adding diodes and having signals encoded this way a single pole 6-way switch can be used which could make it easier or cheaper to obtain.

As to using a plane's chassis as the 0V line for switches or power I don't know if that would be deemed acceptable but I guess there's 'construction and use' rules and guidelines like there are for cars which would cover that.

The usual safety critical caveats will apply as they do with automobiles, perhaps more so with aircraft.
 
By simply adding diodes and having signals encoded this way a single pole 6-way switch can be used which could make it easier or cheaper to obtain.
That is a great idea. I was thinking of diodes as well. Not sure a single pole will work. If you could draw a sketch, schematic out that would be great. To get four patterns you only need two inputs. The problem is getting that 5th or 6th pattern, which needs three pins.

PUSH BUTTON? Where in one of the positions, say FLASH, you can cycle through two or three flash patterns. I read the manual and saw this code. I asked about this and must have not been clear. I was told it can't be done and got into reading the state of the pin. This is the code:

init: let b0 = 0
main: if pin 1 = 1 then add
goto main
add: pause 100 ‘short delay
let b0 = b0 + 1
if b0 < 5 then main
high 1
goto main

(can someone give me the program initalazation to make this code work, I tried and there seems to be syntax error with the first "if". Could be because I did not define it?)

Is there a way to use the push button counter to permantly save a memory value, so when you turn the -08M back on it will defalt to that value?

The other thought is have the button accessable so you can cycle through some flash patterns. When you move the toggle (OFF, ON, FLASH) it will go to the default... unlike the above example.

As to using a plane's chassis as the 0V line for switches or power I don't know if that would be deemed acceptable but I guess there's 'construction and use' rules and guidelines like there are for cars which would cover that.
Very standard stuff, trust me! :rolleyes: Seriously chassis grounding (to the metal airfame has been done from Cessna, Piper, Beech and on. However to avoid ground loops I will have a central GROUND BUS behind the panel. This saves ground loops and other bad things (like bad grounds). The amount of weight added to run wire to a ground bus (verses local grounding) is small. However chassis ground is still used in cars and most planes, large and small.

The usual safety critical caveats will apply as they do with automobiles, perhaps more so with aircraft.
I agree. You just don't want to smoke wires. Smallest aircraft CB's are typically 2 amps (some times 1 amps). They are not fast acting and made to protect wiring not electronics. 5 amp is a typical size and you can gang more than one circuit on one CB (if they don't exceed the CB rating and wiring is rated for way over 5 amps..... The CB's are just to protect the wires not the component it self.

A micro pricessor drawing milli-amps would do well to have an onboard or inline fuse. I could put in a sacrafical fusable link. The down side is shot-gunning or peppering fuses all over the place. It will be in metal box. I am more concerned about protecting the high output mosfits. Those will be on a CB, 10 amps. It makes sense to put the micro on the same circuit, so there is no way the micro will blow a 10 amp fuse with out having a melt down... however so what? It will be in a metal box, let it FUSE it self. I am not trying to save it. If it burns out, it can be repaired or dropped in the trash.

Not having taxi landing regonition lights is really not a life threating event, unless you are landing on some dark remote un-lit strip in the middle of the night in bad weather. Then you are running drugs ;), becasue you would not be doing that... Bigger airports tend to have lots of ambient light at night from all the lights on the runway, taxiway and surrounding areas. However an electrical fire day or night, NOT GOOD!

Most medium sized airports have runway lights and you can land at night with out landing lights. However taxi is a problem on a moonless night or the smaller fields that don't have taxi lights or "light polution" from nearby lights. You would be nuts to land on a unlit strip at night, unless you had SERIOUS landing lights... These lights are pretty minimal, for occasional night flying, but mostly day, where the flashing part comes in. Flashing your landing/taxi light addes great visabilty.
 
Last edited:

Paix

Senior Member
@gmcjetpilot

Code:
#picaxe 08m

init: let b0 = 0

main:
  if pin1 = 1 then add
goto main

add: 
  pause 100 'short pause
  let b0 = b0 + 1
  if b0 < 5 then main
  high 1
  goto main
No space in pin1 and I got a strange character reported after the pause 100 statement for some reason, but retyped the "'" and that went away.

Hope that helps some.

Compiled/checked for syntax OK, but not checked for functionality. As most compilers don't say when they report correct compilation, "you're on your own now" :)


Ian

Just found the code in Manual 3 page 26 and subsequently your other thread on the subject. I hope that between the two threads you have the answers you require about the code fragment. I was only picking up on the syntax error problem. The lexical agility confuses the fluff out of me LoL.
 
Last edited:
No space in pin1 and I got a strange character reported after the pause 100 statement for some reason, but retyped the "'" and that went away.
Works like a charm, made a few mods and can see that working nicely, thanks.

Any one know how to read and write to EPROM? I want to save that button pushing number at the start of the program, when the user will have a short time to change that value with a quick button push.

I read the manual and saw the example but it is pretty poor. Is there a PICAXE programmer guide with better examples, details and explanations?
 

lbenson

Senior Member
Code:
#picaxe 08M

b13 = 0
main:
  write 0,b13 ' save b13 to eeprom position 0
  read 0,b0  ' read eeprom position 0 into b0
  sertxd("%",#bit2, #bit1, #bit0)
  pause 2000
  inc b13
  if b13 > 7 then : b13 = 0: endif
  goto main
 
Top