+ Reply to Thread
Results 1 to 5 of 5

Thread: Help with asynchronous interrupts

  1. #1

    Default Help with asynchronous interrupts

    Please, I need some help in the use of asynchronous interrupts.

    A switch successfully triggers an interrupt. A short time later in my program, the switch will not trigger an interrupt. A little bit later, the switch works again, in a part of the program that is very similar to the part that did not work. It works, it doesn't work, and then it works. What am I missing?

    I have two balls running down a track right-to-left, and as they enter a tunnel they run across a ballComing switch RB.0, which triggers an interrupt when it connects to ground. Then, a pattern of LEDs follows the balls as they go through the tunnel. The balls are not always the same distance apart, so the second ball needs to trigger the interupt, too, so that each ball has a pattern of lights following it. If there is no second ball (or the second ball is far enough behind), the pattern just follows the one ball.

    Here is my problem. There are light patterns that arestepped from a position to the right and then back one position at a time until they are centered, and then they are stepped left one position at a time until the pattern is gone out the left side of the tunnel. Then it looks like the light pattern enters the tunnel on the right, and follows the ball through the tunnel until it runs out the left end. The switch triggers the interrupt to get the process started, and this works fine. Then there is a section of the program where an interrupt (for the second ball) should create a second light pattern overlapping the first light pattern, but this does not happen. Then there is a section almost identical to the first non-functioning section, and it works fine. The only difference is in which direction the pattern is being moved. The code which is detecting the interrupt is the same. Why won't the interrupt get detected on the first half of the light pattern's journey, and yet get detected just fine on the second half of it? As it is, my program works if the second ball is not following too close, but if it is close then the switch gets hit during the part of the program that is not detecting the switch, and I only get one pattern of lights as if there was only one ball.

    I have attached my code. The troublesome section has some comments that point out where the problem is. The patterns in each step are shifted out to MAX6969 chips (constant current LED drivers, each drives up to 16 LEDs, they are connected together so that the patterns for all four sets of LEDs are shifted out all at once). The interrupt routine just sets a flag (runFlag), and the program uses the flag's being set to decide that there are some balls with light patterns to be overlapped. There is so much of the program that works, I can't see why the one section isn't working.

    I have tried a zillion variations, and there is probably some simple thing that I am not doing right, but I sure can't find it. Thank you in advance for your help.

    Vic

    Post Edited (Vic Chaney) : 12/31/2009 6:52:59 AM GMT
    Attached Files Attached Files
    Last edited by ForumTools; 10-02-2010 at 06:16 PM. Reason: Forum Migration

  2. #2

    Default

    It looks like you’re clearing yourrunflag in a few places without any corresponding action. The way you’re using the interrupt will tell you a ball has passed by, not that the ball had just passed by. The code is polling the value of the runflag, but in a few places the runflag has cleared before it is polled possibly erasing the fact that the ball has passed by. One possible solution is to poll the switch in the Main code to capture time the first ball has rolled by, then using the interrupt routine to capture the second ball rolling by.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Bad spellers of the world untie!
    Last edited by ForumTools; 10-02-2010 at 06:16 PM. Reason: Forum Migration

  3. #3

    Default

    Thank you for responding, mojorizing.

    I first had a problem where it always acted as if there was an interrupt in the first part of the program, even if there wasn't. Somehow in the process of trying to correct it, now it acts as if there is never a second ball interrupt. So, I made a short section to keep it clear of interrupt, then hit the switch a second time to see where it will accept an interrupt, and where not. I tried clearing the runFlag at the beginning, one-third, and two-thirds through the trouble section, and it will still not detect the interrupt during the section where the runFlag is available to be set by the interrupt routine.

    For the first ball, I can achieve recognition of the ball through polling the switch or by interrupt, and either way works.

    When I clear the runFlag at the beginning, it still will not detect a second ball interrrupt during that troublesome section, and has no trouble detecting the second ball in the later section.

    So I am still not working, but I appreciate your help! Thank you.

    Vic
    Last edited by ForumTools; 10-02-2010 at 06:16 PM. Reason: Forum Migration

  4. #4

    Default

    I think you need to add
    Code:
    WKPND_B = %1111_1110

    to your "Init" section as you're setting up the portsto clear the pending register to enble new interrupts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Bad spellers of the world untie!
    Last edited by ForumTools; 10-02-2010 at 06:16 PM. Reason: Forum Migration

  5. #5

    Default

    Thank you, mojorizing.

    I gave it a try, and it doesn't help. Of course, my first interrupt always worked, and the "WKPND_B = %1111_1110" gets reset after each interrupt, and other interrupts are working.

    Thanks!
    Last edited by ForumTools; 10-02-2010 at 06:16 PM. Reason: Forum Migration

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts