Advertisement
Guest User

Untitled

a guest
Dec 26th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /* Configure Oscillator to operate the device at 4Mhz */
  2. // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
  3. // M is PLLDIV + 2
  4. PLLFBDbits.PLLDIV = 41;
  5. // N1 is PLLPRE + 2
  6. CLKDIVbits.PLLPRE = 78; //N1 is 80
  7. // N2 is 2*(PLLPOST + 1) // N2 is 1
  8. CLKDIVbits.PLLPOST = 0;
  9. // Fosc = Fin * 43/(80) = Fin * 128; 7.37 * 43/ 80 = 4Mhz
  10. // Fcy = Fosc / frcdiv (if 0 then 1)
  11. CLKDIVbits.FRCDIV = 0;
  12.  
  13. _FOSCSEL(FNOSC_FRCPLL);
  14. CLKDIVBITS.FRCDIV = 0; //FRC Divid-by-1
  15. OSCTUNbits = 0; //7.373Mhz
  16.  
  17. /* Configure Oscillator to operate the device at 4Mhz */
  18. // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
  19. // M is PLLDIV + 2
  20. PLLFBDbits.PLLDIV = 41;
  21. // N1 is PLLPRE + 2
  22. CLKDIVbits.PLLPRE = 78; //N1 is 80
  23. // N2 is 2*(PLLPOST + 1) // N2 is 1
  24. CLKDIVbits.PLLPOST = 0;
  25. // Fosc = Fin * 43/(80) = Fin * 128; 7.37 * 43/ 80 = 4Mhz
  26. // Fcy = Fosc / frcdiv (if 0 then 1)
  27. CLKDIVbits.FRCDIV = 0;
  28.  
  29. // FOSC
  30. #pragma config POSCMD = NONE // Primary Oscillator Mode Select bits (Primary Oscillator disabled)
  31. #pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is clock output)
  32. #pragma config IOL1WAY = ON // Peripheral pin select configuration (Allow only one reconfiguration)
  33. #pragma config FCKSM = CSDCMD // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are disabled)
  34.  
  35.  
  36. // FOSCSEL
  37. #pragma config FNOSC = FRCDIVN // Oscillator Source Selection (Internal Fast RC (FRC) Oscillator with postscaler)
  38. #pragma config PWMLOCK = ON // PWM Lock Enable bit (Certain PWM registers may only be written after key sequence)
  39. #pragma config IESO = ON // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement