diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-07-09 18:52:42 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-07-09 18:52:42 +0200 |
commit | 9fcfb4a01ba104ff7058012f2f73b1be6a143d6c (patch) | |
tree | 238a234b03a830aaf56b1bfa7e504c711d20c8ae | |
parent | 1e38db8e6d96aeec5231d9614ac9f7605773b596 (diff) |
Enable PWM output on TIM2. Base mainloop timing on TIM2.
-rw-r--r-- | main.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -4,21 +4,18 @@ #include "ppmsum.h" #include "i2c.h" -volatile unsigned int cnt; int main() { RCC.enable(RCC.AFIO); RCC.enable(RCC.IOPA); RCC.enable(RCC.IOPB); - GPIOA.CRL = 0x44344444; + GPIOA.CRL = 0x4434bbbb; GPIOA.CRH = 0x444444b4; GPIOA.ODR = 1 << 5; GPIOB.CRH = 0x4444ff44; - cnt = 0; - I2C i2c; i2c.enable(); @@ -31,17 +28,21 @@ int main() { PPMSum ppmsum; ppmsum.enable(); + RCC.enable(RCC.TIM2); + TIM2.PSC = 72; + TIM2.ARR = 20000; + TIM2.CCER = 0x1111; + TIM2.CCMR1 = 0x6868; + TIM2.CCMR2 = 0x6868; + + TIM2.CR1 = 0x05; + while(1) { - cnt++; - if(cnt & (1 << 20)) { - //GPIOA.ODR = 1 << 5; - } else { - //GPIOA.ODR = 0; - } + // Wait for a new update. + while(!(TIM2.SR & 0x01)); + TIM2.SR = 0; - if(!(cnt & ((1 << 20) - 1))) { i2c.read_reg(0x68, 0x1d, 6, buf); //xbee_send(6, buf); - } } } |