复位后MSP430时钟问题

发布于 2024-12-14 00:34:59 字数 884 浏览 0 评论 0原文

我使用以下例程来配置 MSP430 (msp430g2231) 微控制器的时钟:

void configure_clock(void) {
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) { // Checks the clock constants
        while(TRUE); // If callibration constants are erased, TRAP!
    }

    BCSCTL1 |= CALBC1_1MHZ; // Sets DCO range
    DCOCTL |= CALDCO_1MHZ; // Set DCO step and modulation

    BCSCTL1 &= ~(XTS | XT2OFF); // Disables XT2 and sets low frequency mode
    BCSCTL3 |= (LFXT1S_0 | XCAP_3); // Selects LFXT1 crystal with 12,5pF

    do {
        IFG1 &= ~OFIFG;
        __delay_cycles(1000);
    } while (IFG1 & OFIFG); // Waits until crystal stabilizes

    BCSCTL2 |= (SELM_2 | SELS); // Selects SMCLK and MCLK from LFXT1CLK
}

问题是代码第一次运行时(就在微控制器通电后),一切都按预期工作,我得到 32768 kHz 时钟。但是,如果我按下主板上的重置按钮(MSP430 Launchpad),时钟似乎无法正常工作,代码执行速度很慢(大约 10 次左右)。关于时钟配置有什么想法吗?

谢谢!

佩雷

I use the following routine to configure the clock of my MSP430 (msp430g2231) microcontroller:

void configure_clock(void) {
if (CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) { // Checks the clock constants
        while(TRUE); // If callibration constants are erased, TRAP!
    }

    BCSCTL1 |= CALBC1_1MHZ; // Sets DCO range
    DCOCTL |= CALDCO_1MHZ; // Set DCO step and modulation

    BCSCTL1 &= ~(XTS | XT2OFF); // Disables XT2 and sets low frequency mode
    BCSCTL3 |= (LFXT1S_0 | XCAP_3); // Selects LFXT1 crystal with 12,5pF

    do {
        IFG1 &= ~OFIFG;
        __delay_cycles(1000);
    } while (IFG1 & OFIFG); // Waits until crystal stabilizes

    BCSCTL2 |= (SELM_2 | SELS); // Selects SMCLK and MCLK from LFXT1CLK
}

The problem is that the first time the code runs (just after powering up the microcontroller) everything works as expected and I get 32768 kHz clock. But if I press the reset button on the board (MSP430 Launchpad) the clock does not seem to work correctly, the code executes much slowly (like 10 times or so). Any ideas on the clock configuration?

Thanks!

Pere

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深白境迁sunset 2024-12-21 00:34:59

首先可以查看电源电压。如果启动期间出现峰值,则 DCO 将无法工作。在这种情况下,请尝试在值与 BCSCTL1 对齐之前使用延迟。

   __delay_cycles(10000);
   BCSCTL1 = CALBC1_1MHZ; // Sets DCO range

这将确保启动尖峰受到抑制。

下一个嫌疑人将在目标板上解耦。我指的是 VCC 上的电容器以及复位中使用的电容器。 TI 建议复位线使用 1nF-2nF,VCC 使用 0.1uF。但如果您使用 LaunchPad 作为平台,那么这应该不是问题。

此外,对于校准值分配,请使用赋值运算符而不是逻辑运算符。因为其他值 0 是默认值。

  BCSCTL1 = CALBC1_1MHZ;               // Set DCO
  DCOCTL = CALDCO_1MHZ;

如果您计划运行 XT2,它在 G2231 中不可用。直接是LFXT1。
您不需要显式初始化即可使 32.768KHz 晶体工作。
当你通电时它才起作用。因此不需要额外的初始化步骤。

为了获得更好的帮助,请查看 slac463a 获取与时钟设置相关的软件示例。

First you can look at the power supply voltage. In case there is some spike during the startup then DCO wont work. In that case try to use a delay right before the Alignment of the values to BCSCTL1.

   __delay_cycles(10000);
   BCSCTL1 = CALBC1_1MHZ; // Sets DCO range

This will ensure that the startup spike is suppressed.

The next suspect would be decoupling on your target board. I mean the Capacitor on the VCC as well as the one used in the Reset. TI recommends 1nF-2nF for the Reset line and a 0.1uF for the VCC. But in case you are using the LaunchPad as you platform then that should not be a problem.

Also for the calibration value assignments use assignment operators and not logical operators. As the other values being 0 is a default.

  BCSCTL1 = CALBC1_1MHZ;               // Set DCO
  DCOCTL = CALDCO_1MHZ;

If you are planning to Run the XT2 it is not available in G2231. Its LFXT1 directly.
You dont need explicit initialization for the 32.768KHz crystal to work.
It just work when you power up. So the additional initialization step is not needed.

In order to find better help please have a look at slac463a for software examples related to clock setting.

面犯桃花 2024-12-21 00:34:59

我可以对您的代码提出的唯一建议如下。我不知道他们是否解决了您的问题,因为第一次运行正常但重置后却不行,这似乎很奇怪。您是否可以在其他地方访问时钟配置?重置时调用什么代码?

您始终使用位操作将值包含或排除到寄存器中。您应该从一个已知值开始,然后从那里调整位,否则您可能会合并来自先前状态的位。例如,

BCSCTL1 |= CALBC1_1MHZ;
BCSCTL1 &= ~(XTS | XT2OFF);

您可以通过执行以下操作将其设置为确定值:

BCSCTL1 = XT2OFF | (CALBC1_1MHZ & 0x0F);

另一个建议是必须设置 XT2OFF 才能关闭 XT2。您正在清除该位,因此将其保留。这与您的评论相冲突,因此可能是一个错误。

The only things I can suggest with your code are below. Whether or not they fix your issue I don't know as it seems strange that the first run is OK but after a reset it is not. Do you access the clock configuration anywhere else? What code do you call on reset?

You always use bit manipulation to include or exclude values into the registers. You should start with a known value and then adjust bits from there otherwise you may be incorporating bits from a previous state. For example, instead of:

BCSCTL1 |= CALBC1_1MHZ;
BCSCTL1 &= ~(XTS | XT2OFF);

You can set it to a definitive value by doing something like this:

BCSCTL1 = XT2OFF | (CALBC1_1MHZ & 0x0F);

The other suggestion is that XT2OFF has to be set in order to turn off XT2. You are clearing the bit, so are leaving it on. This is in conflict with your comment so might be an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文