0
\$\begingroup\$

First off: I'm brand new to microcontroller development, so please forgive me for the simple question. I'm trying to learn for my FIRST robotics team so we can use the MSP430 to handle some extra sensors.

I'm working on understanding/configuring the Unified Clock System. I want it to run on the 25 MHz setting. I've been reading the family guide and device specific datasheet. I think I have a basic understanding. My code is below:

/*
* Objective: have SMCLK run at ~25 MHz for driving an SPI device
*/
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
__bis_SR_register(SCG0); //Disable FLL
UCSCTL0 = DCO0+DCO1+DCO2+DCO3+DCO4 ; //DCO 31 bit and MOD bit 0 [THIS IS NOT WORKING]
UCSCTL1 = DCORSEL_4; //Select frequency range on http://www.ti.com/lit/ds/symlink/msp430f5529.pdf page 31
UCSCTL2 = 0x000; //Select no loop divider
UCSCTL3 |= SELREF_2; //Set FLL reference to REFOCLK (only internal)
UCSCTL4 |= SELS__DCOCLK; //Select SMCLK clock source to be DCOCLK
P1DIR |= (BIT0 + BIT2); //irrelevant
P2DIR |= BIT2; //Set P2.2 as out direction to monitor clock
P2SEL |= BIT2; //Select P2.2 as SMCLK output defined in http://www.ti.com/lit/ds/symlink/msp430f5529.pdf pg 84
__bic_SR_register(SCG0); //Enable FLL

However, this isn't working well, resulting in a very strange oscilliscope output for two reasons:

  1. The output's waveform is not how I usually see the clock output. Usually I see something resembling a sin wave, now I see something very different.

  2. The waveform shows the clock to be running at ~2 MHz not the desired 25.

enter image description here

Ignore the green line.

\$\endgroup\$

migrated from stackoverflow.com Jul 20 '17 at 17:41

This question came from our site for professional and enthusiast programmers.

  • \$\begingroup\$ What is the value in UCSCTL0 that you see? Also, what do you mean by "does not work"? Wrong frequency or the system hangs? \$\endgroup\$ – kfx Jul 16 '17 at 18:24
  • \$\begingroup\$ @kfx when I configure it to be DCO0+DCO1+DCO2+DCO3+DCO4 I see the correct values for the DCO bits. However, the system hangs, (my led dosen't blink is the indicator and I see no clock output). When I use other DCO values e.g. 0x00 I see the wrong DCO bits 00000 and the wrong output frequency (which is to be expected) but the system works. I've edited this into the question, thanks for pointing out the need for the clarification. \$\endgroup\$ – Ashwin Gupta Jul 16 '17 at 18:26
  • \$\begingroup\$ @kfx yeah I realized that myself just a moment ago. I tried the same code with DCORSEL_4 and DCO 11111 (which should run it at 12-28 MHz) and now the system works but the output I'm getting on my oscilliscope makes no sense to me. \$\endgroup\$ – Ashwin Gupta Jul 16 '17 at 18:33
  • \$\begingroup\$ Oh, great. I just put that suggestion in an answer. \$\endgroup\$ – kfx Jul 16 '17 at 18:34
  • \$\begingroup\$ @kfx lol np, your answer is technically correct, but just dosen't adress the entire question (since it adresses the cause of the issue but dosen't solve it) Any ideas on what that oscilliscope output means? I edited the image of my output into the question body. \$\endgroup\$ – Ashwin Gupta Jul 16 '17 at 18:37
3
\$\begingroup\$

According to the MSP430F5529 datasheet, this MCU supports "up to 25-MHz System Clock" rate. Consequently, achieving 39 MHz stable operation is not possible.

On msp430, it's often possible to write DCO configuration values in the registers that are out of the range of the MCU capabilities. Looks like this is what's happening here.

Try setting UCSCTL1 to DCORSEL_4. That should give MCU clock speed in range from 12 to 28 MHz according to the datasheet.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.