Hot!24FJ64GB002 Clockout problem

Author
barrdgn@gmail.com
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2017/06/02 14:43:01
  • Location: 0
  • Status: offline
2018/01/13 16:13:35 (permalink)
0

24FJ64GB002 Clockout problem

Hello,
 
I am having a problem regarding clock PLL using 8 MHz crystal, my configs are following,
 
#pragma config DSWDTPS = DSWDTPS3 // DSWDT Postscale Select (1:128 (132 ms))
#pragma config DSWDTOSC = LPRC // Deep Sleep Watchdog Timer Oscillator Select (DSWDT uses Low Power RC Oscillator (LPRC))
#pragma config RTCOSC = SOSC // RTCC Reference Oscillator Select (RTCC uses Secondary Oscillator (SOSC))
#pragma config DSBOREN = OFF // Deep Sleep BOR Enable bit (BOR disabled in Deep Sleep)
#pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer (DSWDT disabled)

// CONFIG3
#pragma config WPFP = WPFP0 // Write Protection Flash Page Segment Boundary (Page 0 (0x0))
//#pragma config SOSCSEL = SOSC // Secondary Oscillator Pin Mode Select (SOSC pins in Default (high drive-strength)Oscillator Mode) // default
#pragma config SOSCSEL = IO // Secondary Oscillator Pin Mode Select (SOSC pins in Default (high drive-strength) Oscillator Mode) // added for making RA4 and RB4 operational
#pragma config WUTSEL = LEG // Voltage Regulator Wake-up Time Select (Default regulator start-up time used)
#pragma config WPDIS = WPDIS // Segment Write Protection Disable (Segmented code protection disabled)
#pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select (Last page and Flash Configuration words are unprotected)
#pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)

// CONFIG2
#pragma config POSCMOD = HS // Primary Oscillator Select (HS Oscillator mode selected)
#pragma config I2C1SEL = PRI // I2C1 Pin Select bit (Use default SCL1/SDA1 pins for I2C1 )
#pragma config IOL1WAY = OFF // IOLOCK One-Way Set Enable (The IOLOCK bit can be set and cleared using the unlock sequence)
//#pragma config OSCIOFNC = ON // OSCO Pin Configuration (OSCO pin functions as port I/O (RA3)) // Default
#pragma config OSCIOFNC = OFF // OSCO Pin Configuration (OSCO functions as CLKO (FOSC/2)) // added For clock out
#pragma config FCKSM = CSDCMD // Clock Switching and Fail-Safe Clock Monitor (Sw Disabled, Mon Disabled)
#pragma config FNOSC = PRIPLL // Initial Oscillator Select (Primary Oscillator with PLL module (XTPLL, HSPLL, ECPLL))
#pragma config PLL96MHZ = ON // 96MHz PLL Startup Select (96 MHz PLL Startup is enabled automatically on start-up)
#pragma config PLLDIV = DIV2 // USB 96 MHz PLL Prescaler Select (Oscillator input divided by 2 (8 MHz input))
#pragma config IESO = OFF // Internal External Switchover (IESO mode (Two-Speed Start-up) disabled)

// CONFIG1
#pragma config WDTPS = PS1 // Watchdog Timer Postscaler (1:1)
#pragma config FWPSA = PR32 // WDT Prescaler (Prescaler ratio of 1:32)
#pragma config WINDIS = OFF // Windowed WDT (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF // Watchdog Timer (Watchdog Timer is disabled)
#pragma config ICS = PGx1 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1)
#pragma config GWRP = OFF // General Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)

 
and in SYSTEM_Initialize function I enable PLL with following register 
 CLKDIVbits.PLLEN = 1;
 
I am expecting 16Mhz clockout when I measure CLKO(pin 10)
but I am getting 7.99 Mhz
why I am not able to get 16 Mhz?
should not I have got FOSC/2 (32/2=16Mhz) 
 
Thank you
Regards 
 
 
#1

