Configuración del cristal para 18Fxx5x con USB

En este apartado se muestra cómo configurar correctamente los "fuses". Aunque no utilices el USB estas configuraciones te permitirá hacer funcionar el PIC a 48MHz, es decir, a su máxima velocidad independientemente del cristal que estés utilizando siempre que sea uno de los que verás en la lista.

Es muy importante poner correctamente estos detalles porque si no la parte USB no funcionaría. Comenzamos con CCS y más abajo en Proton IDE.

Nota: El cristal de frecuencia más alta que puedes poner es de 24 MHz; no funciona con cristales de más frecuencia. Para frecuencias superiores a 24MHz sería necesario un oscilador externo*.

CCS y la configuración del cristal u oscilador con el PLL interno.

Verás que sólo cuando usamos 4MHz se pone XTPLL y en frecuencias mayores es HSPLL.

 4MHz:      #Fuses XTPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL1, CPUDIV1, VREGEN
 8MHz:      #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL2, CPUDIV1, VREGEN
 12MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL3, CPUDIV1, VREGEN
 16MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL4, CPUDIV1, VREGEN
 20MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL5, CPUDIV1, VREGEN
 24MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL6, CPUDIV1, VREGEN
  *40MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL10, CPUDIV1, VREGEN 
 *48MHz:     #Fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL12, CPUDIV1, VREGEN

Proton IDE y la configuración del cristal u oscilador con el PLL interno.

Verás que sólo cuando usamos 4MHz se pone FOSC_XTPLL_XT_1 y en frecuencias mayores es FOSC_HSPLL_HS_1.

Nota:

  • En Proton IDE, si usas un cristal de 20MHz no hace falta declarar esta parte porque ya viene por defecto configurado para ese cristal. Uso la versión de compilador: 3.2.5.5, y versión IDE: 1.0.4.6. Es posible que si usas una versión antigua de compilador, la parte de declarar el cristal para el USB te pueda dar un error; si así fuese tendrás que actualizar tu compilador Proton.
  • La @ significa que es una instrucción en ensamblador, los comentarios que se hagan detrás de las instrucciones en ensamblador hay poner un ; (punto y coma) en vez de una ' (una comilla).

Los únicos cambios son las letras en negrita, todo lo demás es exactamente lo mismo.

Cristal de 4MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_1_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_XTPLL_XT_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Cristal de 8MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_2_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Cristal de 12MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_3_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Cristal de 16MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_4_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Cristal de 20MHz:

Nota: En ProtonIDE, si no declaras el valor del cristal, por defecto lo compila para uno de 20Mhz., entonces no haría falta declararlo si vas a usar esa frecuencia. De todas formas la configuración es tal como lo ves y puede servirte de ejemplo para modificar otros "fuses" si en tu proyecto fuera necesario.

@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_5_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Para 24MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_6_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Para 40MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_10_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3
Para 48MHz:
@CONFIG_REQ
        @PLL_REQ
            @__config config1l, PLLDIV_12_1 & CPUDIV_1_1 & USBDIV_2_1
            @__config config1h, FOSC_HSPLL_HS_1
        @WATCHDOG_REQ
            @__config config2h, WDT_OFF_2 & WDTPS_128_2
        @DEBUG_REQ        
            @__config config4l, LVP_OFF_4 & ICPRT_OFF_4 & XINST_OFF_4 & DEBUG_OFF_4
            @__config config3h, PBADEN_OFF_3