forked from cinderblock/3-Phase-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVRClock.h
More file actions
30 lines (23 loc) · 632 Bytes
/
AVRClock.h
File metadata and controls
30 lines (23 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* File: AVRClock.h
* Author: Cameron
*
* Created on October 16, 2015, 11:41 PM
*/
#ifndef AVRCLOCK_H
#define AVRCLOCK_H
#include <avr/io.h>
#include "Board.h"
namespace AVR {
namespace Clock {
inline void enablePLL(u1 const PLL = 10, u1 const timerDiv = 2, bool const useEXT = true) {
PLLFRQ = ((useEXT ? 0 : 1) << PINMUX) | (timerDiv << PLLTM0) | (1 << PLLUSB) | PLL;
bool const divideClock = useEXT && (Board::ClockSpeed == 16000000UL);
PLLCSR = ((divideClock ? 1 : 0) << PINDIV) | (1 << PLLE);
}
inline void waitForPLL() {
while (!(PLLCSR & (1 << PLOCK)));
}
};
};
#endif /* AVRCLOCK_H */