DB101 delay inturrupt

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm playing around with a DB101 and I'd like to exit a loop once the joystick enter is pressed. The problem is that when I use _delay_ms() (in delay_x_gcc.h) it seems it only checks if the joystick enter is pressed BETWEEN delays. This makes it difficult to exit the loop, and requires luck.

How can I interrupt _delay_ms(1000) and exit the loop EVERY time the joystick enter is pressed?

I wouldn't even mind waiting 1000 ms and letting _delay_ms(1000) finish before it exits if that makes it easier.

while (!JOYSTICK_IsEnterPressed())
{
  _delay_ms(1000);
}

Thanks,

Waspinator

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's one solution: Do several much shorter delays, so short that you are sure to catch a closed switch. Maybe a thousand delays of 1 ms?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

How can I interrupt

The answer to your question is in your question ;-)

If you did your delays with a timer interrupt rather than a software loop you'd be free to get on with other stuff while waiting for the interrupt handler to signal the completion of the measured period of time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was actually already thinking of using interrupts, I just wasn't sure how I would do that. I would like to be able to keep using delay_x_gcc.h to wait if that's possible though.

I'm brand new to AVR, so can you give me a code snippet on how I would do this, or maybe point to somewhere where I could find out more?

Thanks,

Waspinator