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.

capturing the signal from another board by using Timer....

Other Parts Discussed in Thread: MSP430G2553

hi ....

I am trying to configure the MSP430G2553 Microcontroller to 250 KHz by using the following DCO configuration,

  DCOCTL = 0xC8;

  BCSCTL1 = 0x02;

  BCSCTL2 = 0;

  BCSCTL3 |= LFXT1S_2;

But the frequency generation of microcontroller ranges is around 255 KHz to 272 KHz (it will keep on  varying in each and every Microcontroller (MSP430G2553) around 5 KHz to 20kHz its not generating exact 250Khz (+1kHz/-2Khz).

My First question:

                                Is there any way to generate exact 250 KHz (with minimum tolerances) frequency?

To overcome the above issue I am trying to change the DCO setting to generate the exact 250 KHz (with minimum tolerances) frequency based on the captured 1Khz PWM signal (50% duty cycle).

How?

Assume my controller(Launch pad 1) is working at 250 KHz (with minimum tolerances) frequency, in this case if we are capture the  1Khz PWM(Launch pad 2 generating  PWM)  signal(50%  duty cycle) by using timer in capture mode the timer capture count will be,

Launch pad 1 is running 250 KHz so 1/250,000 = 4 Microsecond.

Launch pad 2 generating the 1 KHz PWM signal (50% duty cycle) ,1/1000 = 1000 Microsecond.

My captured count should be 1000/4 =250 timer counts.

Based on this calculation if  I capture the signal on every rising edge, my capture/compare register values should  be 250 than I will assume that my controller is working at 250 KHz (with minimum tolerances) frequency until I keep on  changing  my DCO settings values.

My Second question:

I cannot able to capture the signal at constant counts (250 counts(with some tolerances ) it continually varying. Can you please tell me what mistake I am doing?

We are using internal oscillator and we are not using capture/compare ISR.

Here is the my program

volatile UINT16 u16Time_Stamp = 0;

 

UINT16 u16Dc0Cotrlb = (UINT16)(DCO_CLK_SETTINGS_1);

volatile UINT32  TempCount;

 

     unsigned int Dc0Cotrlb = 0xC8;

void main()

{

      WDTCTL = WDTPW + WDTHOLD;

     

  DCOCTL = 0xC8;

  BCSCTL1 = 0x02;

  BCSCTL2 = 0;

  BCSCTL3 |= LFXT1S_2;

     

          

    //Configure Port Pins

    P1DIR &= ~BIT1;                        

    P1SEL |= BIT1;                          

    P1SEL2 &= ~BIT1;                          

 

    TA0CCTL0 = CM_1 + CCIS_0 + SCS + CAP;

    TA0CTL = TASSEL_2 + MC_2 + TACLR;

 

    COMH_vUARTInit(9600);

 

 

      while(1)

      {

           

            while(!(TA0CCTL0 & CCIFG))

            {

            u16Time_Stamp = TA0CCR0;

           

            if(TA0CCTL0 & COV)

            {

                  TA0CCTL0 &= ~COV;

            }

            else if((u16Time_Stamp > u16Exp_CountLow) && (u16Time_Stamp < u16Exp_CountHigh))

                  {

                        _nop();

                        _nop();

                        _nop();

                        _nop();

                  }

                  else if(u16Time_Stamp < u16Exp_CountLow)

                  {

                        DCOCTL  = Dc0Cotrlb++;

                  }

                  else if(u16Time_Stamp > u16Exp_CountLow)

                  {

                        DCOCTL  = Dc0Cotrlb--;

                       

                  }else if(u16Time_Stamp == 250)

                  {

                        PrintF(u16Time_Stamp);

                  } 

                  TA0CCR0 = 0;

                  TA0R = 0;

                  TA0CCTL0 &= ~(CCIFG + COV + CCI);

            }

                 

 

      }

}

  • The DCO of MSP430G2xx has a large inherent uncertainty in frequency from chip to chip. Ti has made an attempt to "calibrate" that. What they did is similar to what you attempted to do. They use a much more accurate reference (probably at 32.786kHz divide by some integer) to produce best BCSCTL1 and DCOCTL settings for 1MHz, 8MHz, 12MHz and 16MHz.

    You could use TI's BCSCTL1 and DOCCTL values for 1MHz and divide that by 4 to produce 250kHz. But even after that, the frequency still has an overall error of +-3%.

    You could also solder the 32.768kHz crystal and use LFXT1 as frequency reference. Refine your program to continuously change  BCSCTL1 and DOCCTL setting. (This is called a Frequency Lock Loop.) Doing it this way, you can further reduce the error to about +-1%.

    You are on the right track.

  • Thanks...

    But my capture is not working properly it giving some unexpected values like 50,20,-61234,6043........ So please answer my second question ...

**Attention** This is a public forum