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);
}
}
}
