This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5438 servo control (timing issues)

Other Parts Discussed in Thread: MSP430F5438

Hey guys

I was wondering if you could help me find the exact frequency at which SMCLK runs on the TI MSP430 Experimenter's Board (with the MSP430F5438 processor on board)? 

I'm trying to run a PWM signal with a period of 10ms, being high for 1.500 ms and low for the rest of the 10ms. This way, the servo should stay in the middle. For my calculations, I used the suggested value of SMCLK from TI in their sample code (1.048MHz). Using this value, I found that the total count for a 10ms period (the value in CCR0) should be 10480, and the count for a 1.5ms pulse (value in CCR1) should be 1572.

However, when observing the value of the pin on the oscilloscope, I find a pulse of about 1.3 - 1.4 ms and an overall period of 9.8ms... I was wondering if there was a higher speed clock that could be used for the timer, which would thereby add more precision to my timing? If not, can you guys help me find the exact speed of the clock in order to produce a reliable 1.5ms pulse every 10ms?

Thanks!

Alvaro

  • Hi Alvaro,

    use MCLK (main clock) for clocking your timers.

    Rgds
    aBUGSworstnightmare

  • Hey there

    Thanks for the quick reply. I don't know if I'm missing something, but one the datasheet it says I can choose from TBxCLK, ACLK, SMCLK or Inverted TBxCLK. It doesn't mention the MCLK as an option. I'm guessing that if I pick the TBxCLK I will get the MCLK you're talking about? Also, do you need the speed of this clock by any chance?

     

    Thanks,

    Alvaro

  • Hi,

    sry for the confusion! I wanted to say that you need to configure SMCLK (Subsystem master clock) to be equivalent to your fastest available clock (MCLK in most cases).

    SMCLK is software selectable as XT1CLK, REFOCLK, VLOCLK,DCOCLK, DCOCLKDIV, and when available, XT2CLK.

    So, let's assume your XT1CLK = 25MHz, then you can configure your clocks to be MCLK=SMCLK=25MHz (when not using any prescalers). No you can clock your timers with SMCLK.

    Rgds
    aBUGSworstnightmare

  • Alvaro,

    After a reset, the SMCLK and MCLK are sourced by the DCO which is not a highly calibrated system.  It can vary a fair amount and is probably why your timing is off.  Take a look at the basic clock module section of the users guide to see how to enable the XT1 oscillator (and selecting the XIN and XOUT pins as special puropose) so the FLL can reference a crystal.  Then your timing should be much more predictable with your calculations.

    Regards,

    Jim

     

  • Thanks for the help,

    I have studied the UCS part of the User's Guide and some example code where MCLK and SMCLK are chosen from different sources and think I know how to do it. My question is, on TI's Experimenter Board, what is the speed of the crystal connected to XT1 or XT2 (if there is a crystal there at all?) 

    Thanks,

    Alvaro

  • Hi Alvaro,

    with reference to the experomenters boards schematics (find them in the usres manual http://focus.ti.com/lit/ug/slau263e/slau263e.pdf, or clik the link to download the design files (page 29 of the users manual) to get the BOM) there is only X1 mounted (a 32.768kHz crystal).

    Rgds
    aBUGSworstnightmare

  • Alvaro,

    Generally the XT2 crystal is not populated on the board when it is shipped.  The XT1 crystal is usually populated with a 32.768kHz crystal or if it is not populated one is usually provided for you to solder in if you like.

    Note that there are different capacitive load selections in the clock module.  Usually these are not too important in actually getting the crystal to start oscillating as the default setting usually works but you may be able to adjust the crystal frequency slightly by varying this loading.  Ideally it should match the data sheet of the crystal which might be listed in teh BOM of the schematic (pointed to by ABugsWorstNightmare in another reply).  If it's not there, and you cannot identify the crystal by markings on it, then you just have to try different values and determine which is best both from startup and run characteristics.  No matter what, the value will be much closer to the actual value than the DCO is and will also be much more stable.  How much work you need to put into getting this exactly right depends on how much error you application can afford.

    Also, in my lab, these boards can get handed around quite a bit and things can change without much notice.  If you have no way of knowing exactly what crystals are populated, you may want do simply replace them with known ones (unless you enjoy banging your head against a wall).

    Good luck,

    Jim

     

  • Hey guys,

    Using the sample code msp430x54x_UCS_4.c (FLL+, Runs Internal DCO at 2.45MHz with LFXT1 as Ref), I was able to get a 2.45 MHz clock that was more precise than the previous ~1.045MHz. This increased the accuracy by a significant amount. If I happen to need more than that, I will just modify that example code to give me the desired frequency from XT1.

     

    Thanks for the help,

    Alvaro 

  • The 54xx has an internal 32k reference which is calibrated to <3% error. The default setup for the device is to use this reference for the internal FLL, resulting in a DCO clock of nearly 16MHz.
    On my demo board, this was precise and stable enough to make a 115kBd connection running. An external crystal, however, is more stable.
    In any case, the FLL will introduce a clock jitter (as the DCO is constantly switching between two taps to maintain the correct average frequency).

    This jitter is naturally reduced if you don't directly use the DCO but divide it down somehow (as it happens when using the baud rate divider, or using a timer and just see the signal over a complete timer cycle).

    personally, I prefer gettign my MCLK from a real high-frequency crystal. As long as there are not power-critical aspects against it.

    Independently of this, the required PWM frequency is usually uncritical (in a certain rainge) for most PWM applications. The critical part is the duty cycle. So  whether the PWM cycle is 9.8 or 10 or 10.2ms does not make any difference to the servo (unless it is doing some 'cheap' timing, not working on duty cycle but absolute pulse time) as long as the duty cycle is correct.

**Attention** This is a public forum