Tool/software: Code Composer Studio
Hello everyone,i have a question for my project im using the msp430g2231 microcontroller and i want to measure frequencies up to 10Mhz.Im new to microcontrollers(not programming),and im not sure how to do it properly.Im using custom itoa function to convert the long int into a string and i send the string to a LCD after storing the calculation into a long.Then i send it to the LCD like this:
void send_string(char *s)
{
while(*s)
{
send_data(*s);
s++;
}
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
delay(100); // delay 100mS until next screen refresh
/*** Timer_A Set-Up ***/
TA0CCR0 = SampleTuneTime;
TA0CCTL0 |= CCIE; // Interrupt enable
TA0CTL |= TASSEL_2 + ID_3; // SMCLK
TA0CCTL1 |= CCIE + CCIS_0 + CM_1 + CAP; // Interrupt enable, capture select CCIxA, Positive edge, capture mode
TA0CTL |= TASSEL_2; //SMCLK
_BIS_SR(GIE); // Enter LPM0 with interrupts enabled
while(1)
{
TA0CTL |= MC0; // Start timer up mode.Timer counts up to TACCR0
TA0CTL |= MC1; // Start timer
//while(CounterValue != 400); // Wait while CounterValue is not equal to 400
TA0CTL &= ~MC0; // Stop timer mode
TA0CTL &= ~MC1; // Stop timer
Result >>= 2; // Divide Result by 4
calc_freq();
//convert long into frequency
char buffer[8]= { 0, };
unsigned long toLCD = Frequency;
// int Base = 10;
itoa(toLCD,buffer); //convert decimal
lcd_init();
send_string("FREQUENCY IS");
send_command(0xC0);
send_string(buffer);
send_command(0xC8);
send_string("HZ");
Result = 0; // Zero Result
CounterValue = 0; // Zero CounterValue
StoredCount = 0; // Zero StoredCount
TA0R = 0; // Zero Timer_A0 register
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void)
{
TA0CTL &= ~MC0; // Stop timer
TA0CTL &= ~MC1; // Stop timer
CounterValue++; // Increment CounterValue
if (CounterValue >= (NumberSamples +1)) // Reset values if NumberSamples +1 is reached
{
CounterValue = 0; // Zero CountValue
StoredCount = 0; // Zero StoredCount
}
Result += StoredCount; // Store accumulated count in Result ( i calculate the frequency with result/Sample time
StoredCount = 0; // Zero StoredCount
TA0CTL |= MC1; // Start timer
TA0CTL |= MC0; // Start timer
StoredCount++; // Increment StoredCount
}
this is the main code of the program im using custom made function for the itoa and the communication with the LCD.I have two questions
1.) Can i make the frequency meter up to 10Mhz because the g2231 has one timer and 1Mhz calibration available.
2.)Can i use only one timer TA0CTL for both MC0 and MC1
Thank you for your time.