POR vs WDT reset oscillator behaviour
Posting this in case of use or interest to others.
PIC16F18345, XC8 v1.44 Pro Mode
I am running an 8MHz crystal on OSC1 and OSC2 and have for CONFIG1:
#pragma config FEXTOSC = HS // FEXTOSC External Oscillator mode Selection bits (HS (crystal oscillator) above 4 MHz)
#pragma config RSTOSC = EXT1X // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits )
At all times my scope indicates the oscillator is producing a clean and stable 8MHz waveform.
Weirdly (to me), every time my circuit had power applied, it would execute code at double the expected speed (FOSC=16MHz). If I set the circuit to hit a WDT reset after 32s, after the WDT reset, code would execute at the expected speed (FOSC=8MHz). After the reset in each case, the executed code was exactly the same.
I printed NOSC and COSC after the resets. This showed that COSC after POR was 0b110 (not the expected 0b111), which combined with the default HFINTOSC value (0b0110), runs the HFINTOSC at 16MHz (causing double speed execution). After the WDT reset, COSC reset to 0b111 and the external 8MHz oscillator was used as expected. Simple solution was to write 0b111 to NOSC in the start up code.
But I am a bit puzzled why COSC did not match the CONFIG1 setting after POR, but did after WDT....??
post edited by bluewave - 2020/10/01 20:23:31