I need some help regarding the use of "On Interrupt". This is the first time I am trying to use the On Iterrupt command.
Setup on 12F683:
A signal with a period of 32 ms is connected to gpio.2 (the CCP1 pin). My reasoning is that this will cause an
interrupt every 32 ms.
A LED is connected to gpio.0 (set as "out") through a resistor. This serves as the "ALARM" output.
The "main" program:
The program is basically a loop wherein the TRIGGER value is increased by 1 (one) every 5 ms. If the TRIGGER
value reaches a value larger than 8 then the ALARM sub-routine is called, making gpio.0 high for 10 us.
Now, the latter will only happen if for some reason the input every 32 ms on pin gpio.0 does not occur
(e.g. a beam is broken which normally supplies this signal). If this "RESETTING" does not take place the value of
"TRIGGER" will not be reset and will reach a value of larger than 8 and the ALARM (gpio.0) is set high.
However, it seems as if the On Interrupt never occurs, although pin gpio.2 (CCP1) is driven high every 32 ms.
This is clear from the fact that the ALARM swithes on with a period that depends on the trigger limit and the wait
duration in the main loop.
I basically confirmed that the main loop does execute. I did this by setting the values as below and
then measuring the period between alarm pulses on gpio.0 :
Results:
1.trigger > 8; wait time in main loop = 5s ==>> gives measured alarm period of (8x5s) + 5s = 45 ms;
2.trigger > 4; wait time in main loop = 5s ==>> gives measured alarm period of (4x5s) + 5s = 25 ms;
3.trigger > 2; wait time in main loop = 5s ==>> gives measured alarm period of (2x5s) + 5s = 15 ms;
I would really appreciate some help on this. Below is my code.
The CODE:
;Chip Settings
chip 12F683,1
;Interrupt Handlers
On Interrupt CCP1 Call RESETTING
dir gpio.0 out
dir gpio.2 in
trigger = 0
main:
If trigger > 8 then
gosub ALARM
else
wait 5 ms
trigger = trigger + 1
end if
goto main
Sub ALARM
GPIO.0 = 1
Wait 10 us
GPIO.0 = 0
trigger = 0
End Sub
Sub RESETTING
trigger = 0
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I need some help regarding the use of "On Interrupt". This is the first time I am trying to use the On Iterrupt command.
Setup on 12F683:
A signal with a period of 32 ms is connected to gpio.2 (the CCP1 pin). My reasoning is that this will cause an
interrupt every 32 ms.
A LED is connected to gpio.0 (set as "out") through a resistor. This serves as the "ALARM" output.
The "main" program:
The program is basically a loop wherein the TRIGGER value is increased by 1 (one) every 5 ms. If the TRIGGER
value reaches a value larger than 8 then the ALARM sub-routine is called, making gpio.0 high for 10 us.
Now, the latter will only happen if for some reason the input every 32 ms on pin gpio.0 does not occur
(e.g. a beam is broken which normally supplies this signal). If this "RESETTING" does not take place the value of
"TRIGGER" will not be reset and will reach a value of larger than 8 and the ALARM (gpio.0) is set high.
However, it seems as if the On Interrupt never occurs, although pin gpio.2 (CCP1) is driven high every 32 ms.
This is clear from the fact that the ALARM swithes on with a period that depends on the trigger limit and the wait
duration in the main loop.
I basically confirmed that the main loop does execute. I did this by setting the values as below and
then measuring the period between alarm pulses on gpio.0 :
Results:
1.trigger > 8; wait time in main loop = 5s ==>> gives measured alarm period of (8x5s) + 5s = 45 ms;
2.trigger > 4; wait time in main loop = 5s ==>> gives measured alarm period of (4x5s) + 5s = 25 ms;
3.trigger > 2; wait time in main loop = 5s ==>> gives measured alarm period of (2x5s) + 5s = 15 ms;
I would really appreciate some help on this. Below is my code.
The CODE:
;Chip Settings
chip 12F683,1
;Interrupt Handlers
On Interrupt CCP1 Call RESETTING
dir gpio.0 out
dir gpio.2 in
trigger = 0
main:
If trigger > 8 then
gosub ALARM
else
wait 5 ms
trigger = trigger + 1
end if
goto main
Sub ALARM
GPIO.0 = 1
Wait 10 us
GPIO.0 = 0
trigger = 0
End Sub
Sub RESETTING
trigger = 0
End Sub
In your case you have to use GPIE interrupt not CCP1
it is an int on change.
If you don't want an interrupt for the the 2 edges, you have to test if GP2 is going up or down...
CCP1 work with comparator
or capture with TMR1