Tool/software: Code Composer Studio
I have this code that reads form a water flow sensor. It works perfectly when I use TB1.2 on pin 2.1, but if I try to use TB0.1 on pin 1.6, it won't go into the interrupt. Here is my code:
#include <msp430.h>
#include <math.h>
#include <stdio.h>
//initialize variables
volatile unsigned int counter=0;
volatile unsigned int prev_counter=0;
unsigned int difference=0;
int flow_rate=0;
__attribute__((ramfunc))
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; //Stop watchdog timer
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
//P1.6/TB0.1
P1DIR &= ~BIT6;
P1SEL1 &= ~BIT1; //0
P1SEL0 |= BIT1; //1
// TB0CCR1: capture mode + on rising edge + enable interrupt request of corresponding CCIFG flag + synchronize capture source + Capture input select CCI1A
TB0CCTL1 = CAP + CM_1 + CCIE + SCS + CCIS_0;
//Use the SMCLK + Divide clk by 8 (125kHz)+Continuous mode: Timer counts up to the value set by CNTL + TimerB clear + Interrupt enable
TB0CTL |= TBSSEL_2 + ID_3 + MC_2 + TBCLR + TBIE;
while(1) {
//enter low power mode0 with interrupt enable
__bis_SR_register(LPM0_bits + GIE);
__no_operation();
difference = counter - prev_counter; //amount of rising pulse edges
//flow rate in L/min. 125000 SMCLKs divided by rising pulse edges detected gives frequency.
//The conversion constant for frequency to L/min is 4.8 or 19/4 so instead of dividing by 4.8, mult by reciprocal of 19/4.
//Whatever the integer result, move decimal one place to the left for true reading.
flow_rate = (40*(125000UL/difference))/19;
}
}
//Timer_B0 TBCCR1 Interrupt Vector Handler Routine
__attribute__((ramfunc));
#pragma vector = TIMER0_B1_VECTOR
__interrupt void TIMER0_B1_ISR (void)
{
switch(__even_in_range(TB0IV,TB0IV_TBIFG))
{
case TBIV__NONE: break; //Vector 0: No interrupt
case TBIV__TBCCR1: //Vector 2: TBCCR1 CCIFG. Interrupt source:capture/compare R1. Interrupt Flag: TBxCCR1 CCIFG.
prev_counter = counter;
counter = TB0CCR1; // 'Counter' value is copied to TB0CCR1 register
__bic_SR_register_on_exit(LPM0_bits + GIE); //exit LPM0
break;
case TBIV__TBCCR2: break; //Vector 4: TBCCR2 CCIFG
case TBIV__TBCCR3: break;
case TBIV__TBCCR4: break;
case TBIV__TBCCR5: break;
case TBIV__TBCCR6: break;
case TBIV__TBIFG: break; //Vector 6: TBIFG
default: break;
}
}
When I run the program and make water flow through the sensor, it does not give any values for 'counter' or 'prev_counter'. I've been debugging for a while and I'm not sure what the problem is. Any suggestions or help would be greatly appreciated.
Thank you!