Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430FG4618.h>
- #include <stdio.h>
- volatile unsigned int count = 0;
- volatile unsigned int old = 0;
- volatile unsigned int cur = 0;
- volatile float velocity = 0;
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
- P1DIR &= ~0x05; // P1.0 - CCI0A, P1.2 - CCI1A
- P1SEL |= 0x05;
- //TACCR0 = 8000-1;
- //TACCTL1 |= CCIE;
- TACCTL0 |= CM_1 + CCIS_0 + CAP + CCIE; // capture front rising + CCI0A + capture mode + CCR0 interrupt enabled
- TACTL = TASSEL_1 + MC_2; // ACLK + divider /8 + contin mode
- TBCCR0 = 4000 - 1;
- TBCTL = TASSEL_1 + ID_3 + MC_1 + TBIE; //
- //printf("MC_count: %d \n", TACTL & 48);
- __enable_interrupt();
- // LPM0 + Enable global ints
- }
- #pragma vector=TIMERA0_VECTOR
- __interrupt void TimerA0(void) {
- count++;
- /*if (TACCTL0 & 2) {
- count++;
- TA0CCTL0 &= ~COV;
- printf("COV HAPPENED \n");
- }*/
- /*if (count == 16) {
- printf("full rotation cycle \n");
- count = 0;
- }*/
- //printf("timer: %d \n", TAR);
- //printf("MC_count: %d \n", TACTL & 48);
- //printf("count: %d \n", count);
- //printf("COV: %d \n", TACCTL0 & 2);
- // printf("TAIFG FLAG_count: %d \n", TAIFG);
- }
- #pragma vector=TIMERB1_VECTOR
- __interrupt void TimerB1(void) {
- switch(__even_in_range(TBIV,14))
- {
- case 14 : // TAIE CCIFG
- cur = count;
- velocity = (float)(cur - old) / 16 * 60;
- printf("%.4f - %d - %d\n", velocity, cur - old, count);
- //printf("cur: %d old: %d\n", cur,old);
- old = cur;
- //printf("TBIE \n");
- }
- }
- /*
- #pragma vector=TIMERA1_VECTOR
- __interrupt void TimerA1(void) {
- switch(__even_in_range(TAIV,10))
- {
- case 10 : // TAIE CCIFG
- //printf("timer_taie: %d \n", TAR);
- //printf("TAIE \n");
- //printf("MC_TAIE: %d \n", TACTL & 48);
- printf("COV_TAIE: %d \n", TACCTL0 & 2);
- break;
- case 2 : // TACCR1 CCIFG
- printf("timestamp cycle \n");
- break;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement