Shop OBEX P1 Docs P2 Docs Learn Events
Can you mix periodic interrupts with port interrupts? — Parallax Forums

Can you mix periodic interrupts with port interrupts?

Mark HubersMark Hubers Posts: 19
edited 2008-12-22 16:35 in General Discussion
Can you mix periodic interrupts with port interrupts?
·
What I mean by this is that I need to track time using interrupts and to watch for a button.· Maybe it would be easier to just state what I am trying to do...
·
1) Program starts up and gets some things setup.
2) Goes to sleep and waits for a button to get tapped.· But this tapping of the button needs to know if it has been tapped or if it has been held down for a few seconds.
3- a)·If it was just tapped then get out of sleep mode.· Start a countdown and keep monitoring the button to see if it has been tapped again, then add some time to the countdown counter.· As it is doing this, it needs to monitor some others tasks too...
·
3-b) If it has been held down for a few seconds, just get out of sleep mode and do some functions…
·
So I was thinking of the only way to pull that off if the interrupts can do both periodic interrupts with port interrupts.· The periodic would be dealing with the countdown as it is still doing other tasks outside the interrupt.· The port triggered interrupts would moniter the button and wakeup the program if in sleep.· Can this be done using interrupts and if so,· is there something to look at to get a idea how to do this?
·
Thanks for any help!
Mark
·

Comments

  • Mark HubersMark Hubers Posts: 19
    edited 2008-12-21 21:16
    Sorry I do not know how all the html showed up in my last post in email. I hope this fixed it.



    Can you mix periodic interrupts with port interrupts?

    What I mean by this is that I need to track time using interrupts and to watch for a button. Maybe it would be easier to just state what I am trying to do...

    1) Program starts up and gets some things setup.
    2) Goes to sleep and waits for a button to get tapped. But this tapping of the button needs to know if it has been tapped or if it has been held down for a few seconds.
    3- a) If it was just tapped then get out of sleep mode. Start a countdown and keep monitoring the button to see if it has been tapped again, then add some time to the countdown counter. As it is doing this, it needs to monitor some others tasks too...

    3-b) If it has been held down for a few seconds, just get out of sleep mode and do some functions…
    So I was thinking of the only way to pull that off if the interrupts can do both periodic interrupts with port interrupts. The periodic would be dealing with the countdown as it is still doing other tasks outside the interrupt. The port triggered interrupts would moniter the button and wakeup the program if in sleep. Can this be done using interrupts and if so, is there something to look at to get a idea how to do this?
    Thanks for any help!

    Regards,
    Mark
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-21 21:48
    The answer is "yes", but it's not very straightforward. The problem is that the RTCC interrupt lacks a pollable interrupt flag. Here is a thread that deals with this issue, along with some code.

    -Phil
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-12-22 13:20
    It might be easier to just use RTCC rollover for interrupt
    and checking the port B pending bits from inside the isr. These bits get set even
    when not generating an interrupt. Some latency will
    occur. At 100_000 interrupt rate, the latency is
    10 usec maximum but for a button that doesn't matter.

    regard peter
  • mojorizingmojorizing Posts: 249
    edited 2008-12-22 16:35
    I would enable the Wake-Up on Edge Detection for that pin. Once the button is pressed, the SX takes approx. 19ms to wake up, at which point I would poll the pin in a debounce fashion. Using the RTCC (or any other timing method), you can determine if it was pressed less than a few hundred msecs or over 2 seconds (or whatever works for you).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Bad spellers of the world untie!
Sign In or Register to comment.