![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LPC800-MAX RGB demo using SCT and MRT
LPC800-MAX RGB demo using State-Configurable Timer(SCT) and Multi-Rate Timer(MRT).
http://www.youtube.com/watch?v=PABxoWZB0YM
MRT.cpp@1:4e19f154ec21, 2013-10-14 (annotated)
- Committer:
- va009039
- Date:
- Mon Oct 14 03:59:30 2013 +0000
- Revision:
- 1:4e19f154ec21
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:4e19f154ec21 | 1 | #include "MRT.h" |
va009039 | 1:4e19f154ec21 | 2 | |
va009039 | 1:4e19f154ec21 | 3 | MRT::MRT(int channel) |
va009039 | 1:4e19f154ec21 | 4 | { |
va009039 | 1:4e19f154ec21 | 5 | static bool insted = false; |
va009039 | 1:4e19f154ec21 | 6 | |
va009039 | 1:4e19f154ec21 | 7 | if (!insted) { |
va009039 | 1:4e19f154ec21 | 8 | inst(); |
va009039 | 1:4e19f154ec21 | 9 | insted = true; |
va009039 | 1:4e19f154ec21 | 10 | } |
va009039 | 1:4e19f154ec21 | 11 | |
va009039 | 1:4e19f154ec21 | 12 | _ch = &LPC_MRT->Channel[channel]; |
va009039 | 1:4e19f154ec21 | 13 | _ch->CTRL |= (1<<1); // one-shot |
va009039 | 1:4e19f154ec21 | 14 | } |
va009039 | 1:4e19f154ec21 | 15 | |
va009039 | 1:4e19f154ec21 | 16 | void MRT::inst() |
va009039 | 1:4e19f154ec21 | 17 | { |
va009039 | 1:4e19f154ec21 | 18 | LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10); // enable MRT |
va009039 | 1:4e19f154ec21 | 19 | LPC_SYSCON->PRESETCTRL |= (1<<7); // reset MRT |
va009039 | 1:4e19f154ec21 | 20 | us_clk = SystemCoreClock / 1000000; |
va009039 | 1:4e19f154ec21 | 21 | } |
va009039 | 1:4e19f154ec21 | 22 | |
va009039 | 1:4e19f154ec21 | 23 | void MRT::write(uint32_t interval) |
va009039 | 1:4e19f154ec21 | 24 | { |
va009039 | 1:4e19f154ec21 | 25 | _ch->INTVAL = interval | (1<<31); // and LOAD |
va009039 | 1:4e19f154ec21 | 26 | _ch->STAT |= 0x01; |
va009039 | 1:4e19f154ec21 | 27 | } |
va009039 | 1:4e19f154ec21 | 28 | |
va009039 | 1:4e19f154ec21 | 29 | int MRT::status() |
va009039 | 1:4e19f154ec21 | 30 | { |
va009039 | 1:4e19f154ec21 | 31 | return (_ch->STAT & 1) ? IDLE : RUNNING; |
va009039 | 1:4e19f154ec21 | 32 | } |
va009039 | 1:4e19f154ec21 | 33 | |
va009039 | 1:4e19f154ec21 | 34 | void MRT::wait_ms(uint32_t timeout_ms) |
va009039 | 1:4e19f154ec21 | 35 | { |
va009039 | 1:4e19f154ec21 | 36 | wait_raw(us_clk * 1000 * timeout_ms); |
va009039 | 1:4e19f154ec21 | 37 | } |
va009039 | 1:4e19f154ec21 | 38 | |
va009039 | 1:4e19f154ec21 | 39 | void MRT::wait_us(uint32_t timeout_us) |
va009039 | 1:4e19f154ec21 | 40 | { |
va009039 | 1:4e19f154ec21 | 41 | wait_raw(us_clk * timeout_us); |
va009039 | 1:4e19f154ec21 | 42 | } |
va009039 | 1:4e19f154ec21 | 43 | |
va009039 | 1:4e19f154ec21 | 44 | void MRT::wait_raw(uint32_t timeout) |
va009039 | 1:4e19f154ec21 | 45 | { |
va009039 | 1:4e19f154ec21 | 46 | write(timeout); |
va009039 | 1:4e19f154ec21 | 47 | while(status() == RUNNING); |
va009039 | 1:4e19f154ec21 | 48 | } |
va009039 | 1:4e19f154ec21 | 49 | |
va009039 | 1:4e19f154ec21 | 50 | uint32_t MRT::read() |
va009039 | 1:4e19f154ec21 | 51 | { |
va009039 | 1:4e19f154ec21 | 52 | return _ch->TIMER; |
va009039 | 1:4e19f154ec21 | 53 | } |