Previous in Forum: Bus Coupler Requirements in a Switchyard   Next in Forum: Selecting Bus Bars
Close
Close
Close
4 comments
Rate Comments: Nested
Associate

Join Date: Jul 2007
Posts: 26

Polling Help

05/08/2008 6:33 AM

hi guys
i have a switch connected to a pic
one contact to the pic portA bit 2 and the other to ground
when the switch is pressed,it call a function which it does correctly but as long as the switch is pressed it keeps calling that function.i want it to call the function only once per press,that is if you press the switch it should call the function,if you want it to call it again ,you have to release the switch and press it again,i dont want to use interrupt
any help?

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
Engineering Fields - Instrumentation Engineering - New Member Hobbies - Fishing - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 753
Good Answers: 8
#1

Re: Polling Help

05/08/2008 11:55 AM

It's not clear for me what you'd meant when said "...don't want use interrupt". Don't you want use additional interrupt or using ones a whole?. As well I have not any idea what an environment you're prefering for programming (ASM, Basic, C)?

Nontheless, your function() shouldn't be called by a static EVENT (whether switch pushed or not) but dynamic (tranistient) one. i.e whether there had been transition from switch ON state to switch OFF state.

In a nutshell my supposition is (excuse me for some mixing style as I dont know your prog language)

initialState=PortA:Bit2;

....timeDelay;

postState=PortA:Bit2;

IF (initialState==0 and postState==1) {call your function()}

else passing by...

.....

TimeDelay is conventialy called procedure to organize some time gap between Port readings. It can be organized simply if you place initialState calling quite apart from postState at your program.

Event is function of initialState and postState i.e. EventFunc(initialState, postState). EventFunc has four possible state and I for example used to prefer programming respond of system on all these states, using for instance switch statement on C. Some tricks with pointers would be possible here as well. But it's up to you.

Hope it helps.

P.S. You can put capacitor(some pF) between your switch and ground :).

Register to Reply
Guru
Popular Science - Weaponology - bwire Hobbies - Car Customizing - New Member

Join Date: Dec 2007
Location: Upper Mid-west USA
Posts: 7498
Good Answers: 97
#2

Re: Polling Help

05/09/2008 3:47 AM

When you have received the function release the button

__________________
If death came with a warning there would be a whole lot less of it.
Register to Reply
Guru
United Kingdom - Member - Olde Member!! Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jul 2006
Location: Dunstable, England
Posts: 2821
Good Answers: 45
#3

Re: Polling Help

05/09/2008 9:31 AM

Could this be a problem due to switch bounce??

John.

__________________
A little knowledge is a dangerous thing - Googling is far worse!
Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#4

Re: Polling Help

05/09/2008 2:14 PM

I would tend to use a location in memory as a status register and select one bit of the register to correspond to the switch. The other bits are free to use for other functions.

Check the condition of the switch.

If switch is 0, set your status bit to 0

If switch is 1 (activated) check status bit

If status bit is 0, perform switch routine and set status bit to 1

If status bit is 1, the routine has executed so ignore it.

Thus the switch has to return to the inactive state before the routine will run again.

Bill

Register to Reply
Register to Reply 4 comments
Copy to Clipboard

Users who posted comments:

bwire (1); caramba (1); Electroman (1); Sciesis2 (1)

Previous in Forum: Bus Coupler Requirements in a Switchyard   Next in Forum: Selecting Bus Bars

Advertisement