hkBattousai
Advanced Member level 4
MPLAB>Help>Topics>Language Tools>PIC18 Config Settings said:Code:PLL // Prescaler Selection bits: PLLDIV = 1 // No prescale (4 MHz oscillator input drives PLL directly) PLLDIV = 2 // Divide by 2 (8 MHz oscillator input) PLLDIV = 3 // Divide by 3 (12 MHz oscillator input) PLLDIV = 4 // Divide by 4 (16 MHz oscillator input) PLLDIV = 5 // Divide by 5 (20 MHz oscillator input) PLLDIV = 6 // Divide by 6 (24 MHz oscillator input) PLLDIV = 10 // Divide by 10 (40 MHz oscillator input) PLLDIV = 12 // Divide by 12 (48 MHz oscillator input) // CPU System Clock Postscaler: CPUDIV = OSC1_PLL2 // [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2] CPUDIV = OSC2_PLL3 // [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3] CPUDIV = OSC3_PLL4 // [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4] CPUDIV = OSC4_PLL6 // [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6] // USB Clock Selection bit (used in Full Speed USB mode only; UCFG:FSEN = 1): USBDIV = 1 // USB clock source comes directly from the primary oscillator block with no postscale USBDIV = 2 // USB clock source comes from the 96 MHz PLL divided by 2 // Oscillator Selection bits: FOSC = XT_XT // XT oscillator, XT used by USB FOSC = XTPLL_XT // XT oscillator, PLL enabled, XT used by USB FOSC = ECIO_EC // External clock, port function on RA6, EC used by USB FOSC = EC_EC // External clock, CLKOUT on RA6, EC used by USB FOSC = ECPLLIO_EC // External clock, PLL enabled, port function on RA6, EC used by USB FOSC = ECPLL_EC // External clock, PLL enabled, CLKOUT on RA6, EC used by USB FOSC = INTOSCIO_EC // Internal oscillator, port function on RA6, EC used by USB FOSC = INTOSC_EC // Internal oscillator, CLKOUT on RA6, EC used by USB FOSC = INTOSC_XT // Internal oscillator, XT used by USB FOSC = INTOSC_HS // Internal oscillator, HS used by USB FOSC = HS // HS oscillator, HS used by USB FOSC = HSPLL_HS // HS oscillator, PLL enabled, HS used by USB
I have two matters to consider:
1) I will use a 20MHz crystal for external oscillator.
2) I will use USB feature of the PIC
I read the datasheet of the PIC which says (at page 32) that for the case of using a 20MHz crystal these are the settings which I have to choose:
1) PLL Division (PLLDIV2LLDV0): +5 (100)
2) Clock Mode (FOSC3:FOSC0): HSPLL, ECPLL, ECPIO
3) MCU Clock Division (CPUDIV1:CPUDIV0): +4 (10)
I'm totally lost!
The PIC datasheet and MPLAB help file are talking in different languages.
I know I must add some "#pragma config xxx=yyy" lines at the beginning of my code, but I don't know what to add. The thing I want to learn most is what the CPUDIV value mean; what does "[OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]" mean? I googled for an hour and couldn't find any relevant result. Can anyone please help me add the required "pragma" lines in my code?