Hi All,
I am using the MSP430F2618 64 pin chip and the appropriate experimenters board.
In a nutshell I am developing a metering application that when a user leaves the threshold (or minimum value) it starts graphing but once they go below the threshold again the program gets stuck in a while loop until the users leaves threshold again. The problem I am currently working on is using Timer_A to find the exact time it takes for one cycle (which we estimate anywhere from 1 second to 6 seconds). From my understanding we have to use a capture register to capture the clock at the exact moment we need it and than use that register make any calculations we need (e.g. Change the clock cycles into seconds based on HZ of the clock we set it too). We would also like to at the point after we capture it to reset timer_A back to 0 and continue the counting. I will put the sections of the code that have this implemented and I hope this community can nudge me in the right directions!
I am also setting ACLK (my source for Timer_A) to VLO and trying to get the lowest HZ I can since we need at most 1/100th of a second even that is a bit more precision than we need.
Thanks,
Jake G.
void InitFreq(void)
{
// External oscilator 32kHz
// Watchdog
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = CALDCO_8MHZ;
BCSCTL1 = CALBC1_8MHZ;
BCSCTL1|=DIVA_3; // divide ACLK by 8
BCSCTL3= LFXT1S_2; // Set the source of ACLK to VLO to be used by Timer A
TACCTL1 =CAP|CM_3|SCS|CCIS_1; //Initialize channel 1 to capture and syncronize to timer_A
TACTL = TASSEL_1|ID_3|MC_2|TACLR; // Initializes Timer A: ACLK, /8, continuous mode, and clearing timer
}
.
.
if (y_data[0]<THRESHOLD && time_cnt>15) // Setting a minimum threshold
{
TACCTL1^=CCIS0;//toggle the capture bit
//TACTL &= ~MC_2; // Stop Timer A
rate = (int)(3.125/TACCR1+.5); // Store Timer's cycles, get rate by dividing by Hz.
TACTL |= TACLR; // Clear Timer A
TACTL = TASSEL_1|ID_3|MC_2; // Reconfigure Timer A, start it