oPossum 1,083 Posted November 6, 2011 Share Posted November 6, 2011 This is a method to measure the DCO frequency by timing serial data. The ASCII character 'x' has two falling edges that are 8 bit times apart. There are also two 4 bit times from falling to rising and rising to falling. At 9600 bps the time between edges will be 833.33 us. Counting the number of DCO clock ticks that occur between the falling clock edges will allow the DCO frequency to be calculated. The stored DCO calibrations are shown and then frequency measurement begins. Each time the 'x' character is sent a line of info will be displayed. RSEL - Range SELect - the lower four bits of BCSCTL1 DCO - All eight bits of DCOCTL T - The count of DCO clock pulses F - Calculated DCO frequency in kHz The accuracy of the measurement is dependent on the accuracy of the serial data. Using the serial port of the Launchpad gave readings about 0.2% low. The SMCLK is output on P1.4 so a frequency counter can be used to determine how well this works. Timer A capture is used to accurately count the DCO clock ticks between falling edges. Code excerpt for(; { // --- Measure duration of 8 bits TACCTL1 &= ~CCIFG; // Clear capture flag // Wait for falling edge, check for S2 press while(!(TACCTL1 & CCIFG)) if(!(P1IN & BIT3)) { s2(); continue; } start = TACCR1; // Save captured start time // TACCTL1 &= ~CCIFG; // Clear capture flag while(!(TACCTL1 & CCIFG)); // Wait for falling edge stop = TACCR1; // Save captured stop time duration = stop - start; // Calculate duration of 8 bits // Calculate frequency freq = (unsigned)(((unsigned long)duration * 39322) >> 15); // Setup serial using measured bit duration serial_setup(BIT1, BIT2, duration >> 3); // Show info printf("RSEL: %u DCO: %u T: %u F: %u kHz\r\n", (unsigned)(BCSCTL1 & 0x0F), (unsigned)DCOCTL, duration, freq); // Increment DCO ++DCOCTL; } dco_serial.zip jim940, Rickta59 and bluehash 3 Quote Link to post Share on other sites
greeeg 460 Posted November 14, 2011 Share Posted November 14, 2011 This is actually pretty cool. I have a project that I have implemented a UART connection but no 32.768 khz crystal. You could adapt this to calculate the number of DCO clicks between bit for UART generation. You would just have to make sure the first transmitted character was an x Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.