Hello,
I hope you are doing well. I have currently having problems with regards to setting my timer on capture mode on my MSP430 to interface with the TCS3200 colour sensor. The colour sensor outputs a square wave of a frequency depending on the colour it is capturing and I am trying to count this for a certain amount of time. To do this I am using a timer on pin 8.3 as an input, but I cannot get my count variable to increment and I am unsure why. I don't know if I am missing something when configuring the timer or if my interrupt vector is incorrect. Here is the code provided below:
#include <msp430.h>
#include <driverlib.h>
#include <stdio.h>
#include "hal_LCD.h"
unsigned int red=0,green=0,blue=0;
unsigned int count = 0;
unsigned int which_filter = 0;
// interrupts
#pragma vector = TIMER0_A0_VECTOR
__interrupt void delay1 ()
{
P1OUT ^= BIT0; // blinking LED to confirm functioning
}
//Timer general interrupt
#pragma vector = TIMER1_A1_VECTOR
__interrupt void increment(void)
{
switch (TA1IV) {
case 0x08: //Capture/compare interrupt 2
count++;
break;
default:
break;
}
}
void displayIntegerOnLCD(int value) {
char str[20]; // Assuming a maximum of 5 digits for the integer
sprintf(str, "%d", value); // Convert integer to string
displayScrollText(str); // Display the string on LCD using displayScrollText function
}
void init_timers()
{
// Timer A1 assigned to pin 8.3 as a counter
TA1CCTL2 |= CM_1; // capture on rising edge of clock
TA1CCTL2 |= CCIS_0; // select pin 8.3
TA1CCTL2 |= SCS; // synchronous capture
TA1CCTL2 |= CAP; // Capture mode
TA1CCTL2 |= CCIE; // enable interupts
TA1CTL |= TASSEL_2 | MC_2 | TACLR; // SMCLK, continuous mode, clear timer
// Timer A0 - confirmed working
TA0CTL |= TACLR; // reset timer
TA0CTL |= TASSEL_1; // SMCLK
TA0CTL |= MC_1; // timer starts counts to TA0CCR0
TA0CCTL0 = CCIE; // interupts enabled
TA0CCR0 |= 50000 - 1 ;
}
void init_ColourSensor(){
P1DIR = 0x31; // ports 1.4 and 1.5 as outputs for S0 and S1
P2DIR = 0xA0; // port 2.5 and 2.7 as outputs for S2 and S3 respectivly
P8DIR = ~0x08; // port 8.3 set as input for OUT to connect to timer TA0.1
P8SEL0 = 0x08; // port 8.3 selected as primary function (timer A0)
P1OUT = 0x30; // 1.4 high and 1.5 low: output frequency scaling = 100%
P2OUT = 0x00; // red colour filter initially
}
int main(void){
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1OUT |= 0x00;
PMM_unlockLPM5();
init_timers();
init_ColourSensor();
__enable_interrupt();
__bis_SR_register(GIE); // makes timer interrupts work
Init_LCD(); // initialise LCD
clearLCD();
while(1){
displayIntegerOnLCD(count);
}
}