11 Replies Related Threads

    jtemples
    Super Member
    • Total Posts : 10406
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/13 18:14:37 (permalink)
    4 (1)
    You haven't shown your CLKDIV or CPDIV settings.
    #2
    barrdgn@gmail.com
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/06/02 14:43:01
    • Location: 0
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 03:32:42 (permalink)
    0
    Hello,

    I have never set anything except CLKDIVbits.PLLEN
    Do I need to set all CLKDIV register?
    I thought only PLLEN would be enough,
    Am I wrong?

    Thank you
    Regards
    #3
    qɥb
    Monolothic Member
    • Total Posts : 626
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 04:44:52 (permalink)
    0
    barrdgn@gmail.com
    I have never set anything except CLKDIVbits.PLLEN
    Do I need to set all CLKDIV register?

    Yes

    I thought only PLLEN would be enough,

    No
     

    Am I wrong?

    Yes

    PicForum "it just works" (again)
    #4
    barrdgn@gmail.com
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/06/02 14:43:01
    • Location: 0
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 06:40:49 (permalink)
    0
    Hello,

    I set followings

    CLKDIVbits.PLLEN = 1
    CLKDIVbits.CPDIV = 0
    CLKDIVbits.RCDIV = 0

    But nothing's changed
    Any thoughts?

    Thank you
    Regards
    #5
    davekw7x
    Entropy++
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 10:21:03 (permalink)
    0
    barrdgn@gmail.com
    ...8 MHz crystal...
     
    #pragma config POSCMOD = HS // Primary Oscillator Select (HS Oscillator mode selected)
    ...
    #pragma config FNOSC = PRIPLL // Initial Oscillator Select (Primary Oscillator with PLL module (XTPLL, HSPLL, ECPLL))

    I am expecting 16Mhz clockout...
     
    should not I have got FOSC/2 (32/2=16Mhz)

    No.
    With POSCMOD = HS and FNOSC = PRIPLL, you are seeing the crystal frequency.  Note that 'scope probe adds a little capacitance, so the measurement probably pulls the frequency down a little.
     
    [/Begin Edit]
    If you want to verify visually that it's running at 32 MHz (16 MIPS) you can try something like the following
    // Put your configuration settings here
    //
    // To use __delay_ms, must define FCY before including libpic30.h
    #define FCY 16000000UL
    #include <libpic30.h>

    //
    #define LED1        LATBbits.LATB0
    #define LED1_TRIS   TRISBbits.TRISB0

    int main()
    {
        LED1_TRIS = 0;
        LED1 = 0;
        while (1) {
            LED1 = !LED1;
            __delay_ms(1000);
        }
    }

    If it is running at 32 MHz, the LED will flash with a cadence of one second on, one second off.
    For a somewhat more precise indication, put a 'scope probe on the LED pin and change __delay_ms(1000) to __delay_us(500).  If it's running at 32MHz you will see a 1 kHz (approximately) square wave on the LED pin.
     
    That's what I get with your configuration settings and no other initialization.
    [/End Edit]
     
    (Tested on my PIC24FJ64GB002 breadboard.)
     
     
    Regards,

    Dave
    post edited by davekw7x - 2018/01/14 10:39:30

    Sometimes I just can't help myself...
    #6
    barrdgn@gmail.com
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/06/02 14:43:01
    • Location: 0
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 10:46:18 (permalink)
    0
    Hello,

    I don't wanna see crystall frequency. I wanna see FOSC/2, 16Mhz,
    How should I set the register values for 16Mhz clockout?
    Does This result indicate that my MCU's FCY is 8MHZ and FOSC is 16Mhz?

    But I need two times of them
    FCY should be 16MHz and FOSC should be 32MHz so that MCU can drive clock out with 16MHz

    I think I could not run MCU with 32MHz
    How can I do that?

    Thank you
    Regards
    #7
    davekw7x
    Entropy++
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 10:49:28 (permalink)
    0
    qɥb
    barrdgn@gmail.com
    I have never set anything except CLKDIVbits.PLLEN
    Do I need to set all CLKDIV register?

    Yes

    I thought only PLLEN would be enough,

    No
     

    Am I wrong?

    Yes



    No, the OP is correct.  With his configuration pragmas, default values in CLKDIV make it run at 32 MHz. See my previous post about why he is seeing 8 MHz.
     
    Regards,

    Dave

    Sometimes I just can't help myself...
    #8
    davekw7x
    Entropy++
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 10:54:03 (permalink)
    0
    barrdgn@gmail.com
    I don't wanna see crystall frequency.

    Well with the primary oscillator enabled, and it set to run PRIPLL, you are going to see the crystal frequency.  Period.
    barrdgn@gmail.com
    Does This result indicate that my MCU's FCY is 8MHZ and FOSC is 16Mhz?


    I edited my post to show how to verify operating frequency. (I'm sorry I didn't edit it more quickly.  I was working on the edit when you replied)
     
    Bottom line:
    There is no way to verify it directly. 
     
    As I mentioned: With your configuration pragmas, it is running at 32 MHz according to my tests.  I was also able to initialize and operate a UART and a timer based on FCY = 16 MHz, so it really is working.
     
    Regards,

    Dave
    post edited by davekw7x - 2018/01/14 11:02:18

    Sometimes I just can't help myself...
    #9
    barrdgn@gmail.com
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/06/02 14:43:01
    • Location: 0
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 11:50:45 (permalink)
    0
    Hello,

    Why I am seeing 8MHz clockout is totally regarding primary osc and pll settings right?

    If so, I will never see 16Mhz as clock out on pin 10 as I tied 8Mhz crystall into it?

    Or infact that it successfully drives 16Mhz square wave out through pin 10 but I cannot see because of measurement equipment's capacitive behaviour?

    Datasheet matter 8.7 reference clock output says

    "clko is available in certain oscillator modes" but does not mention which mode is suitable for clko

    In which oscillator mode I can make clock out?

    Thank you
    Regards
    #10
    davekw7x
    Entropy++
    • Total Posts : 1288
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 12:27:34 (permalink)
    0
    barrdgn@gmail.com
    ...
    In which oscillator mode I can make clock out?
    ...

    If you have POSCMD set to HS or XT, the pins OSCI and OSCO are I/O for an internal oscillator.  You connect a crystal, and that's what you see.  (Well, depending on the frequency and the crystal and the probe, it's possible that the crystal will even stop oscillating at all)
     
    So, first of all, POSCMD must NOT be set to HS or XT.  Setting it OFF is OK.  Haven't tested EC, but I would guess it's OK.
     
    Then, to get it work at all, FNOSC must not be set to PRI or PRIPLL.  I mean, since the oscillator is off, selecting one of PRI options simply won't work. Period.
     
    For sure: FRC, FRCDIV and FRCPLL will be OK.  Haven't tested others.
     
    I don't know why you are obsessing about measuring the operating frequency directly on the CLK0 pin.  You simply can't measure it directly on that pin if you are operating in one of the crystal modes.  Period.
     
    I told you a way to verify the approximate operating frequency.  Since using __delay_ms() or __delay_us() in a loop will not give an exact cycle-correct overall delay between output changes, it will be off by a few instruction cycle times, but it won't be off by, say, a factor of 2 or 4 (which are, I think, the most likely errors that people make).
     
    And, by the way, if your design doesn't use the REFO pin for anything else, just keep reading Section 8.7:
    Data Sheet, DS39940D, with emphasis added by davekw7x
    In addition to the CLKO output (FOSC/2) available in certain
    oscillator modes, the device clock in the
    PIC24FJ64GB004 family devices can also be configured
    to provide a reference clock output signal to a port pin.
    This feature is available in all oscillator configurations
    and allows the user to select a greater range of clock
    submultiples to drive external devices in the application

    So, maybe you can read about REFO pin and how to get a reference clock on that pin.

    Regards,

    Dave
     
    post edited by davekw7x - 2018/01/14 13:07:30

    Sometimes I just can't help myself...
    #11
    barrdgn@gmail.com
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2017/06/02 14:43:01
    • Location: 0
    • Status: offline
    Re: 24FJ64GB002 Clockout problem 2018/01/14 13:07:51 (permalink)
    0
    Hello,

    OK I see I have been making pll with internal oscillator since I used hs and pll

    I am insisting because I am using that clock for all the chips that need clock signal in the board for making sure that in all sync with same clocking.
    I will use your way to make sure whether my FCY is OK with 16MHz.
    I cannot use REFO because my I/O pins run it fine. I may wanna upgrade my MCU to another one

    I was totally confused by oscillator modes
    I understand that I have been using wrong config registers

    Thanks a lot for your advices and clarifications

    Regards
    #12
    Jump to:
    © 2018 APG vNext Commercial Version 4.5