Jump to content
43oh

Please help new dude on use of clocks with G2231


Recommended Posts

Being a wide eyed innocent to these TI woods I thought to set my launchpad msp430g2231 to run faster I could just set with:

BCSCTL1 = CALBC1_8MHZ;

DCOCTL = CALDCO_8MHZ;

 

... but now I've learned life is just not that simple!

 

Can these value line chip's internal clock be set to run to 8 or 16 mhz just by code or does it take some under the hood trick work? I read something somewhere in the forum about re-setting the dco values in the flash or something like that...it sounded quite a bit involved. So no simple way? I got a lot out of the "for beginner's thread" and especially the Gustavo Litovsky PDF link that's there, so I thx. But there's nothing there regarding my inquiry.

Link to post
Share on other sites

Hey iDave, have you considering using the Grace plugin for CCS? It will give you a nice GUI to set registers and then if you look in the src folder at the various Init files, you can see a great description of what each register does and how it's set in C code.

 

If you're not worried about the initial accuracy of the DCO, you can do it all in C without reflashing the calibration constants. You'll be off a few ticks here and there, for example without a reflash on one 2231, the closest I get is 8003.8Khz and it's different for others. There are few threads on here about reflashing the constants if you want the accuracy.

Link to post
Share on other sites

iDave,

 

You might also consider sampling some of the 20-pin devices. The '2252, '2452, and the '2553 devices I've received all have factory calibration in flash for 1, 8, 12, and 16 MHz, whereas the '2231 only has the 1 MHz factory calibration.

 

Cheerful regards, Mike

Link to post
Share on other sites
Hey iDave, have you considering using the Grace plugin for CCS? It will give you a nice GUI to set registers and then if you look in the src folder at the various Init files, you can see a great description of what each register does and how it's set in C code.

 

If you're not worried about the initial accuracy of the DCO, you can do it all in C without reflashing the calibration constants. You'll be off a few ticks here and there, for example without a reflash on one 2231, the closest I get is 8003.8Khz and it's different for others. There are few threads on here about reflashing the constants if you want the accuracy.

 

Thx for the reply gwdeveloper. And no initial accuracy I don't think is important for now. Do u have any example code or point me to some? I also DO have the GRACE plug in, I just haven't played with it yet.

 

iDave,

 

You might also consider sampling some of the 20-pin devices. The '2252, '2452, and the '2553 devices I've received all seem to have factory calibration in flash for 1, 8, 12, and 16 MHz, whereas the '2231 only seems to have the 1 MHz factory calibration.

 

Cheerful regards, Mike

 

Great to know! I'll order some for sure.

Link to post
Share on other sites

Hey guys, did you see this thread?

http://www.43oh.com/forum/viewtopic.php?f=10&t=239

 

You will need the watch crystal that came with the LP soldered on to do this... if you haven't already...

Then, all you need to do to use 8, 12, or 16MHz, is program the 2231 with Zeke's code on the top of page 2, and run it.

 

Also, check the last page for my post.

Link to post
Share on other sites
Hey guys, did you see this thread?

http://www.43oh.com/forum/viewtopic.php?f=10&t=239

 

You will need the watch crystal that came with the LP soldered on to do this... if you haven't already...

Then, all you need to do to use 8, 12, or 16MHz, is program the 2231 with Zeke's code on the top of page 2, and run it.

 

Also, check the last page for my post.

 

Awesome! Works like a champ...now I've got some real horsepower to play with!

 

Thanks a ton, everyone

Link to post
Share on other sites

Don't forget you can overclock as well... think 19.5MHz was the best I've gotten so far, worked perfectly fine too.

 

#define SetLow(port, pin) (port &= ~pin)
#define SetHigh(port, pin) (port |= pin)
#define Pulse(port, pin) do{SetHigh(port, pin);SetLow(port, pin);} while(0)

#define DELTA_1MHZ    244                   // 244 x 4096Hz = 999.4Hz
#define DELTA_8MHZ    1953                  // 1953 x 4096Hz = 7.99MHz
#define DELTA_12MHZ   2930                  // 2930 x 4096Hz = 12.00MHz
#define DELTA_16MHZ   3906                  // 3906 x 4096Hz = 15.99MHz
#define DELTA_18MHZ   4395                  // 4395 x 4096Hz = 18.00MHz
#define DELTA_20MHZ   4883                  // 4883 x 4096Hz = 20.00MHz
#define DELTA_24MHZ   5859                  // 5859 x 4096Hz = 23.99MHz

void Set_DCO(unsigned int Delta);            // Set DCO to selected frequency

#include "msp430g2452.h"

char Flipper = 0;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;						// Stop WDT

volatile unsigned int i;
for(i=0; i < 0xffff; i++ ) { ; }	// warm up the CPU

BCSCTL1 &= ~XTS;								// External source is LF
BCSCTL3 &= ~(LFXT1S0 + LFXT1S1);				// Watch crystal mode
BCSCTL3 |= XCAP0 + XCAP1;						// ~12.5 pf cap on the watch crystal as recommended

Set_DCO(4735); // 19,394,560

//	BCSCTL1 = CALBC1_1MHZ;                      // Set range  
//	DCOCTL = CALDCO_1MHZ;                       // Set DCO step + modulation

P1DIR |= (BIT0|BIT6);                               // P1.1 used to latch, P1.2 used to clock, P1.3 used to clear, P1.4 used to select DC/EEPROM
P1OUT &= ~(BIT0|BIT6);

CCTL0 = CCIE;									// CCR0 interrupt enabled
CCR0 = 62499;
TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK, Up 

_bis_SR_register(LPM0_bits + GIE);           // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if(Flipper)
	SetLow(P1OUT, BIT0);
