forked from igkov/bcomp11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.c
42 lines (35 loc) · 936 Bytes
/
timer.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <LPC11xx.h>
#include "timer.h"
void timer1_init(void) {
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL<<6)|(1UL<<10)|(1UL<<16);
// pio init:
LPC_IOCON->R_PIO1_1 &= ~0x07; /* As */
LPC_IOCON->R_PIO1_1 |= 0x01; /* GPIO */
// set 0:
LPC_GPIO1->DIR |= (1UL<<1);
LPC_GPIO1->DATA &= ~(1UL<<1);
// timer init:
LPC_TMR32B1->TC = 0;
LPC_TMR32B1->PR = 0;
LPC_TMR32B1->TCR = 0x01; // start
}
void timer1_pwm_on(void) {
LPC_IOCON->R_PIO1_1 &= ~0x07;
LPC_IOCON->R_PIO1_1 |= 0x03;
// start clk:
LPC_TMR32B1->MCR = 0x02<<0; // Reset on MR0
LPC_TMR32B1->EMR = (1<<0)|(3<<4);
}
void timer1_pwm_off(void) {
LPC_IOCON->R_PIO1_1 &= ~0x07;
LPC_IOCON->R_PIO1_1 |= 0x01;
}
void timer1_pwm_freq(int freq) {
LPC_IOCON->R_PIO1_1 &= ~0x07;
LPC_IOCON->R_PIO1_1 |= 0x03;
LPC_TMR32B1->MR0 = 48000000/2/freq;
LPC_TMR32B1->TC = 0;
}
uint32_t timer1_get(void) {
return LPC_TMR32B1->TC;
}