Menu

Not returning from an interrupt

Help
Peter
2016-11-26
2016-11-26
  • Peter

    Peter - 2016-11-26

    I have some code for controlling a WS2811 strip.
    I have a tactile switch connected to RA0 for control and I have set up an interrupt handler:

        Set WPUA0 On
        Set IOCAN0 on
        On Interrupt PortBChange Call IntSW2
    

    The interrupt occurs and the code jumps to the handler, however it doesn't seem to do anything afterwards.

    sub IntSW2
      StopTimer 0   'Timer0 interrupt is used for data flow control
      IntOff
      set IOCIF Off  'Clear IF for IOC
    
      repeat PixelCount
                WS2812SendData ( 0 )    'Turn off all the LEDs
      end repeat
    
      wait 3 s
    
      Inton
    
    end Sub
    

    Have I done something wrong in my code? Once interrupt handler has completed should it just go back to the main code where it left off?
    I tried adding a sub (doBounce) at the end of IntSW2 and doBounce does not run when the interrup occurs, however if I put IntSW2 at the top of my code it runs fine.

    Full code attached.

     

    Last edit: Peter 2016-11-26
  • kent_twt4

    kent_twt4 - 2016-11-26

    I am not familiar with the ws2812 code or library. I think the repeat is the problem, perhaps an overflow of the stack there? Set a flag in the interrupt, like ClearLeds = True. Then use a conditional IF ClearLeds = True Then .....Clear the flag and deal with the repeat and wait in Main.

     

    Last edit: kent_twt4 2016-11-26
  • Anobium

    Anobium - 2016-11-26

    This looks like you are using the same repeat variable - PixcelCount

     
    • Peter

      Peter - 2016-11-26

      Yes, the idea was to turn the LEDs off for 3 seconds just as a simple visual indication that the interrupt was working.

      See below though vv

       
  • Peter

    Peter - 2016-11-26

    It's not the Repeat, or the Wait - I have made the interrupt sub essentially empty and it doesn't return to the main code:

    sub IntSW2
        set IOCIF Off
    end Sub
    
     
    • Anobium

      Anobium - 2016-11-26

      You need clear the correct flag. Datasheet is needed.

       
  • Peter

    Peter - 2016-11-26

    SOLVED

    You need to clear the IOC flag from RA.0, which is IOCAF0, not the IOCIF flag.

    sub IntSW2
    
    set IOCAF0 Off
    Wait 3 s
    
    end Sub
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.