OK. The Problem is.........A PROBLEM.........

TEZARM

Senior Member
OK. Here is my next question.
How do I Program a Picaxe 18A so that when it gets a constant positive trigger it tells an output to turn on for 2 seconds and then off again. Now the Problem is that the Picaxe is to IGNORE all Positive Feeds to the Input Pin between 0 Seconds and 2 Seconds. Only must it trigger the Output after a 2 SECOND Interval. For example a 1 Second positive pulse to input pin of Picaxe will not do anything to the Output as it is to short a time. I have no code written up yet as I don't really no where to start with this problem. I know, I have a weird way of explaining things, it must be the whole amateur thing coming out in me. Any Ideas Guys.
 

ylp88

Senior Member
How accurate do you need the 2 seconds?

(Psuedo-code because I've forgotten a lot of sytax for this...)
<code><pre><font size=2>shortpulse:
For i = 1 to 4
PULSIN inputpin, +ve edge, variable
If variable &lt;&gt; 0 Goto shortpulse
Next i </font></pre></code>
If this goes to plan, it should loop four times in which it will timeout in each case, if the pulase is longer than 2 seconds. If the pulse if short, then the loops will restart. As each timeout is ~0.655s long, 4 loops will require a pulse of 2.62 seconds...

This is post is more like my random ramblings and a bit of brainstroming and is not at all elegant, but may trigger some other minds out there...

EDIT: AAARGH!!! May not work as the pulse is continuous and thus does not have a rising edge with which to trigger the PICAXE... [sigh]...

2nd EDIT: Perhps 3 loops is better if you don't mind a shorter pulse, but three loops is close to your requested 2 seconds...

ylp88

Edited by - ylp88 on 10/19/2005 1:29:28 PM

Edited by - ylp88 on 10/19/2005 1:31:04 PM
 

BeanieBots

Moderator
The use of pulsin won't work because as stated, it requires both edges to start and stop the internal counter.

Something along the lines of:-

main:
if pin1=1 then start_timer
goto main

...
...
start_timer:
for b0=1 to 200 'experiment with this value
if pin1&lt;&gt;1 then main 'go back to beginning if no input
pause 10
next b0

high 1 'turn output on
pause 2000 'wait for 2 secs
low 1 'turn output off
goto main 'start monitoring again.

The problem with the above code is that if the input is momentarily interrupted while the for/next is doing the pause 10, it will miss the fact and carry on as if it was a continuous push. This may acceptable. If not, increase the for/next loop count and decrease the pause to give the desired effect. The value of 200 needs to be a bit smaller in practice to take into account the time taken for the other commands in the loop as well as the pause 10.

You really need to read up on interrupts, especially if you want your PICAXE to be doing something else other than just sitting and waiting for a button push. This is especially true if you want outputs to be changing state such flashing an LED while still looking for a change on an input.
 

ylp88

Senior Member
Late at night here now but hopefully this makes sense:

Perhsps you can make use of a front end circuit. Use a 555 set to a 2 second interval and use the push button to control the 555's reset pin. If the button is released prematurely, the 555 resets. The output of the 555 can then be used to trigger an input pin on the PICAXE and an interrupt if necessary. You must configure the 555 in a &quot;one-shot&quot; mode (in a monostable operation?) or else the PICAXE will keep receiving interrupts if the button is kept pressed for say 4 or more seconds.

Hope it makes sense... Good night!

ylp88
 

TEZARM

Senior Member
yip88. Thanks for ya help. I would rather get the Picaxe to do everything for me as I don't have the room on circuit board for more components. It Looks rather tricky to work out actually so I might have to change my ideas as I don't have the time at the mo for anything to tricky but hope to get into that stuff more next year. Thanks so much for your help though, I really appreciate it.
BeanieBots. Yes it looks as though I am going to have to Research those INTERRUPTS alot more as it seems they are used in so many situations and I know nothing about them but anyway thanks for your help aswell, again it is appreciated. Thanks.
 

TEZARM

Senior Member
yip88. Thanks for ya help. I would rather get the Picaxe to do everything for me as I don't have the room on circuit board for more components. It Looks rather tricky to work out actually so I might have to change my ideas as I don't have the time at the mo for anything to tricky but hope to get into that stuff more next year. Thanks so much for your help though, I really appreciate it.
BeanieBots. Yes it looks as though I am going to have to Research those INTERRUPTS alot more as it seems they are used in so many situations and I know nothing about them but anyway thanks for your help aswell, again it is appreciated. Thanks.
 

BarryP

Senior Member
Totally Untested ..
Not sure what the twosecondcount should be
you would need to experiment

symbol counter = W6
symbol twosecondcount = 2000 ; ??
main:
if pin1 = 1 then incrementcounter
counter = 0
low output1
goto restofcode
incrementcounter:
counter = counter + 1
if counter = twosecondcount then timeoutreached
goto restofcode
timeoutreached:
counter = 0
high output1

restofcode:
goto main
 

TEZARM

Senior Member
Thanks BarryP. Now I am definitely giving up on this idea. Your code has scared me off this idea of mine as it is all getting to confusing for me. However like the others, your help is very appreciated and thanks for taking the time to try and help me out. Next year I will get on to this project and get it sussed out so have takin a print out of your example to play with next year more. Thanks all so much.
 

BeanieBots

Moderator
Draw it out on a piece of paper as a flow diagram. It will all become clear.
If you have a box that says something like &quot;wait 2 secs&quot;, that box must complete before anything else can happen. You cannot test the input or set the output while inside that box. If you change the box to say &quot;wait 50 mSecs&quot;, then you have another box after it that might say &quot;have I waited a total of 2 secs?&quot;. If yes, then change output, if no then add 50mS to the total time and then go around the loop.
Flow diagrams are great for getting your head around things like this.
Do read up on interrupts. They are EXACTLY the mechanism for your issue.
 

TEZARM

Senior Member
Oh. I have never tried using flow charts before as I thought it to be bad practice as it does not tell you how it should be written in code (I don't think) but have never considered using it for problems I have either. Actually, thats a damn good idea BeanieBots, good thinking, I am going to try that idea now. Thanks
 

Rickharris

Senior Member
Actually drawing a flow chart (in pencil) is a very GOOD idea. It allows you to get the flow of the events in the right order.

At school we only use a rectangle for actions (turn on outputs, wait for a time etc) and a diamond for decisions (check an input and do something, Goto somewhere else if something is bigger or equal to something else etc.)

This allows a simple approach that covers nearly everything. If you do the flow chart in enough detail you can write the relevent code next to each of the boxes and you have your programme.

You will know if it is a diamond you will use the If ...Then command, and if a rectangle you will use high, low, wait, pause etc.

The only problem with using the inbuilt flowchart system is that not all commands are covered and it can be difficult sometime to get the system to do what you want it to do. The flow chart is converted into basic anyway so why not use basic in the first place, used meaningful lables and learn to programme ion a way that will help you move onto more complex languages in the future.
 

TEZARM

Senior Member
Yes. Excellent way of explaining it Rick. You and BeanieBots have made me stop and think. Maybe I will start using them Flowcharts more from now on. It sounds like your a teacher of some sought Rick, so if you advise it to be a good idea using the flow chart system than it be best I try it that way. Thanks for the good idea you Guys. Don't know why I didn't think of it however? We seem to forget the simplest things at times and need to be remin ded at times I guess. $
 
Top