Created
January 19, 2013 10:24
-
-
Save ossicode/4571821 to your computer and use it in GitHub Desktop.
system timer using timer B / timer B using CCR0 for 1 sec / CCR1 for 1ms / ms is compensated every 1 sec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ossiobc.h" | |
#include "wdt.h" | |
#include "timerB.h" | |
/* | |
* main.c | |
*/ | |
int main(void) { | |
wdt_hold(); | |
clock_setup(); | |
// XT2CLK = 7.3728MHz, LFXT1CLK = 32.768kHz | |
// XT2CLK = MCLK = SMCLK = 7.3728 MHz | |
// LFXT1CLK = ACLK = 32.768 kHz | |
clock_dividerSetup(MCLK_DIVIDED_BY_1, SMCLK_DIVIDED_BY_1, ACLK_DIVIDED_BY_1); | |
P6DIR |= BIT0 +BIT1; | |
P6OUT |= BIT0 + BIT1; | |
_EINT(); | |
volatile uint16_t i; | |
volatile uint32_t timeMs1, timeMs2; | |
volatile uint32_t timeSec1, timeSec2; | |
// set for 1ms tick / 1 sec tick / compensate msTick every second | |
systimer_init(TIMER_B_ACLK, TIMER_B_DIVIDED_BY_1, TIMER_B_UP_MODE, 33, 32763); | |
systimer_start(); | |
while(1) | |
{ | |
timeSec1 = systimer_getSecTick(); | |
timeMs1 = systimer_getMsTick(); | |
// 2 sec | |
for(i = 0 ; i < 2000; i++) | |
{ | |
// 1 ms | |
__delay_cycles(7372); | |
} | |
timeMs2 = systimer_getMsTick(); | |
timeSec2 = systimer_getSecTick(); | |
_NOP(); | |
// __bis_SR_register(LPM3_bits + GIE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment