Other Parts Discussed in Thread: MSP430F149,
Tool/software: Code Composer Studio
I have an old source code for the MSP430F149. Now I want migrate this code to the MSP430FR5994. In the old code, the DCO was readjusted regularly (each time, when a UART communication was needed, ...). This DCO correction was used to compensate the faults due to temperature changes and so on.
I couldn't find anything comparable for the MSP430FRxxxx serie. Is there an equivalent to this code for the MSP430FR5994?
//------------------------------------------------------Main - MSP430F149------------------------------------------------------//
int main(void)
{ stopWatchdog();
BCSCTL1 = 0xB7; // ACLK is devided by 8 = 4096 Hz. RSEL=6 no division for MCLK and SSMCLK. XT2 is off.
BCSCTL2 = 0x00; // Init FLL to desired frequency using the 32762Hz crystal DCO frquenzy = 4,001792 MHz
DCOCTL = 0xFF;
//Delay for XTAL to settle
volatile unsigned int i;
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
initPorts();
Set_DCO();
IE1 |= WDTIE; // Enable WDT interrupt
eint();
while(1)
{...
//Before each UART communication, Set_DCO
if (...)
{Set_DCO();}
...
}
}
//------------------------------------------------------DCO correction - MSP430F149------------------------------------------------------//
void Set_DCO (void) // Set DCO to selected frequency
{
#define DELTA 977 // target DCO = DELTA*(4096) = 4001792
unsigned int Compare, Oldcapture = 0;
BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8
CCTL2 = CM_1 + CCIS_1 + CAP; // CAP, ACLK
TACTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, cont-mode, clear
while (1)
{
while (!(CCIFG & CCTL2)); // Wait until capture occured
CCTL2 &= ~CCIFG; // Capture occured, clear flag
Compare = CCR2; // Get current captured SMCLK
Compare = Compare - Oldcapture; // SMCLK difference
Oldcapture = CCR2; // Save current captured SMCLK
if ((Compare >= DELTA-1)&&(Compare <= DELTA+1)) break;
else if (DELTA < Compare) // DCO is too fast, slow it down
{
DCOCTL--;
if (DCOCTL == 0xFF)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3)))
BCSCTL1--; // Did DCO roll under?, Sel lower RSEL
}
}
else
{
DCOCTL++;
if (DCOCTL == 0x00)
{
if (!(BCSCTL1 == (XT2OFF + DIVA_3 + 0x0F)))
BCSCTL1++; // Did DCO roll over? Sel higher RSEL
}
}
}
CCTL2 = 0; // Stop CCR2
TACTL = 0; // Stop Timer_A
}