Jump to content
43oh

MSP430g2553 1mhz or 16mhz? how to set it?


Recommended Posts

I have here some msp430g2553 wich i don't know the frequency. Since sometimes i need a low consuption (and i don't know sleep mode) and others a faster uControler i need to know how to set the frequency of the clock.

How can this be done with energia?

Link to post
Share on other sites

all the MSP430s can be set to any clock frequency generated by the DCO internally up to a max f i think 18MHZ or so, but they are most accurate frequency wise at 16MHZ, and 1MHZ which are the calibration point.  but you can set the DCO much lower than that to save power, and run it through internal dividers to make the effective frequency lower still.

Link to post
Share on other sites

Energia initializes it on poweron, yes.

 

The DCO is configured using some SFR (special function registers) for which there happen to be some pre-calibrated values built into the chip's flash (Info_A segment to be technical).  The two SFRs in question are called DCOCTL and BCSCTL1.

 

Energia actually does this inside "wiring.c":

#if defined(CALBC1_16MHZ_) && F_CPU >= 16000000L
        BCSCTL1 = CALBC1_16MHZ;
        DCOCTL = CALDCO_16MHZ;

There's nothing to say that, in your code, you can't do:

 

DCOCTL = CALDCO_1MHZ;

BCSCTL1 = CALBC1_1MHZ;

 

However from what I've been able to gather, the current Energia release uses that DCO for operating its millis() clock, so your millis() will be inaccurate as a result (clock will appear to run 1/16th as fast as it should).  This is because the app is hard-compiled with "F_CPU" of 16MHz which is used to derive the clock ticks vs. milliseconds.

 

(Those CALDCO_1MHZ and CALBC1_1MHZ constants are #define's provided by TI's headers that point to the location of those calibration constants in the Info_A segment, btw, so you don't have to think about figuring out where they are.)

 

Optionally, you can edit Energia's boards.txt file and create your own "board"...

 

Boards.txt entry for the G2553 looks like this:

lpmsp430g2553.name=LaunchPad w/ msp430g2553 (16MHz)
lpmsp430g2553.upload.protocol=rf2500
lpmsp430g2553.upload.maximum_size=16384
lpmsp430g2553.build.mcu=msp430g2553
lpmsp430g2553.build.f_cpu=16000000L
lpmsp430g2553.build.core=msp430
lpmsp430g2553.build.variant=launchpad

You can create your own version that runs exclusively at 1MHz by adding a new section to the end with the name changed (including the keyword prefix for those config settings), e.g.:

lpmsp430g2553mhz1.name=LaunchPad w/ msp430g2553 (1MHz)
lpmsp430g2553mhz1.upload.protocol=rf2500
lpmsp430g2553mhz1.upload.maximum_size=16384
lpmsp430g2553mhz1.build.mcu=msp430g2553
lpmsp430g2553mhz1.build.f_cpu=1000000L
lpmsp430g2553mhz1.build.core=msp430
lpmsp430g2553mhz1.build.variant=launchpad

Note how I added "mhz1" to the end of the prefix, and changed the "(16MHz)" to "(1MHz)".

The operative change, though, is changing "build.f_cpu" to 1000000.  This should trigger the #define's in Energia's core that make it run & clock at 1MHz instead.  Using this method, you should have an accurate millis() clock but the chip really will run at 1MHz all the time.

 

Of course, in that instance, you could always do the opposite strategy and up-clock it to 16MHz for critical math-intensive processing sections, so long as you can accept the fact that your millis() will get skewed during the duration of that section...

 

/* spin up the CPU... */

DCOCTL = CALDCO_16MHZ;

BCSCTL1 = CALBC1_16MHZ;

/* run some math-intense code here..... */

DCOCTL = CALDCO_1MHZ;

BCSCTL1 = CALBC1_1MHZ;

/* back to normal. */

Link to post
Share on other sites

I see that is very usefull.

I got to learn more about the cores and more advanced stuff. I didn't know that i could change the clock speed for each part of the code i need.

So in millis() if i see like 1 second it's actualy 16 seconds more or less? 

Link to post
Share on other sites

I see that is very usefull.

I got to learn more about the cores and more advanced stuff. I didn't know that i could change the clock speed for each part of the code i need.

So in millis() if i see like 1 second it's actualy 16 seconds more or less? 

Yeah, if your boards.txt spec has f_cpu of 16MHz and then you manually clock it down to 1MHz, that's what will happen.

Link to post
Share on other sites

Yeah, if your boards.txt spec has f_cpu of 16MHz and then you manually clock it down to 1MHz, that's what will happen.

ah! i see. I thought it was an error in Energia. It's actualy just the way it's configured when it compiles. Thanks!

Link to post
Share on other sites

I have a question about power use at 1mhz vs 16mhz. I know the processor uses less power at 1mhz, but if you spend most of your time in LPM3, waking up to do small tasks, it will take 16x longer to do those tasks at 1mhz. So do you actually gain anything by running at 1mhz?

Link to post
Share on other sites

Thanks @@spirilis, that's what I suspected - I figured it would take the same number of microamp-seconds to perform a certain routine, regardless of whether it was done at 1mhz or 16mhz.

 

As for LPM3, I've made a few mods to my libraries so that it is handled a little more gracefully. But like everything there are drawbacks.

Link to post
Share on other sites

Thanks @@spirilis, that's what I suspected - I figured it would take the same number of microamp-seconds to perform a certain routine, regardless of whether it was done at 1mhz or 16mhz.

 

As for LPM3, I've made a few mods to my libraries so that it is handled a little more gracefully. But like everything there are drawbacks.

Can you elaborate a bit on your experiences with LPM3 in Energia? I am mulling over some ideas to contribute to the Energia core to properly support LPM3 but I'm curious what kind of things already work.

 

Sent from my Galaxy Note II with Tapatalk

 

 

Link to post
Share on other sites

here is what i used:

 

I defined those constants to reference data written to the flash with the "Calibrate DCO With Checksum" program. There should be a copy of lnk_msp430g2231.cmd buried in the working directory for the compiler, renamed to lnk_msp430g2231_mod.cmd that has the new constants in it. You can check out this thread which explains clock calibration with the MSP430, custom clock calibration constants that result from running the calibration program, and what to do to be able to use those constants: http://www.43oh.com/forum/viewtopic.php?f=10&t=239

 
Basically, the MSP430G2XXX series does not have clock constants for anything higher than 1 MHz, so to be able to run the processor any faster (like what you'd need to be able to do the I2C stuff), then you have to manually make those constants.
 
Anyways, check out that thread.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...