1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

msp430x20xx dco flashcal

3 107 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 29,5 KB

Nội dung

//*********************************************************************** ******* // MSP430F20xx Demo - DCO Calibration Constants Programmer // // NOTE: THIS CODE REPLACES THE TI FACTORY-PROGRAMMED DCO CALIBRATION // CONSTANTS LOCATED IN INFOA WITH NEW VALUES USE ONLY IF THE ORIGINAL // CONSTANTS ACCIDENTALLY GOT CORRUPTED OR ERASED // // Description: This code re-programs the F2xx DCO calibration constants // A software FLL mechanism is used to set the DCO based on an external // 32kHz reference clock After each calibration, the values from the // clock system are read out and stored in a temporary variable The final // frequency the DCO is set to is 1MHz, and this frequency is also used // during Flash programming of the constants The program end is indicated // by the blinking LED // ACLK = LFXT1/8 = 32768/8, MCLK = SMCLK = target DCO // //* External watch crystal installed on XIN XOUT is required for ACLK *// // // MSP430F20xx // // /|\| XIN|// | | | 32kHz // |RST XOUT|// | | // | P1.0| > LED // | P1.4| > SMLCK = target DCO // // A Dannenberg // Texas Instruments Inc // May 2007 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A //*********************************************************************** ******* #include "msp430x20x1.h" #define #define #define #define DELTA_1MHZ DELTA_8MHZ DELTA_12MHZ DELTA_16MHZ 244 1953 2930 3906 unsigned char CAL_DATA[8]; constants volatile unsigned int i; int j; char *Flash_ptrA; void Set_DCO(unsigned int Delta); void main(void) { // // // // 244 x 4096Hz = 999.4Hz 1953 x 4096Hz = 7.99MHz 2930 x 4096Hz = 12.00MHz 3906 x 4096Hz = 15.99MHz // Temp storage for // Segment A pointer WDTCTL = WDTPW + WDTHOLD; for (i = 0; i < 0xfffe; i++); stabilization P1OUT = 0x00; P1SEL = 0x10; P1DIR = 0x11; j = 0; // Stop WDT // Delay for XTAL // Clear P1 output latches // P1.4 SMCLK output // P1.0,4 output // Reset pointer Set_DCO(DELTA_16MHZ); constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; // Set DCO and obtain Set_DCO(DELTA_12MHZ); constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; // Set DCO and obtain Set_DCO(DELTA_8MHZ); constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; // Set DCO and obtain Set_DCO(DELTA_1MHZ); constants CAL_DATA[j++] = DCOCTL; CAL_DATA[j++] = BCSCTL1; // Set DCO and obtain Flash_ptrA = (char *)0x10C0; // Point to beginning of seg A FCTL2 = FWKEY + FSSEL0 + FN1; Generator FCTL1 = FWKEY + ERASE; FCTL3 = FWKEY + LOCKA; *Flash_ptrA = 0x00; seg A FCTL1 = FWKEY + WRT; operation Flash_ptrA = (char *)0x10F8; consts for (j = 0; j < 8; j++) *Flash_ptrA++ = CAL_DATA[j]; data FCTL1 = FWKEY; FCTL3 = FWKEY + LOCKA + LOCK; while (1) { P1OUT ^= 0x01; for (i = 0; i < 0x4000; i++); } } // MCLK/3 for Flash Timing // Set Erase bit // Clear LOCK & LOCKA bits // Dummy write to erase Flash // Set WRT bit for write // Point to beginning of cal // re-flash DCO calibration // Clear WRT bit // Set LOCK & LOCKA bit // Toggle LED // SW Delay void Set_DCO(unsigned int Delta) frequency { unsigned int Compare, Oldcapture = 0; BCSCTL1 |= DIVA_3; TACCTL0 = CM_1 + CCIS_1 + CAP; TACTL = TASSEL_2 + MC_2 + TACLR; while (1) { while (!(CCIFG & TACCTL0)); TACCTL0 &= ~CCIFG; flag Compare = TACCR0; Compare = Compare - Oldcapture; Oldcapture = TACCR0; SMCLK if (Delta == Compare) break; else if (Delta < Compare) { DCOCTL ; // Set DCO to selected // ACLK = LFXT1CLK/8 // CAP, ACLK // SMCLK, cont-mode, clear // Wait until capture occured // Capture occured, clear // Get current captured SMCLK // SMCLK difference // Save current captured // If equal, leave "while(1)" // DCO is too fast, slow it down if (DCOCTL == 0xFF) if (BCSCTL1 & 0x0f) BCSCTL1 ; } else { DCOCTL++; // Did DCO roll under? // Select lower RSEL // DCO is too slow, speed it up if (DCOCTL == 0x00) if ((BCSCTL1 & 0x0f) != 0x0f) BCSCTL1++; // Did DCO roll over? // Sel higher RSEL } } TACCTL0 = 0; TACTL = 0; BCSCTL1 &= ~DIVA_3; } // Stop TACCR0 // Stop Timer_A // ACLK = LFXT1CLK

Ngày đăng: 25/12/2017, 11:46

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w