GL82
Joined: 12 Jun 2019 Posts: 15
|
18F67K40. Fail Safe Clock Monitor |
Posted: Wed Jun 12, 2019 2:26 am |
|
|
Hi everybody,
I am having problems in my new project with the configuration of the fail safe clock monitor frequency of the PIC18F67K40.
I am using external quartz of 8Mhz with PLL so I configured the following fuses (HS and PLL)
#include <18F67K40.h>
#device ADC=10 //lectura del ADC = 10bits
#use delay(clock = 32000000)
#fuses HS,RSTOSC_EXT_PLL,PROTECT,NOLVP,PUT,MCLR,BROWNOUT, BORV28,PROTECT,WDT,WDT65536,FCMEN // watchdog = 3.9ms x 128 = 0.5s
In this conditions if I make the external oscillator fail, the fail safe clock monitor switch to the HF int oscillator. I can see it clearly beacuse the speed of the program is reduce in 4 times (from 32Mhz to 4MHz)
I want to program the HF int oscillator to 32Mhz in case external quartz fails the program will not be affected.
However I am not achieving that. I have define a bit variable OSCFIF (PIR1.bit7) that should set when external oscillator fails. When that happens the green loop should execute and configure the HF int oscillator to 16Mhz (the fail safe monitor should had switched to internal oscillator before)
#byte PIR1 = getenv("SFR:PIR1")
#bit OSCFIF = PIR1.7
void main(void) {
inicializaciones();
while (TRUE) {
restart_wdt();
if (CCP1IF) { // bucle control lento cada 10ms (100 Hz):
output_high(PIN_C2);
CCP1IF = 0; // borrar flag de CCP1
if ((OSCFIF == 1)&&(internalOscRC == 0)){
internalOscRC = 1;
setup_oscillator(OSC_HFINTRC_16MHZ);
delay_ms(10);
}
leerEntradasDigitales(); //función lectura de entradas digitales
leerEntradasAnalogicas(); //función lectura de entradas analógicas
SelectIdioma();
gestionMenu(); //función del menu de programación/visualización
grabarEEPROM();
imprimirDisplay(); //función de escritura del display
gestionRS232(); //función de gestión de la comunicación con VF
gestionFSM();
gestionPRINCIPAL();
gestionBOTONES();
gestionMOVIMIENTO();
}
}
However I can check that when external oscillator fails, the program runs at 4 MHz so I can imagine that my green loop is not correctly programmed.
What am I doing wrong?
Thanks in advance, |
|