This issue is not documented on Microchip. There is only one document TB3193 discussing active clock tuning for PIC16LF191XX with the 32KHz secondary oscillator. Below is the config I've tried, it does not work, the ACT is not locking. I can't understand how the reference clock required for active clock tuning is derived from the USB host as long communication does not work through the USB transceiver without clock. However some guy reported that ACT feature works with PIC18F25K50: https://www.microchip.com/forums/m847890.aspx. The smartest gives up....
include 18f25k50 -- target PICmicro
pragma target clock 48_000_000 -- oscillator frequency
pragma target PLLSEL PLL3X -- PLL multiplier
pragma target PLLEN ENABLED -- PLL select
pragma target CPUDIV P1 -- no divide
pragma target LS48MHz P8 -- USB 48MHz/8 = 6MHz
pragma target OSC INTOSC_NOCLKOUT -- internal OSC
pragma target PCLKEN ENABLED -- Primary Oscillator
pragma target FCMEN DISABLED -- Fail-Safe Clock Monitor
pragma target IESO DISABLED -- Oscillator Switchover mode
pragma target PWRTE ENABLED -- power up timer
pragma target BROWNOUT DISABLED -- no brownout detection
pragma target LPBOR DISABLED -- Low-Power Brown-out Reset
pragma target WDT CONTROL -- watchdog software controlled
pragma target PBADEN DIGITAL -- digital input port<0..4>
pragma target MCLR EXTERNAL -- master reset on MCLR
pragma target STVR DISABLED -- reset on stack over/under flow
pragma target LVP DISABLED -- low-voltage programming
pragma target ICPRT DISABLED -- In-Circuit Debug/Programming Port
pragma target XINST DISABLED -- Extended Instruction Set
pragma target DEBUG DISABLED -- Background Debugger
WDTCON_SWDTEN = OFF -- disable watchdog
include delay
include print
OSCCON_IRCF = 0b111 -- select INTOSC 16MHz
OSCCON_SCS = 0b00 -- select primary clock defined by CONFIG1H FOSC3:0
ACTCON_ACTEN = 0 -- ACT module disabled
ACTCON_ACTUD = 0 -- enable OSCTUNE update
ACTCON_ACTSRC = 1 -- set HFINTOSC to match with the USB host clock ?
?
ACTCON_ACTEN = 1 -- ACT module enabled
UCFG_FSEN = 1 -- USB full speed mode
UCFG_UPUEN = 1 -- pull_up enabled
UCFG_UTRDIS = 0 -- USB transciever enabled
delay_1mS ( 2 )
UCON_USBEN = 1 -- USB enabled, this bit cannot be enabled without apropiate clock source!
alias led_lock is pin_A0 -- alias for pin with LED ACTlock
pin_A0_direction = OUTPUT
alias led_range is pin_A1 -- alias for pin with LED OSCTUNE out of range
pin_A1_direction = OUTPUT
alias led is pin_A2 -- alias for pin with LED blink
pin_A2_direction = OUTPUT
for 100 loop
if ACTCON_ACTLOCK == 0 then
led_lock = OFF ; not locked
delay_1mS ( 1 )
elsif ACTCON_ACTLOCK == 1 then
led_lock = ON ;16MHz ACT locked
end if
end loop
if ACTCON_ACTORS == 1 then ; out of OSCAL range
led_range = on
elsif ACTCON_ACTORS == 0 then ; in the OSCAL range
led_range = off
end if
enable_digital_io() -- make all pins digital I/O
INTCON_GIE = false
const byte str_welcome[] = "USB Serial HFINTOSC Demo app\n"
include usb_serial
usb_serial_init()
var bit has_shown_welcome_msg = true
var byte ch = "A"
forever loop
if ( usb_cdc_line_status() != 0x00 ) then
if !has_shown_welcome_msg then
has_shown_welcome_msg = true
print_string( usb_serial_data, str_welcome )
end if
else
has_shown_welcome_msg = false
end if
usb_serial_flush()
usb_serial_data = ch
; _usec_delay(100_000)
led = ON
_usec_delay(100_000)
led = OFF
_usec_delay(400_000)
end loop