Login | Register

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

Comments Format:






Close

Subscribe to Discussion:

CR4 allows you to "subscribe" to a discussion
so that you can be notified of new comments to
the discussion via email.

Close

Rating Vote:







4 comments
Active Contributor

Join Date: Jul 2007
Posts: 20

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?

Send to a friend Digg this Add to del.icio.us
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Power-User
Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 265
Good Answers: 1
#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 :).

Guru
Popular Science - Weaponology - bwire

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

Re: Polling Help

05/09/2008 3:47 AM

When you have received the function release the button

__________________
bwise
Guru
United Kingdom - Member - New Member Engineering Fields - Instrumentation Engineering - New Member Fans of Old Computers - Vector 1 - New Member

Join Date: Jul 2006
Location: Dunstable, England
Posts: 2480
Good Answers: 33
#3

Re: Polling Help

05/09/2008 9:31 AM

Could this be a problem due to switch bounce??

John.

__________________
I failed my DNA test - it was my parents' fault.
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 599
Good Answers: 4
#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

4 comments
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
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
You might be interested in: Logic Gates, Analog-to-Digital Converter (ADC) Chips, SRAM Memory Chips