• AVR Freaks

PIC32MK1024MCF100 crystal oscillator initialization

Author
MPaulHolmes
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2009/10/31 10:52:40
  • Location: 0
  • Status: offline
2019/11/13 14:02:58 (permalink)
0

PIC32MK1024MCF100 crystal oscillator initialization

I'm slogging my way through a bunch of datasheets trying to figure out how to configure system clock with an external crystal.  My ultimate goal is to have 120MHz system clock with the minimum amount of jitter. I'm not using the USB.  I'm using a regular old surface mount 2 pin external crystal with a 20pF load capacitance.  I'm using 2 load capacitors that are 30pF.   I don't know what MHz the crystal should be yet.  The clock initialization is so much more complicated on this chip than on the dsPIC30F family.  
 
Here's where I am so far:
I have no idea what the POSCGAIN should be (3 is highest, 0 is lowest).  The default is 3.  So maybe that's good?
Can I just do "clock switch disabled, fail safe clock mode disabled" if I am using an external crystal, or must I start with the internal oscillator and switch to the external crystal at startup?  
Should I "boost the kickstart of the oscillator"?  LOL.  There's no information in any datasheet that I've seen about POSCBOOST.  I'm fine with a relatively slow startup.  I don't want to do anything weird.  I always have the code just sit there and do nothing for a few hundred milliseconds at startup anyway.
 
So, let's say I pick a 10MHz external crystal.  So, the first thing that happens is, I set PLLIDIV to 1.  so, it's still 10MHz and in the range of 5-64MHz.  Next, I choose FPLLRNG = "8-16MHz".  Now, I can do FPLLMULT = 48, and FPLLODIV = 4, and you get SPLL = 120MHz.  OK.  
 
Now, for the ADCs, I CANNOT set REFCLKx to SPLL, because SPLL is 120MHz, and REFCLKx input must be <= 50MHz.  So, I could set REFCLKx to POSC.  So, I guess this is why I would choose a higher POSC in the first place...
 
Then, you can use SPLL for the SYSCLK, and from that you get the clock for all the timers and PWM.  
 
#1

2 Replies Related Threads

    LostInSpace
    Super Member
    • Total Posts : 276
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: PIC32MK1024MCF100 crystal oscillator initialization 2019/11/14 18:44:03 (permalink)
    5 (2)
    This is what I would do (feel free to ignore any of it).
     
    I see that Harmony 2.x supports this device -
    1) I would load that and use the graphical wizards to set the clocks, etc. They provide wonderful feedback and are quick to use.
    2) Build the project to generate the code.
    3) Look at the startup files that are generated to see how they set everything up.
    4) Discard and do it by hand at this point if you wish, but at least you used the Wizards to help you out.
     
    Many people get all worked up about Harmony and this is really a result of bad information, Harmony can be used as a simple chip configurator just like everyone else's chip configurator, no extra overhead at all required.
     
    I wrote a Tutorial on this and you may find it helpful,
    https://analoghome.blogspot.com/2019/07/microchip-pic32-harmony-bare-metal.html
     
    I hope this helps.... As I said, this is what I would do - As they say in Detroit: "your mileage may vary".
     
     
    #2
    MPaulHolmes
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2009/10/31 10:52:40
    • Location: 0
    • Status: offline
    Re: PIC32MK1024MCF100 crystal oscillator initialization 2019/11/15 12:50:38 (permalink)
    0
    Thanks!  I'll try that out.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5