I need use watchdog timer for PIC12F629 microcontroller runs 2,3 seconds. The microcontroller will run with 4 MHz frequency and watchdog will run with interval 2,3s. How could I config the microcontroller? Do I need use OPTION_REG = b'????????'?
This a simple code (for test... modified):
chip 12F629, 4
config CPD = On
config CP = Off
config BODEN = On
config MCLRE = Off
config PWRTE = Off
config WDTE = On
config OSC=INTRC_OSC_NOCLKOUT
Dir GPIO.0 Out ' Canal 1
Dir GPIO.1 Out ' Canal 2
Dir GPIO.2 In ' interrupção do sensor Hall
Dir GPIO.3 In ' retorno chave de segurança
Dir GPIO.4 Out ' led verde -> motor funcionando
Dir GPIO.5 Out ' led vermelho -> motor parado
Dim Tempo_espera as integer ' conta número de interrupções do temporizador. Usado para gerar a frequência
Dim Freq_Acionada as bit
'---------------------------- Inicio do Software -------------------------------
inicio:
set GPIO.5 Off
nop
set GPIO.5 On
nop
CLRWDT
goto inicio
end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unless you want to change the max (by default) prescaler, loading OPTION register isn't necessary. But if you want to be sure then go ahead. Here is demo of WDT(E) timeout period:
#chip 12f1822, 4
#config WDTE=ON
#define Led GPIO.2
Dir Led Out
'prescale assigned to WDT, load max prescale value
'movlw 255
'OPTION
OPTION_REG = b'11111111'
Main:
Set Led On
wait 1 s
Set Led Off
asm sleep
nop
Goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello kent_twt4... Thanks for your answer !!! Is there other form to use watchdog(..."loading OPTION register isn't necessary"...)? Shouldn't I use CLRWDT to clear (reset) period of watchdog? I don't understand --> "asm sleep".
Thanks !!!!
Cristiano Henz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, my example is one form of two that I am aware of. One is to use the WDT to wake from sleep (low power mode), perform a function, then go back to low power or sleep mode.
The second function of using the WDT/CLRWDT is to prevent the micro/code from getting stuck (failsafe) for more than the WDT timeout period.
The asm sleep, is really just the PIC assembler "sleep" intruction for standby mode. Some time ago (maybe a long time ago) the "asm" precursor for some assembler instructions were required by GCB. It looks like Hugh has patched this.
Here in this example the WDT intervenes to keep the code from waiting the full 10 seconds.
#chip 12f1822, 4
#config WDTE=ON
#define Led GPIO.2
Dir Led Out
'prescale assigned to WDT, load max prescale value
'movlw 255
'OPTION
OPTION_REG = b'11111111'
Main:
Set Led On
wait 1 s
CLRWDT
Set Led Off
wait 10 s
'sleep
'asm sleep
'nop
Goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello friends...
I need use watchdog timer for PIC12F629 microcontroller runs 2,3 seconds. The microcontroller will run with 4 MHz frequency and watchdog will run with interval 2,3s. How could I config the microcontroller? Do I need use OPTION_REG = b'????????'?
This a simple code (for test... modified):
chip 12F629, 4
config CPD = On
config CP = Off
config BODEN = On
config MCLRE = Off
config PWRTE = Off
config WDTE = On
config OSC=INTRC_OSC_NOCLKOUT
Dir GPIO.0 Out ' Canal 1
Dir GPIO.1 Out ' Canal 2
Dir GPIO.2 In ' interrupção do sensor Hall
Dir GPIO.3 In ' retorno chave de segurança
Dir GPIO.4 Out ' led verde -> motor funcionando
Dir GPIO.5 Out ' led vermelho -> motor parado
Dim Tempo_espera as integer ' conta número de interrupções do temporizador. Usado para gerar a frequência
Dim Freq_Acionada as bit
'---------------------------- Inicio do Software -------------------------------
inicio:
set GPIO.5 Off
nop
set GPIO.5 On
nop
CLRWDT
goto inicio
end
Unless you want to change the max (by default) prescaler, loading OPTION register isn't necessary. But if you want to be sure then go ahead. Here is demo of WDT(E) timeout period:
Hello kent_twt4... Thanks for your answer !!! Is there other form to use watchdog(..."loading OPTION register isn't necessary"...)? Shouldn't I use CLRWDT to clear (reset) period of watchdog? I don't understand --> "asm sleep".
Thanks !!!!
Cristiano Henz
Yes, my example is one form of two that I am aware of. One is to use the WDT to wake from sleep (low power mode), perform a function, then go back to low power or sleep mode.
The second function of using the WDT/CLRWDT is to prevent the micro/code from getting stuck (failsafe) for more than the WDT timeout period.
The asm sleep, is really just the PIC assembler "sleep" intruction for standby mode. Some time ago (maybe a long time ago) the "asm" precursor for some assembler instructions were required by GCB. It looks like Hugh has patched this.
Here in this example the WDT intervenes to keep the code from waiting the full 10 seconds.
Oh kent_twt4... I resolved the problem !!! the watchdog timer have 18 ms overflow, then I can realize 2,3 seconds using prescaler (1,1,1)...
Thanks for help !!!!
Cristiano Henz