Sean 1 Posted August 30, 2010 Share Posted August 30, 2010 This is probably redundant to some/most, this is just some of my test code on interpreting ti's docs on clocks, timers & interrupts into c, all their example code was in asm which wasn't too helpful for me as I'm pretty much starting from scratch, its been a long time since I've done any programming. Its mostly just setting up the clocks,timers, interrupts, and not much of a demo: it uses 3 clocks and blinks. Cpu/software@15.25mhz, wdt, & timer_a1. Wdt & timer_a1 are sourced from aclk/vlo@12khz. software clock runs somewhere from 600ms-700ms, wdt@ ~667ms , timer_a1 @ ~5.46seconds(65545@12khz). The software clock goes in/out of sync with the wdt clock. I didn't put a stop watch to the wdt, or timera1 to check for accuracy, if ti's docs &my math are correct wdt/timera1 should be good enough for my purposes Anyways here's my code I hope it helps someone: #include "msp430.h" int main(void) { /*PIN SETTINGS*/ P1DIR = 1|2|4|8|16|32|64|128; P1OUT=32|64; // p1.x dir=output /*CPU, CLOCK SETTINGS*/ //SET CPU @ ~15.25MHZ refer to chip datasheet for speed settings DCOCTL = DCO1|DCO0 ; //DCOx = 3, MODx=0 BCSCTL1 = RSEL3|RSEL2|RSEL1|RSEL0; //RSELx =15 /*CLK Dividers, _3:/8 _2:/4 _1:/2 _0:/1 */ BCSCTL2 = DIVM_0|DIVS_0|DIVA_0; //MCLK|SMCLK|ACLK BCSCTL3 = LFXT1S_2; //ACLK=VLO:12kHz /* WATCHDOG, TIMER , INTERRUPT SETTINGS*/ _BIS_SR(GIE); // enable interrupts WDTCTL = WDT_ADLY_250; // ~667ms@12khz using aclock:vlo IE1 |= WDTIE; //enable wdt interrupt TACTL = TASSEL_1|ID_0|MC_2|TAIE; //aclk:vlo|/0| mode:cont.| TimerA int for(;{ //infinite loop int ms, us; //time scale for (ms=0;ms<34;ms++) //software delay for (us=0;us<0xffff;us++); P1OUT ^= 1|2; //flashes p1.0,p1.1 }; } #pragma vector = WDT_VECTOR,TIMERA1_VECTOR __interrupt void interrupts (void) { switch(TAIV){ //check timer_a1 interrupt cause case TAIV_NONE: //check other interrupts? break; case TAIV_TAIFG: P1OUT ^=64|128; // flashes p1.6,1.7 @ 65545/12khz =~5.46seconds break; }; if (IFG1|=WDTIFG){ //check wdt interrupt flag P1OUT ^=4|8|16|32; //flashes p1.3-1.5 @ 250ms*32khz/12khz=~667ms }; /*clear interrupts*/ TACTL &= ~TAIFG; IFG1 &= ~WDTIFG; }; bluehash 1 Quote Link to post Share on other sites
bluehash 1,581 Posted August 30, 2010 Share Posted August 30, 2010 Thanks for your code Sean. I'll be loading it on mine today. Quote Link to post Share on other sites
kenemon 29 Posted February 28, 2011 Share Posted February 28, 2011 Hi Sean, looks good. What docs did you utilize to get this working? Quote Link to post Share on other sites
RobG 1,892 Posted February 28, 2011 Share Posted February 28, 2011 Sean, I would clear interrupt flags for the given interrupt inside conditionals. For example timer's IF could be set while servicing WDT interrupt, then it would be cleared, and in turn that interrupt would not be handled. Alternatively, you could use 2 separate ISRs. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.