The idea is as follows.
When launched, the LOOP1 in program is working and doing something. If user presses the button, interrupt is generated and LOOP2 engaged. When button pressed again, LOOP2 terminates and LOOP1 starts.
Any example code?
The idea is as follows.
When launched, the LOOP1 in program is working and doing something. If user presses the button, interrupt is generated and LOOP2 engaged. When button pressed again, LOOP2 terminates and LOOP1 starts.
Any example code?
Have a flag (bit variable) which you toggle in the ISR.
In the main program you poll the flag and decide which subroutine (loop) to execute.
This will have the potential drawback of always finishing the current subroutine (loop) before switching, is that a problem?
/Henrik.
with PBP "on interrupt" it looks this figure is covered in the manual @ $ 5.66 ( RESUME xxx ) : you can choose the "return" adress xxx as you want ... so LOOP2 always completes.
- also note if you do not clear the interrupt flag ( With a DEFINE ) you automatically re-enter the ISR when completed !
- For DT interrupts ... I didn't check if the resume address can be freely chosen ...
- last idea is simply to overwrite the interrupt return address on the stack ... ( with asm "push" and "pop" macros see midrange manual, interrupts chapter ), depending on the button state.
Alain
Last edited by Acetronics2; - 24th August 2013 at 09:38.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
I don't want to include the button status check routine in the loops, since whole program works with microsecond delays and high accuracy. This is why I wanted to use interrupt. LOOP1 and LOOP2 are totally independent tasks, they don't use same variables, timings or whatsoever.
That's a good question...
I wonder if something like this would work?
Like Henrick said, the routines could be cut short anytime the button is pushed though.Code:x VAR BIT ;----------------------- Setup Interrupts -------------------------------- INCLUDE "DT_INTS-18.bas" ; Darrel Taylor's Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT0_INT, Button_ISR, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM ;----------------------[Initialise Interrupts]----------------------- @ INT_ENABLE INT0_INT ; Enable Button interrupt input x = 0 ' Clear button status flag bit PAUSE 100 GOTO loop1 ' Start at loop1 routine ' ---------------- Independent program routines ------------------------- loop1_start: @ INT_RETURN ; Reset the ISR loop1: ' Perform one type of "time critical" function GOTO loop1 loop2_start: @ INT_RETURN ; Reset the ISR loop2: ' Perform a different type of "time critical" function GOTO loop2 ;--------------------[Program routine selector ISR]---------------------- ; make sure button signal debounced Button_ISR: x = !x ' Toggle x status flag bit IF !x THEN GOTO loop1_start ' Go here when x=0 ELSE GOTO loop2-start ' Go here when x=1 @ INT_RETURN
Louie
Thanks. As I can see, the code is for PIC18xxx family. Will it work on 12xx or 16xx ?
Bookmarks