Latest version of my quadcopter controller with an LPC1768 and MPU9250.

Dependencies:   mbed

Currently running on a custom PCB with 30.5 x 30.5mm mounts. There are also 2 PC apps that go with the software; one to set up the PID controller and one to balance the motors and props. If anyone is interested, send me a message and I'll upload them.

ClockControl/ClockControl.cpp

Committer:
Anaesthetix
Date:
2018-07-31
Revision:
8:981f7e2365b6
Parent:
0:0929d3d566cf

File content as of revision 8:981f7e2365b6:

#include "ClockControl.h"

void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N)
{
      LPC_SC->CLKSRCSEL = clkSrc;
      LPC_SC->PLL0CFG   = (((unsigned int)N-1) << 16) | M-1;
      LPC_SC->PLL0CON   = 0x01;             
      LPC_SC->PLL0FEED  = 0xAA;
      LPC_SC->PLL0FEED  = 0x55;
      while (!(LPC_SC->PLL0STAT & (1<<26)));
    
      LPC_SC->PLL0CON   = 0x03;
      LPC_SC->PLL0FEED  = 0xAA;
      LPC_SC->PLL0FEED  = 0x55;
}

void setPLL1Frequency(unsigned char clkSrc, unsigned short M, unsigned char N)
{
      LPC_SC->CLKSRCSEL = clkSrc;
      LPC_SC->PLL1CFG   = (((unsigned int)N-1) << 16) | M-1;
      LPC_SC->PLL1CON   = 0x01;             
      LPC_SC->PLL1FEED  = 0xAA;
      LPC_SC->PLL1FEED  = 0x55;
      while (!(LPC_SC->PLL1STAT & (1<<26)));
    
      LPC_SC->PLL1CON   = 0x03;
      LPC_SC->PLL1FEED  = 0xAA;
      LPC_SC->PLL1FEED  = 0x55;
}

unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N)
{
    setPLL0Frequency(clkSrc, M, N);
    LPC_SC->CCLKCFG = clkDivider - 1;
    SystemCoreClockUpdate();
    return SystemCoreClock;
}