Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 63683

Forum Post: RE: Error in Timer

$
0
0
Thanks. You were right. I made 2 programs, one with the SMCLK and another with ACLK, in which both have satisfied me for my desired output . Using SMCLK, I was able to produce alternating delay on each LED with almost 1s delay. In another program using ACLK, you were right that the crystal might be the problem so I give it a push and tried to work on my first program and made some editing. Please have a look on my programs if you still have something to add? ************************************Here is my code with the use of SMCLK: ******************************************* #include volatile int i; void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer P1DIR |= 0x41; //Setting P1.0 and P1.6 as output direction CCTL0 = CCIE; //Enable CCR0 interrupt CCR0 = 16384; TACTL = TASSEL_2 | ID_3 | MC_1; // SMCLK/8, Up mode i=0; while(1){ _BIS_SR(GIE); //enter LPM0 with interrupt if (i 7) //turn on LED2 and turn off LED1 for 1sec. {P1OUT = 0X40;} if (i==14) {i=0;} }} //timer A0 interrupt service routine #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A(void) {i++;} *************************************Here is my code using ACLK: *************************************************************** #include volatile int i; void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer P1DIR |= 0x41; //Setting P1.0 and P1.6 as output direction CCTL0 = CCIE; //Enable CCR0 interrupt CCR0 = 16384; //32768/32768=1Hz TACTL = TASSEL_1 + MC_1; //ACLK,UPMODE i=0; while(1){ _BIS_SR(GIE); //enter LPM0 with interrupt if (i==1) //turn LED1 on and turn off LED2 for 1sec. {P1OUT = 0X01;} if (i==2) //turn on LED2 and turn off LED1 for 1sec. {P1OUT = 0X40;} if (i==2) {i=0;} }} //timer A0 interrupt service routine #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A(void) {i++;}

Viewing all articles
Browse latest Browse all 63683

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>