This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2231: MSP430G2231

Part Number: MSP430G2231


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.

  • 2) MC0/1 are bits in a two-bit field. I suggest you use MC_2 (Continuous) to set the field and (~MC) to clear it.

    1) You won't succeed in measuring 10MHz using capture, since even at top CPU speed (16MHz) that gives you only 1.6 CPU clocks to process each capture.

    Capture is useful (preferred) for low-frequency signals, but for high-frequency signals you need frequency-counting. For that, you use your signal as the clock for the timer (TACLK=P1.0), then periodically sample the running count in TA0R. For the G2231 in particular, this presents some headaches:

    A) TACLK can't run faster than Fsystem [Ref data sheet (SLAS694J) p. 25 ("Timer_A")] As you mentioned, the G2231 only has one CALDCO, at 1MHz, and you need at least 10MHz. It is possible to generate a diffferent CALDCO, but for that you need a reference clock (typically a 32kHz crystal).

    B) The G2231 has only one timer, which you're using for your signal, so it may be tricky to do the "periodically sample" part. One possibility is __delay_cycles, which is pretty accurate but your program won't be able to do anything else. Another is to use capture, but differently: TA0.CCI0B triggers captures using ACLK, which gives you a reliably periodic (every 31+ microseconds) snapshot of TA0R [Ref data sheet Table 10]. To run ACLK (with any sort of accuracy) really requires a 32kHz crystal.

    Considering both (A) and (B), you probably want a 32kHz crystal. If you're using a G2 Launchpad, and can do a bit of soldering, you can install/enable a crystal on-board.

**Attention** This is a public forum