CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F67K40. Fail Safe Clock Monitor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
GL82



Joined: 12 Jun 2019
Posts: 15

View user's profile Send private message

18F67K40. Fail Safe Clock Monitor
PostPosted: Wed Jun 12, 2019 2:26 am     Reply with quote

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,
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Wed Jun 12, 2019 6:09 am     Reply with quote

The CKS fuse needs to be set. Otherwise software cannot switch from the
default clock settings (This is the CSWEN bit in the Microchip data sheet).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group