Latest version of my quadcopter controller with an LPC1768 and MPU9250.
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@0:0929d3d566cf, 2018-07-09 (annotated)
- Committer:
- Anaesthetix
- Date:
- Mon Jul 09 16:31:40 2018 +0000
- Revision:
- 0:0929d3d566cf
Latest version of my multicopter controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:0929d3d566cf | 1 | #include "ClockControl.h" |
Anaesthetix | 0:0929d3d566cf | 2 | |
Anaesthetix | 0:0929d3d566cf | 3 | void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N) |
Anaesthetix | 0:0929d3d566cf | 4 | { |
Anaesthetix | 0:0929d3d566cf | 5 | LPC_SC->CLKSRCSEL = clkSrc; |
Anaesthetix | 0:0929d3d566cf | 6 | LPC_SC->PLL0CFG = (((unsigned int)N-1) << 16) | M-1; |
Anaesthetix | 0:0929d3d566cf | 7 | LPC_SC->PLL0CON = 0x01; |
Anaesthetix | 0:0929d3d566cf | 8 | LPC_SC->PLL0FEED = 0xAA; |
Anaesthetix | 0:0929d3d566cf | 9 | LPC_SC->PLL0FEED = 0x55; |
Anaesthetix | 0:0929d3d566cf | 10 | while (!(LPC_SC->PLL0STAT & (1<<26))); |
Anaesthetix | 0:0929d3d566cf | 11 | |
Anaesthetix | 0:0929d3d566cf | 12 | LPC_SC->PLL0CON = 0x03; |
Anaesthetix | 0:0929d3d566cf | 13 | LPC_SC->PLL0FEED = 0xAA; |
Anaesthetix | 0:0929d3d566cf | 14 | LPC_SC->PLL0FEED = 0x55; |
Anaesthetix | 0:0929d3d566cf | 15 | } |
Anaesthetix | 0:0929d3d566cf | 16 | |
Anaesthetix | 0:0929d3d566cf | 17 | void setPLL1Frequency(unsigned char clkSrc, unsigned short M, unsigned char N) |
Anaesthetix | 0:0929d3d566cf | 18 | { |
Anaesthetix | 0:0929d3d566cf | 19 | LPC_SC->CLKSRCSEL = clkSrc; |
Anaesthetix | 0:0929d3d566cf | 20 | LPC_SC->PLL1CFG = (((unsigned int)N-1) << 16) | M-1; |
Anaesthetix | 0:0929d3d566cf | 21 | LPC_SC->PLL1CON = 0x01; |
Anaesthetix | 0:0929d3d566cf | 22 | LPC_SC->PLL1FEED = 0xAA; |
Anaesthetix | 0:0929d3d566cf | 23 | LPC_SC->PLL1FEED = 0x55; |
Anaesthetix | 0:0929d3d566cf | 24 | while (!(LPC_SC->PLL1STAT & (1<<26))); |
Anaesthetix | 0:0929d3d566cf | 25 | |
Anaesthetix | 0:0929d3d566cf | 26 | LPC_SC->PLL1CON = 0x03; |
Anaesthetix | 0:0929d3d566cf | 27 | LPC_SC->PLL1FEED = 0xAA; |
Anaesthetix | 0:0929d3d566cf | 28 | LPC_SC->PLL1FEED = 0x55; |
Anaesthetix | 0:0929d3d566cf | 29 | } |
Anaesthetix | 0:0929d3d566cf | 30 | |
Anaesthetix | 0:0929d3d566cf | 31 | unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N) |
Anaesthetix | 0:0929d3d566cf | 32 | { |
Anaesthetix | 0:0929d3d566cf | 33 | setPLL0Frequency(clkSrc, M, N); |
Anaesthetix | 0:0929d3d566cf | 34 | LPC_SC->CCLKCFG = clkDivider - 1; |
Anaesthetix | 0:0929d3d566cf | 35 | SystemCoreClockUpdate(); |
Anaesthetix | 0:0929d3d566cf | 36 | return SystemCoreClock; |
Anaesthetix | 0:0929d3d566cf | 37 | } |
Anaesthetix | 0:0929d3d566cf | 38 |