Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <msp430FG4618.h>
  2. #include <stdio.h>
  3. volatile unsigned int count = 0;
  4. volatile unsigned int old = 0;
  5. volatile unsigned int cur = 0;
  6. volatile float velocity = 0;
  7. void main(void)
  8.  
  9. {
  10.  
  11. WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
  12. P1DIR &= ~0x05; // P1.0 - CCI0A, P1.2 - CCI1A
  13. P1SEL |= 0x05;
  14. //TACCR0 = 8000-1;
  15. //TACCTL1 |= CCIE;
  16. TACCTL0 |= CM_1 + CCIS_0 + CAP + CCIE; // capture front rising + CCI0A + capture mode + CCR0 interrupt enabled
  17. TACTL = TASSEL_1 + MC_2; // ACLK + divider /8 + contin mode
  18. TBCCR0 = 4000 - 1;
  19. TBCTL = TASSEL_1 + ID_3 + MC_1 + TBIE; //
  20. //printf("MC_count: %d \n", TACTL & 48);
  21. __enable_interrupt();
  22. // LPM0 + Enable global ints
  23. }
  24.  
  25. #pragma vector=TIMERA0_VECTOR
  26. __interrupt void TimerA0(void) {
  27. count++;
  28. /*if (TACCTL0 & 2) {
  29. count++;
  30. TA0CCTL0 &= ~COV;
  31. printf("COV HAPPENED \n");
  32. }*/
  33. /*if (count == 16) {
  34. printf("full rotation cycle \n");
  35. count = 0;
  36. }*/
  37. //printf("timer: %d \n", TAR);
  38. //printf("MC_count: %d \n", TACTL & 48);
  39. //printf("count: %d \n", count);
  40. //printf("COV: %d \n", TACCTL0 & 2);
  41. // printf("TAIFG FLAG_count: %d \n", TAIFG);
  42. }
  43.  
  44. #pragma vector=TIMERB1_VECTOR
  45. __interrupt void TimerB1(void) {
  46. switch(__even_in_range(TBIV,14))
  47. {
  48. case 14 : // TAIE CCIFG
  49. cur = count;
  50. velocity = (float)(cur - old) / 16 * 60;
  51. printf("%.4f - %d - %d\n", velocity, cur - old, count);
  52. //printf("cur: %d old: %d\n", cur,old);
  53. old = cur;
  54. //printf("TBIE \n");
  55.  
  56. }
  57.  
  58. }
  59. /*
  60. #pragma vector=TIMERA1_VECTOR
  61. __interrupt void TimerA1(void) {
  62. switch(__even_in_range(TAIV,10))
  63. {
  64. case 10 : // TAIE CCIFG
  65. //printf("timer_taie: %d \n", TAR);
  66. //printf("TAIE \n");
  67. //printf("MC_TAIE: %d \n", TACTL & 48);
  68. printf("COV_TAIE: %d \n", TACCTL0 & 2);
  69. break;
  70. case 2 : // TACCR1 CCIFG
  71. printf("timestamp cycle \n");
  72. break;
  73. }
  74.  
  75. }
  76. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement