Searching \ for '[PIC] One button, three purposes' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'One button, three purposes'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] One button, three purposes'
2009\04\01@103855 by Rikard Bosnjakovic

picon face
I'm working on a Timer1-based project where a button should serve
three purposes: start the timer, stop the timer, reset the timer.
Implementing the start/stop alone is easy (TMR1ON = 1 ^ TMR1ON), but
I'm having serious problems figuring out how I can implement the reset
as well.

What I have been playing around with is Timer0. As soon as RA0 is
pressed T0IE is set (cleared when RA0 is released), and the ISR counts
overflows. Later I have made logic based on the amount of
TMR0-overflows.

This is how I want it to behave:

* (If RA0 is pressed) AND (Timer1 is stopped) AND (overflows > 50)  =>  reset
* (If RA0 is pressed) AND (either state of Timer1) AND ( 0 < overflows
< 5) => TMR1ON = 1 ^ TMR1ON

(50 overflows is a couple of seconds - no need to be exact)

I have implemented both of these but I cannot make them work together.
Been wasting(?) two hours on this so I can't really think straight any
longer.

Does anyone have suggestions for another approach other than use Timer0?


--
- Rikard - http://bos.hack.org/cv/

2009\04\01@105715 by Scott

picon face
You have failed to recognize a third state:

Timer1 is running and overflows > 50.


When the button is pressed, why not simply check if overflows is
greater than 50? If so, reset the timer, if not (i.e. overflows <=
50), start/stop the timer. This assumes that one doesn't care if the
timer needs to be running or not after the 50 overflows. If the
start/stop is still required after the 50, the button would need to be
pressed twice (first to stop the timer, then to reset it.)

Unless I have completely misinterpreted your situation...

-Scott



On Wed, Apr 1, 2009 at 10:38 AM, Rikard Bosnjakovic
<spam_OUTrikard.bosnjakovicTakeThisOuTspamgmail.com> wrote:
{Quote hidden}

>

2009\04\01@111643 by Rikard Bosnjakovic

picon face
On Wed, Apr 1, 2009 at 16:57, Scott <.....goldscottKILLspamspam@spam@gmail.com> wrote:

> You have failed to recognize a third state:
> Timer1 is running and overflows > 50.

You are right, I forgot the third state:

* (If Timer1 is on) AND (RA0 is kept pressed) => ignore and continue

The reason for this is that the timer should not be reset if it's
running. If the user wants to reset, s/he must first stop the timer.
Therefore, if RA0 is pressed and overflows go beyond 50 (while Timer1
not running), the overflow check can be aborted since they are no
longer of interest here.

I hope I haven't forgot to include any vital information.


--
- Rikard - http://bos.hack.org/cv/

2009\04\01@131122 by Michael Rigby-Jones

picon face


> -----Original Message-----
> From: piclist-bouncesspamKILLspammit.edu [.....piclist-bouncesKILLspamspam.....mit.edu] On
Behalf
{Quote hidden}

Timer0?

Just to clarify, are you using the overflow counter to check how long
the button is pressed, so a short press starts or stops the timer, and a
long press resets it?

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2009\04\01@133245 by Rikard Bosnjakovic

picon face
On Wed, Apr 1, 2009 at 19:11, Michael Rigby-Jones

> Just to clarify, are you using the overflow counter to check how long
> the button is pressed,

Correct. The overflow-variable counts the Timer0-overflows (which
starts counting as soon as the button/RA0 is pressed).

> so a short press starts or stops the timer, and a
> long press resets it?

Yes, this is my intention which I'm unsuccessfull with. To clarify
even more: "timer" here means Timer1 (external 32kHz-crystal).


--
- Rikard - http://bos.hack.org/cv/

2009\04\01@135354 by Michael Rigby-Jones

picon face


> -----Original Message-----
> From: EraseMEpiclist-bouncesspam_OUTspamTakeThisOuTmit.edu [piclist-bouncesspamspam_OUTmit.edu] On
Behalf
> Of Rikard Bosnjakovic
> Sent: 01 April 2009 18:33
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] One button, three purposes
>
> On Wed, Apr 1, 2009 at 19:11, Michael Rigby-Jones
>
> > Just to clarify, are you using the overflow counter to check how
long
{Quote hidden}

For this example it might be easier to check the button in the interrupt
handler e.g. in pseudo code:

' main loop
do
   if short_press = 1 then
       ' toggle timer state
       TMR1ON = 1 ^ TMR1ON
       
       ' short press now serviced
       short_press = 0
   end if

   if long_press = 1 then
       ' is timer running?
       if TMR1ON = 0 then
           ' timer not running so reset it
           TMR1H = 0
           TMR1L = 0
       end if
       
       ' long press now serviced
       long_press = 0
   end if

loop



interrupt:
   ' button pressed
   if RA0 = 1 then
       overflows = overflows + 1

       if overflows = 50 then
           ' flag a long button press
           long_press = 1
       else if overflows > 50 then
           ' stop overflow counter rolling over
           overflows = 51
       end if

   ' button released
   else
       ' test for short press
       if (overflows > 0) AND (overflows < 5) then
           short_press = 1
       end if
       ' reset overflow counter
       overflows = 0
   endif


If the button press length isn't critical, you may be able to optimise
the interrupt by checking individual bits within the overflow counter
variable e.g. if bit 6 is set that means 64 over flows and a long press,
if bit 7 is set then stop incrementing counter etc.


Hope that helps

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

More... (looser matching)
- Last day of these posts
- In 2009 , 2010 only
- Today
- New search...