Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

msp430 launchpad clock system is really confusing. How to make accurate timing?

Status
Not open for further replies.

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
751
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,054
I am trying to make some thing with msp430 launchpad. Actually it got a DCO but that one is not at alll efficient and I cannot use it for some purpose like frequency measurement etc...

There is an option for connecting a external crystal in the board. But that is a 32KHz watch crystal. Still, I cannot use it while the MCU is running with MCLK. I mean I cannot make timer to run with the ACLK clock (32KHz) while the mcu is not in a power saving mode, ie when MCLK is not zero . So, how can I do some thing which need accurate timing using msp430 launchpad?
 

Hello!

I don't know what exactly you are trying to do, but what I do most of the time is using
FLL (frequency locked loop) and DCO. The time base is the 32k crystal, and your MCLK will be
a multiple of it.

Dora.
 

    V

    Points: 2
    Helpful Answer Positive Rating
okay that is enough... But I dont know how to make the main cpu clock as a multiple of the 32KHz crystal connected to it. Is that feature really there in msp430 launchpad devices?
 

Hello!

I just had a look at TI page, they write (for G2x series):

Basic Clock Module Configurations
Internal Frequencies up to 16 MHz With Four Calibrated Frequency
Internal Very-Low-Power Low-Frequency (LF) Oscillator
32-kHz Crystal
External Digital Clock Source

So if there are pre calibrated frequencies, it should be extremely easy to use them.
Beside this, there is a command to increase or decrease the DCO (which is the way
of making an FLL control). If you want a certain multiple, then you can use a timer
on the DCO frequency. Use a timer to measure DCO with 32k crystal reference. If
the number you get on timer interrupt is less than the multiple you want, then increase
DCO, otherwise decrease. Once you found the right value, you're done. HINT: you can
store this value in flash to use it next time. Or you can use the pre calibrated values
if they fit your needs.
By the way, look at TI code, there are many examples for using the clock system.

Edit on June 6th:
I just had a look at TI source code (launch pad related = slac467a.zip).
The following setting allows you to set a 16 MHz clock (factory calibrated). Of course,
it's a multiple of 32768 and therefore not exactly 16 MHz but very close.
as 16MHz/32768 = 488.28125, and as the modulation allows you to reduce the
interval by 8 (not sure, please verify), you will be set to 488.25 and the error will
be 64 ppm which is quite acceptable. If you use no modulation, you will be close
to 600 ppm from the target 16 MHZ, which is still quite acceptable, but this depends
on what you want to do.

Code:
BCSCTL1 = CALBC1_16MHZ;                   // Set range
DCOCTL = CALDCO_16MHZ;                    // Set DCO step + modulation

Dora.
 
Last edited:
Hi,
Actually the msp430g2231 packed with the launchpad kit have only 1 factory calibrated freqeuncy settings (1MHz). But any way I want some higher freq,say 16MHz.
Also, the msp430g2231 have only 1 timer module.
So I think I need to do a variable increment in a while loop (probably in assembly) and need to measure it at two different time intervals using 32KHz (crystal) ACLK timer interrupts and then calculate the current DCO frequency using that two values and adjust the DCO and repeat it until it matches our requirement and then save it for future use.

Is this what I should do? Or is there any better idea for it?
 

Hello!

Maybe the best way is to try to look at the registers and tune the clock yourself.
I don't know if it's possible on these small devices, but if you can get the SMCLK out, then
you do it and measure with the scope.
If you cannot do this, you enable for instance port1.0 as an output, set your scope on pin 1.0
and then do a loop like this:
while(1) P1OUT ^= 0x01;
You should observe 1/10 of the master clock.

Then you try to modify the internal DCO resistors. Open the register sub-window and look
at their values. Try to modify the DCO values and also register values. Modulation is not
important, so leave it as is. You should end up with the proper setting.

Dora.
 
The link may useful to you!
generation of delay using _delay_cycles() -- exact delay
**broken link removed**
 
I am trying to make some thing with msp430 launchpad. Actually it got a DCO but that one is not at alll efficient and I cannot use it for some purpose like frequency measurement etc...

There is an option for connecting a external crystal in the board. But that is a 32KHz watch crystal. Still, I cannot use it while the MCU is running with MCLK. I mean I cannot make timer to run with the ACLK clock (32KHz) while the mcu is not in a power saving mode, ie when MCLK is not zero . So, how can I do some thing which need accurate timing using msp430 launchpad?

I din't Understand what exactly you need, But here i had given code for ACLK(Crystal),

Code Description:
* This code can be used to test if you have installed the 32 Khz Crystal on your LaunchPad correctly.
* Using this code LED1 (P1.0) will turn on for 1 second, and turn off for 1 Second.
* You can verify this with Oscilloscope.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <msp430g2231.h>
 
unsigned int Minutes, Seconds;
 
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;   // Stop WDT
 
BCSCTL1 |= DIVA_3;  // ACLK/8
BCSCTL3 |= XCAP_3;  //12.5pF cap- setting for 32768Hz crystal
 
P1DIR |= BIT0;  // set P1.0 (LED1) as output
P1OUT |= BIT0;  // P1.0 low
 
Minutes = 0;
Seconds = 0;
 
CCTL0 = CCIE;   // CCR0 interrupt enabled
CCR0 = 511; // 512 -> 1 sec, 30720 -> 1 min
TACTL = TASSEL_1 + ID_3 + MC_1; // ACLK, /8, upmode
 
_BIS_SR(LPM3_bits + GIE);   // Enter LPM3 w/ interrupt
}
 
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= BIT0;  // Toggle LED
}

 
Last edited by a moderator:
Read this article! introduction to MSP430 Clock system
**broken link removed**
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top