CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sensor ...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Bibi
Guest







sensor ...
PostPosted: Fri Jul 01, 2005 3:00 am     Reply with quote

Hello,

i have a sensor that is 1 when (!input(sensor)) and 0 when (input(sensor)).

What i want to do is to count if it is pressed 6 times in an interrupt.

It should be something pretty much like this :

Code:
counter = 0;
button_pressed_6_times = 0;


if (!input(sensor)){        // Wait for Enter Button to be pressed
while (!input(sensor));   // Wait for Enter Button to be released
counter +=1;                // counts how many times it is pressed
}

if(counter == 5) button_pressed_6_times == 1;


Will that work or does someone has an idea ?

The thing that is difficult is that it should be in an interrupt ...

Thank you very much.
valemike
Guest







Re: sensor ...
PostPosted: Fri Jul 01, 2005 5:13 am     Reply with quote

Bibi wrote:
Hello,

i have a sensor that is 1 when (!input(sensor)) and 0 when (input(sensor)).

What i want to do is to count if it is pressed 6 times in an interrupt.
[/code]

Wait. You want to stay this long in an interrrupt service routine? Don't do that. Your interrupt should get in and out within microseconds. Defer this counting six times for your main loop.


Code:
counter = 0;
button_pressed_6_times = 0;


if (!input(sensor)){        // Wait for Enter Button to be pressed
while (!input(sensor));   // Wait for Enter Button to be released
counter +=1;                // counts how many times it is pressed
}

if(counter == 5) button_pressed_6_times == 1;


This should be:
if (counter == 5)
{
button_pressed_6_times = 1;
}

Will that work or does someone has an idea ?

The thing that is difficult is that it should be in an interrupt ...

Thank you very much.


There is something clumsy about staying long in an interrupt service routine. But if you do insist on staying in the ISR, the above code, with the "==" correction should work. Make sure those variables are Global though; i don't see how or where they are initialized.
Bibi
Guest







PostPosted: Fri Jul 01, 2005 5:25 am     Reply with quote

If it is not in an isr how could i do ?

The variables are global exact !
Bibi
Guest







PostPosted: Fri Jul 01, 2005 6:30 am     Reply with quote

I forgot to say that it should be pressed 6 times for a period of 30 seconds.

So if the button is pressed 6 times during 30 seconds button_pressed_6_times == 1;
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Fri Jul 01, 2005 7:11 am     Reply with quote

Bibi wrote:
I forgot to say that it should be pressed 6 times for a period of 30 seconds.

So if the button is pressed 6 times during 30 seconds button_pressed_6_times == 1;


That's a MUCH different problem, and you need to define it a little better. Do you mean 30 seconds from the first button press, or any 6 presses within 30 seconds? With the first, you would start a 30 second timer on the first button press, and reset things if the timer reaches 30 seconds and six presses have not occured. The second cas is much more complex.

Be careful about button bounce, as well.

Scott
Bibi
Guest







PostPosted: Fri Jul 01, 2005 7:18 am     Reply with quote

It should be 6 presses in 30 seconds, the first press starts the process and then ther are 30 secondes left for the button to be pressed 5 more times to the process to be ok if not nothing happens.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jul 01, 2005 8:48 am     Reply with quote

Don't forget to do some debouncing of the switch
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Bibi
Guest







PostPosted: Mon Jul 04, 2005 1:50 am     Reply with quote

Do have any other idea ?
Bibi
Guest







PostPosted: Mon Jul 04, 2005 6:09 am     Reply with quote

PLEASE HELP !!!! Crying or Very sad
valemike
Guest







PostPosted: Mon Jul 04, 2005 7:10 am     Reply with quote

Do you want code?

ex_stwt1.c
or
ex_stwt.c
or
ex_stwt2.c

in the CCS examples directory that comes with every version of the compiler

Read it and you'll find you can set up your isr. Then look the main. It counts the timing between two events (you press a key two consecutive times and it tells you how many seconds elapsed between the two keypresses).

With a few changes, you can have this example work for you.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group