I am currently doing a project which requires the timing of signals via a PIC.
i am using the timer counter to count the time it takes between one input going high (input switch) and another input going high (external sensor). I am using the PIC16F84 and pin RBO to configure the external interupt. The external sensor is connected to RBO.
The problem lies with the PIC while it is waiting for the external interupt. If i put the pic in a loop until it recieves the external interupt, when i come out of the interupt it goes back into the loop. This is no good if i want to do something with the time/count after the interupt. It means all the stuff i want to do after the interupt i have to include inside the interupt.
Is there a way around this???? I was thinking about the sleep function instead of a loop but that would stop the clock which is needed for the PIC to continue counting.
An RETFIE should return to where it was called from, in this case it wouldn't cause it to leave the loop if it did - unless you've proved it differently, which is why I suggested it as a 'bug' if it does.
An RETFIE should return to where it was called from, in this case it wouldn't cause it to leave the loop if it did - unless you've proved it differently, which is why I suggested it as a 'bug' if it does.
It is basically how subroutines works. If it is like what you said, no subroutine call will ever works.
All subroutine calls, and interrupt included, in every CPU I know of, would store the address of the NEXT instruction onto the stack so that a RET or RETFIE will branch and starts execute the next instruction.
It will definitely not returning to where it was called, but to the instruction that follows the current instruction while interrupt occurs.
I think you got it wrong there Mr Chung. Or, you are right, the next instruction is executed. As the next instruction is Goto Loop, then that is what it will do.
For normal instructions except branching instructions, the next instruction is the instruction following the current instruction.
For branching instruction, the next instruction is the target address of the branching instruction and thus this target address will be saved onto the stack.
It is true we are in an endless loop.
Do you have any suggestions which flag i might check. I was thinking of checking the global interupt flag but i think its best practise to reset that flag once inside interupt otherwise if another interupt comes along the program wont respond to another interupt. Am i correct in this???
You create your own flag in a GPR, this is a sample from a file created by my BASIC compiler.
Code:
;Flags register bit definitions
LEADZ EQU 0x00 ;set to show leading zeros
OverFlow EQU 0x01 ;set for add/sub overflow
;Pre-defined variables
Flags EQU 60
So to set a flag you would use 'BSF Flags, OverFlow', or to clear one use BCF, and you test with the usual bit test instructions. So your main routine would clear the flag before the loop, and the loop would test for the flag being set - the routine run when the flag is set would clear it again.