Jump to content
43oh

Sean

Members
  • Content Count

    14
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Sean got a reaction from bluehash in basic demo: clocks,timers,interrupts   
    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; };
×
×
  • Create New...