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.
Hi TI team:
1、在使用MSP430FR2433的TA0R不计数,发现如果执行延时函数,TA0R能够正常计时,但是其他的语句无法让TA0R计时;
2、想了解下在主频配置或者定时器初始化有什么不一样的地方?现在用的是16M主频,对输入时钟进行了8分频,8s中断唤醒一次
3、又测试发现如果定时器时钟源选择ACLK只有经过延时函数定时器可以正常计时,其他语句指令不计时,时钟源选择SMCLK时,所有指令都可以正常计时。附件是测试程序。
main() { _DINT(); WDTCTL = WDTPW | WDTHOLD; PortInit(); Ucs_Init_16M(); // Ucs_Init_1M(); TimerA0CounterSetup(); while(1) { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 WDTCTL = WDTPW | WDTCNTCL | WDTSSEL0_L | WDTIS_2; UCA1IE |= UCRXIE; APP_RTCPro_Delay_ms(2); uiTranceiver=TA0R; do { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 if(TA0R>=uiTranceiver)uiTemp=TA0R; else uiTemp=TA0R+0x8000; if((uiTemp-uiTranceiver)> T50ms) //400ms { P1OUT |= BIT3; P3OUT |=BIT3;; break; } }while((uiTemp-uiTranceiver)<(T200ms+T200ms)); P1OUT |= BIT3; UCA1IE &= ~UCRXIE; } } void Ucs_Init_16M(void) { FRCTL0 = FRCTLPW | NWAITS_1; P2SEL0 |= BIT0 | BIT1; do { CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag SFRIFG1 &= ~OFIFG; } while (SFRIFG1 & OFIFG); // Test oscillator fault flag __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__XT1CLK; CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // MCLK=SMCLK=DCO; ACLK=XT1 PM5CTL0 &= ~LOCKLPM5; } void TimerA0CounterSetup(void) { TA0CCTL0 |= CCIE; // CCR0 interrupt enabled TA0CCR0 = 0x8000; TA0CTL = TASSEL_1 | TACLR | ID_3 | MC_1; // ACLK, clear TAR,8��Ƶ��Up to CCR0 }
Susan:
我拿例程测试时单步执行还是无法计数;您可以将您测试例程发我一下。另外我测试程序如下。
main() { _DINT(); WDTCTL = WDTPW | WDTHOLD; PortInit(); Ucs_Init_16M(); TimerA0CounterSetup(); while(1) { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 WDTCTL = WDTPW | WDTCNTCL | WDTSSEL0_L | WDTIS_2; UCA1IE |= UCRXIE; APP_RTCPro_Delay_ms(2); unsigned int uiTemp=0; unsigned int uiTranceiver=0; uiTranceiver=TA0R; do { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 if(TA0R>=uiTranceiver)uiTemp=TA0R; else uiTemp=TA0R+0x8000; if((uiTemp-uiTranceiver)> T50ms) //400ms { P1OUT |= BIT3; P3OUT |= BIT3; break; } }while((uiTemp-uiTranceiver)<(T200ms+T200ms)); P1OUT |= BIT3; UCA1IE &= ~UCRXIE; } } void PortInit(void) { _DINT(); // P1DIR=0xff; P1OUT=0x00; // P2DIR=0xff; P2OUT=0x00; // P3DIR=0xff; P3OUT=0x00; P1DIR=0; P2DIR=0; P3DIR=0; P1OUT |= BIT3; P3OUT &= ~BIT3; _NOP(); } void Ucs_Init_16M(void) { FRCTL0 = FRCTLPW | NWAITS_1; P2SEL0 |= BIT0 | BIT1; do { CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag SFRIFG1 &= ~OFIFG; } while (SFRIFG1 & OFIFG); // Test oscillator fault flag __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__XT1CLK; CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // MCLK=SMCLK=DCO; ACLK=XT1 PM5CTL0 &= ~LOCKLPM5; } void TimerA0CounterSetup(void) { TA0CCTL0 |= CCIE; // CCR0 interrupt enabled TA0CCR0 = 0x8000; TA0CTL = TASSEL_1 | TACLR | ID_3 | MC_1; // ACLK, clear TAR,8��Ƶ��Up to CCR0 } void APP_RTCPro_Delay_ms(unsigned int iTimes) { for(unsigned int i=0;i<iTimes;i++) { unsigned int uiTemp0=0; unsigned int uiTranceiver0=TA0R; do { _NOP(); if(TA0R>=uiTranceiver0) uiTemp0=TA0R; else uiTemp0=TA0R+0x8000; }while((uiTemp0-uiTranceiver0)<0x21 ); } } /*********************************************************** �������ƣ� �������ܣ���ʱ��TA0�жϷ����������ж� ��ڲ����� ���ڲ����� ������ ************************************************************/ #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0_Counter (void) { TA0CTL=TA0CTL&(~TAIFG); _BIC_SR_IRQ(LPM3_bits); }
对于MSP430,查看定时器寄存器的话,建议不要单步,您可以设置断点或者全速运行后暂停查看
测试例程如下
/* --COPYRIGHT--,BSD_EX * Copyright (c) 2014, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT--*/ //****************************************************************************** // MSP430FR24xx Demo - Timer0_A3, Toggle P1.0, Overflow ISR, 32kHz ACLK // // Description: Toggle P1.0 using software and the Timer0_A overflow ISR. // In this example an ISR triggers when TA overflows. Inside the ISR P1.0 // is toggled. Toggle rate is exactly 0.5Hz. Proper use of the TAIV interrupt // vector generator is demonstrated. // // ACLK = TACLK = 32768Hz, MCLK = SMCLK = 8MHz/2 // // // MSP430FR2433 // ----------------- // /|\| | // | | | // --|RST | // | | // | P1.0|--> LED // // // Wei Zhao // Texas Instruments Inc. // Jan 2014 // Built with IAR Embedded Workbench v6.20 & Code Composer Studio v6.0.1 //****************************************************************************** #include <msp430.h> int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure clock __bis_SR_register(SCG0); // disable FLL CSCTL3 = SELREF__REFOCLK; // Set REFOCLK as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_3; // Set DCOCLK = 8MHz CSCTL2 = FLLD_1 + 121; // FLLD = 1, by default, DCODIV = DCO/2 = 4MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set ACLK = REFOCLK = 32768Hz, DCOCLK as MCLK and SMCLK source CSCTL5 |= DIVM0 | DIVS0; // SMCLK = MCLK = DCODIV = 4MHz // Configure GPIO P1DIR |= BIT0; P1OUT |= BIT0; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Configure Timer_A TA0CTL = TASSEL_1 | MC_2 | TACLR | TAIE; // ACLK, count mode, clear TAR, enable interrupt __bis_SR_register(LPM3_bits | GIE); // Enter LPM3, enable interrupts __no_operation(); // For debugger } // Timer0_A3 Interrupt Vector (TAIV) handler #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) TIMER0_A1_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(TA0IV,TA0IV_TAIFG)) { case TA0IV_NONE: break; // No interrupt case TA0IV_TACCR1: break; // CCR1 not used case TA0IV_TACCR2: break; // CCR2 not used case TA0IV_TAIFG: P1OUT ^= BIT0; // overflow break; default: break; } }