Best way to look for an input?

Artie2

New Member
I have an 08M, and I want it to sit and do nothing until pin 3 goes hi. I can see at least two ways to do this. I could just "loop" on pin 3 looking for an input, or I could set an interrupt, and then just pause the Picaxe, waiting for the event. Is one way better than the other, or is there even a better way?

Thanks;
Artie
 

westaust55

Moderator
Some further information will help get an answer.

1. Are you trying to save power consumption between responding to activity on Pin3?

2. what is the frequency and time duration of the input signals on pin3?
 

inglewoodpete

Senior Member
It depends on what you are using the PICAXE for.

How long will the input condition persist on the input pin? If you PICAXE is busy servicing some other code, it could miss a brief input. If the PICAXE is idle most of the time, then polling the pin is suitable.

An interrupt is best suited to a busy PICAXE. The interrupt routine will often be designed to just record the fact that the input event has occurred (in, say, a spare variable). When the PICAXE finishes the task it was doing when the interrupt occurred, it would test the variable and act accordingly.
 

Artie2

New Member
It will be a "latching" type key press. The Picaxe doesn't need to do anything until it sees the key-press event, then it will branch to another routine to take action on that event. The Picaxe itself will clear the key-press, so it will persist until the Pic is done with it. The key-press event will occur less than once every several seconds.

P.S. This will be AC-mains powered, so I'm not at all concerned with power consumption.
 

hippy

Ex-Staff (retired)
A simple 'poll' for input is perhaps the easiest to implement ...

Code:
Do
  Do : Loop Until pin3 = 1
  Gosub DoSomething
  Do : Loop While pin3 = 1
Loop
You can always move to interrupts later if you want to or it becomes necessary.
 

westaust55

Moderator
Concur with Hippy wrt polled for simple programs.

You mention the input as "It will be a "latching" type key press. "
Is this latched using an external device (such as a logic flip flop) and the external device is reset by a PICAXE output?
or
are/were you thinking to try and latch the PICAXE input (before it is polled or an interrupt is actioned)?
or
some other means?
 

Artie2

New Member
You mention the input as "It will be a "latching" type key press. "
Is this latched using an external device (such as a logic flip flop) and the external device is reset by a PICAXE output?
Yes. Here's a rough draft of what I'm doing. Nothing here is "written in stone" yet. Also, while I'm using an 08M for testing, the actual design calls for a 14M.

http://www.neighborhost.com/picaxe/forum01.png

Those switches are foot-switches. As you first start to apply pressure, you break the normally-closed (NC) contact. The cap charges through the resistor and places a "hi" on the input of its associated OR-gate, generating a channel-event. (Non-latching at this time.) When the contact hits the bottom normally-open (NO) contact, it places a "hi" on the KP OR-gate, generating a key-press event. The 14M only need watch for the KP event before it scans for a channel-event. The KP also enables the latching of the channels.

So now, even though you've lifted your foot, both the KP-event and channel-event stay persistant. The 14M can take its sweet time reading the inputs. After it reads, (and stores), the inputs, it clears output pin 0. Then it reads input pin 0 again to make sure it dropped "low". If it didn't, it means you are holding your foot down, and the program takes a different action. Kinda like those clocks where you can advance a digit one at a time, or have the numbers advance quickly if you hold the button down.

Part of the reason for the somewhat unusual key-press scheme, is that in my initial testing, I discovered that it wasn't unusual to rest your foot on a switch, causing false inputs. This way, no action is taken unless a true "full press" takes place.

I still have some bugs to work out, and I may go a completely different direction, but this is the crux of it. By the way, this is for an "intelligent" guitar effect/amp switching foot board.

Artie

P.S. I also wanted to experiment with those Ti SN74LVC1G58/9's. They're a cool IC that can be almost any gate you want, simply by how you connect it. Also, they have schmitt-trigger inputs and can source or sink over 30ma's at 5V.

P.S.2: Those channel AND gates will probably be replaced with a pair of simple 74HC08's. I don't need the schmitt trigger on those gates, and it eliminates the need for that lone invertor.
 
Last edited:

BeanieBots

Moderator
Might be worth reading up on the "button" command.
Has some features which sound like they would do most of what you want in just one command.
 

Artie2

New Member
Yeah, I was looking at that one also. The only thing about the "button" command is that it appears to do switch debouncing within the command, and I do that in hardware. I'm just concerned about what that adds in processing time. Still, probably the best thing for me to do is try each method and see what does what.
 

Mycroft2152

Senior Member
Yeah, I was looking at that one also. The only thing about the "button" command is that it appears to do switch debouncing within the command, and I do that in hardware. I'm just concerned about what that adds in processing time. Still, probably the best thing for me to do is try each method and see what does what.
That is the best approach!

You will get many different opinions from the brain trust here on the forum, but the bottom line is what works best for you.

The PICAXE makes it very easy to try them out.

As one of the footwear companies says: Just do it!

Myc
 
Top