it runs, then sleeps, but does not wake when i put pull gpio.1 high?
Here is my code:
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
dir gpio.0 out
dir gpio.1 in
on interrupt gpiochange call wake_up
main:
set gpio.0 on
wait 1 s
set gpio.0 off
wait 1 s
gpie=0
gpif=0
asm sleep
nop
goto main
sub wake_up
goto main
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That works god for the first cycle, but the chip never returns to sleep, it just loops the main and "skips" the sleep command?
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
dir gpio.0 out
dir gpio.2 in
On Interrupt EXTINT0 call wake_up
main:
set gpio.0 on
wait 1 s
set gpio.0 off
wait 1 s
asm sleep
nop
goto main
sub wake_up
set gpio.0 on
wait 250 ms
set gpio.0 off
wait 250 ms
set gpio.0 on
wait 250 ms
set gpio.0 off
wait 250 ms
goto main
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Keep the interrupt routine as short as possible. Long delays are bad. Increment a counter, assess a condition, or toggle a boolean value and leave the interrupt ASAP. Process information from interrupt, at top of main.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Works for me. Sounds like a hardware problem, whereby the PIC wants to reset itself all the time. Things to check:
1) Be sure MCLR pulled up with 10k resistor.
2) Bypass the PIC with a 0.1uf cap as close to Vdd and Vss as possible.
3) Is the programmer holding the PIC in reset? disconnect and see.
4) If the PIC circuit is soldered on strip board, recheck for solder bridges.
5) Running batteries?, check for min 3V (preferably more) for 8Mhz osc.
6) Noisy power supply? Bypass with 100uf and 0.1uf caps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried all of those things, it acts likr the interrupt needs to be cleared and is not getting cleared. it runs through once and sleeps and then wakes when i pull the pin high just fine, but then when the pin goes low and stays low it never goes back to sleep after the first time, it just runs through the main skipping over the sleep?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it runs, then sleeps, but does not wake when i put pull gpio.1 high?
Here is my code:
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
dir gpio.0 out
dir gpio.1 in
on interrupt gpiochange call wake_up
main:
set gpio.0 on
wait 1 s
set gpio.0 off
wait 1 s
gpie=0
gpif=0
asm sleep
nop
goto main
sub wake_up
goto main
end sub
1. The easiest is to enable MCLRE in config, and put a button on MCLR, no interrupt routine required. .
2. For interrupt on pin change, the interrupt routine needs to know which pin is being used. So add this line prior to Main:
Set IOC.IOC1 On ;Set interrupt on change for gpio.1
3. If you use "On Interrupt EXTINT0 call wake_up" no pin setup is required. The interrupt pin (INT) is gpio.2.
Also, GCBasic clears the appropriate flags in the interrupt routine (i.e. gpie=0 and gpif=0 not required).
That works god for the first cycle, but the chip never returns to sleep, it just loops the main and "skips" the sleep command?
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
dir gpio.0 out
dir gpio.2 in
On Interrupt EXTINT0 call wake_up
main:
set gpio.0 on
wait 1 s
set gpio.0 off
wait 1 s
asm sleep
nop
goto main
sub wake_up
set gpio.0 on
wait 250 ms
set gpio.0 off
wait 250 ms
set gpio.0 on
wait 250 ms
set gpio.0 off
wait 250 ms
goto main
end sub
Keep the interrupt routine as short as possible. Long delays are bad. Increment a counter, assess a condition, or toggle a boolean value and leave the interrupt ASAP. Process information from interrupt, at top of main.
even with it this way it still loops and does not return to sleep:
#chip 12F683, 8 'mhz
#config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
dir gpio.0 out
dir gpio.2 in
On Interrupt EXTINT0 call wake_up
main:
set gpio.0 on
wait 1 s
set gpio.0 off
wait 1 s
asm sleep
nop
goto main
sub wake_up
goto main
end sub
Works for me. Sounds like a hardware problem, whereby the PIC wants to reset itself all the time. Things to check:
1) Be sure MCLR pulled up with 10k resistor.
2) Bypass the PIC with a 0.1uf cap as close to Vdd and Vss as possible.
3) Is the programmer holding the PIC in reset? disconnect and see.
4) If the PIC circuit is soldered on strip board, recheck for solder bridges.
5) Running batteries?, check for min 3V (preferably more) for 8Mhz osc.
6) Noisy power supply? Bypass with 100uf and 0.1uf caps.
I tried all of those things, it acts likr the interrupt needs to be cleared and is not getting cleared. it runs through once and sleeps and then wakes when i pull the pin high just fine, but then when the pin goes low and stays low it never goes back to sleep after the first time, it just runs through the main skipping over the sleep?
Leave out the goto main in the wake-up sub. GCBasic will return to its proper place after the retfie command in the interrupt service routine.
that did it thanks