else
	SetHigh(P1OUT, BIT0);
Flipper ^= 1;
Pulse(P1OUT, BIT6); 
}

void Set_DCO(unsigned int Delta)            // Set DCO to selected frequency
{
 unsigned int Compare, Oldcapture = 0;

 BCSCTL1 |= DIVA_3;                        // ACLK = LFXT1CLK/8
 TACCTL0 = CM_1 + CCIS_1 + CAP;            // CAP, ACLK
 TACTL = TASSEL_2 + MC_2 + TACLR;          // SMCLK, cont-mode, clear

 while (1)
 {
   while (!(CCIFG & TACCTL0));             // Wait until capture occured
   TACCTL0 &= ~CCIFG;                      // Capture occured, clear flag
   Compare = TACCR0;                       // Get current captured SMCLK
   Compare = Compare - Oldcapture;         // SMCLK difference
   Oldcapture = TACCR0;                    // Save current captured SMCLK

   if (Delta == Compare)
     break;                                // If equal, leave "while(1)"
   else if (Delta < Compare)
   {
     DCOCTL--;                             // DCO is too fast, slow it down
     if (DCOCTL == 0xFF)                   // Did DCO roll under?
       if (BCSCTL1 & 0x0f)
         BCSCTL1--;                        // Select lower RSEL
   }
   else
   {
     DCOCTL++;                             // DCO is too slow, speed it up
     if (DCOCTL == 0x00)                   // Did DCO roll over?
       if ((BCSCTL1 & 0x0f) != 0x0f)
         BCSCTL1++;                        // Sel higher RSEL
   }
 }
 TACCTL0 = 0;                              // Stop TACCR0
 TACTL = 0;                                // Stop Timer_A
 BCSCTL1 &= ~DIVA_3;                       // ACLK = LFXT1CLK
}

Link to post
Share on other sites
Hey guys, did you see this thread?

http://www.43oh.com/forum/viewtopic.php?f=10&t=239

 

You will need the watch crystal that came with the LP soldered on to do this... if you haven't already...

Then, all you need to do to use 8, 12, or 16MHz, is program the 2231 with Zeke's code on the top of page 2, and run it.

 

Also, check the last page for my post.

 

Well, sorry I was wrong. Nuetron, not sure what part of your post I need to apply. I copy paste what u have there and run it and just get errors. I use CCS (not IAR).

Link to post
Share on other sites

Oh, sorry. That was written for IAR. In the first post of the thread, it says this about CCS:

 

I'm using the MSP430G2231, so I duplicated the file C:\Program Files (x86)\Texas Instruments\ccsv4\msp430\include\msp430g2231.cmd in that directory, and renamed the duplicate as msp430g2231_mod.cmd. Now I can edit it without affecting the original. Edit msp430g2231_mod.cmd and change the calibration section at the bottom to this:

 

/************************************************************
* Calibration Data in Info Mem
************************************************************/
CALDCO_16MHZ       = 0x10F8;
CALBC1_16MHZ       = 0x10F9;
CALDCO_12MHZ       = 0x10FA;
CALBC1_12MHZ       = 0x10FB;
CALDCO_8MHZ        = 0x10FC;
CALBC1_8MHZ        = 0x10FD;
CALDCO_1MHZ        = 0x10FE;
CALBC1_1MHZ        = 0x10FF;

 

Now the linker knows we have calibration data in that section when we use the modified file.

 

When we create a new project in CCS or modify an existing one, CCS will want to use the default linking file, and the default header. Here's an example about how to configure a project to use the new constants.

First create a new project. Within the project, there should be a file called something like lnk_msp430g2231.cmd. The last line of that file should be something like -l msp430g2231.cmd. Open it, and change the last line to reflect the new linker file so it reads -l msp430g2231_mod.cmd.

Next, add the appropriate header file to the project. Right-click the project folder in the left pane of CCS and click "Add files to project..." In this example, I'm using C:\Program Files (x86)\Texas Instruments\ccsv4\msp430\include\msp430g2231.h. Now we have a copy of the file in the project we can safely edit. Edit the file so the calibration section looks like this:

/************************************************************
* Calibration Data in Info Mem
************************************************************/

#ifndef __DisableCalData

SFR_8BIT(CALDCO_16MHZ);                       /* DCOCTL  Calibration Data for 16MHz */
SFR_8BIT(CALBC1_16MHZ);                       /* BCSCTL1 Calibration Data for 16MHz */
SFR_8BIT(CALDCO_12MHZ);                       /* DCOCTL  Calibration Data for 12MHz */
SFR_8BIT(CALBC1_12MHZ);                       /* BCSCTL1 Calibration Data for 12MHz */
SFR_8BIT(CALDCO_8MHZ);                        /* DCOCTL  Calibration Data for 8MHz */
SFR_8BIT(CALBC1_8MHZ);                        /* BCSCTL1 Calibration Data for 8MHz */
SFR_8BIT(CALDCO_1MHZ);                        /* DCOCTL  Calibration Data for 1MHz */
SFR_8BIT(CALBC1_1MHZ);                        /* BCSCTL1 Calibration Data for 1MHz */

#endif /* #ifndef __DisableCalData */

 

Now you can begin using the new calibration data in your program. When you #include the msp430g2231.h file, put it in quotes instead of <> to ensure it's loading the modified header local to the project directory.

 

 

After you have that done, you should be able use

 

BCSCTL1 = CALBC1_16MHZ;

DCOCTL = CALDCO_16MHZ;

 

in your project code, or replace 16MHZ with 12MHZ, 8MHZ, or 1MHZ. Does that help? :)

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...