TI中文支持网
TI专业的中文技术问题搜集分享网站

比较器中断唤醒CPU的例程 /FR2111

Dear All,

有比较器中断唤醒CPU的例程吗?我看官方是没有使用中断的。

Susan Yang:

官方的例程是用port interrupt来唤醒的,没有比较器中断唤醒的

msp430fr211x_LPM3_01.c Enters LPM3 with ACLK = XT1CLK = 32768Hz.msp430fr211x_LPM3_02.c LPM3 entry with MCLK 16MHzmsp430fr211x_lpm3_5_01.c LPM3.5, device enter LPM3.5 and toggles P1.0 with RTC interrupt handling every 1smsp430fr211x_lpm4_5_01.c LPM4.5, Device enters LPM4.5 waiting for a port interrupt on P1.3msp430fr211x_lpm4_5_02.c LPM4.5, Device enters LPM4.5 waiting for a port interrupt on P1.3 with SVS disabled

Wade ZED:

回复 Susan Yang:

Hi Susan,
你们有写过吗?用汇编写的。

Susan Yang:

回复 Wade ZED:

很抱歉,暂时没有

Susan Yang:

回复 Wade ZED:

/* --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--*/
//******************************************************************************
// MSP430FR211x Demo - eCOMP output toggle, wake up from LPM3;
//Vcompare is compared against 1V.
//
// Description: Use eCOMP and internal VREF to determine if input 'Vcompare'
//is high or low.When Vcompare exceeds 1V(VREF*43/64), CPOUT goes high
//and LED is turned on. When Vcompare is less than 1V(VREF*43/64) then
//CPOUT goes low and LED is turned off. eCOMP interrupt enabled, wake up
//from LPM3.
//
//MSP430FR2111
//------------------
///|\||
//| ||
//--|RSTP1.1/C1|<--Vcompare
//|P2.0/COUT|--> 'high'(Vcompare>1V); 'low'(Vcompare<1V)
//|P1.0|--> LED
//||
//
//Xiaodong Li
//Texas Instruments Inc.
//Dec. 2015
//Built with IAR Embedded Workbench v6.40 & Code Composer Studio v6.1//******************************************************************************
#include <msp430.h>int main(void)
{WDTCTL = WDTPW | WDTHOLD;// Stop WDT// Configure GPIOP1OUT &= ~BIT0;// Clear P1.0 output latch for a defined power-on stateP1DIR |= BIT0;// Set P1.0 to output direction// Configure Comparator input & outputP1SEL0 |= BIT1;// Select eCOMP input function on P1.1/C1P1SEL1 |= BIT1;P2DIR |= BIT0;P2SEL1 |= BIT0;// Select CPOUT function on P2.0/COUTPM5CTL0 &= ~LOCKLPM5;// Disable the GPIO power-on default high-impedance mode// to activate previously configured port settings// Configure referencePMMCTL0_H = PMMPW_H;// Unlock the PMM registersPMMCTL2 |= INTREFEN;// Enable internal referencewhile(!(PMMCTL2 & REFGENRDY));// Poll till internal reference settles// Setup eCOMPCPCTL0 = CPPSEL0;// Select C1 as input for V+ terminalCPCTL0 |= CPNSEL1 | CPNSEL2;// Select DAC as input for V- terminalCPCTL0 |= CPPEN | CPNEN;// Enable eCOMP inputCPCTL1 |= CPIIE | CPIE;// Enable eCOMP dual edge interruptCPDACCTL |= CPDACREFS | CPDACEN;// Select on-chip VREF and enable DACCPDACDATA |= 0x002B;// CPDACBUF1=On-chip VREF*43/64 = 1VCPCTL1 |= CPEN;// Turn on eCOMP, in high speed mode__bis_SR_register(LPM3_bits | GIE);// Enter LPM3__no_operation();// For debug
}// eCOMP interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ECOMP0_VECTOR
__interrupt void ECOMP0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ECOMP0_VECTOR))) ECOMP0_ISR (void)
#else
#error Compiler not supported!
#endif
{switch(__even_in_range(CPIV, CPIV__CPIIFG)){case CPIV__NONE:break;case CPIV__CPIFG:P1OUT |= BIT0;break;case CPIV__CPIIFG:P1OUT &= ~BIT0;break;default:break;}
}

灰小子:

回复 Wade ZED:

现在很少有人用汇编了吧。推荐用c啊,更方便快捷。
楼主是什么样的应用?不防说出来大家给你推荐更合适的方案

Wade ZED:

回复 Susan Yang:

谢谢你,因为FR2111的程序空间有限,和MCU要求的反应时间较短,用汇编写是最快的。麻烦帮忙看看有没有相关的汇编程序。

Susan Yang:

回复 Wade ZED:

上面的那个例程是没有汇编的,只有一个IAR下的 msp430fr211x_eCOMP_01.s43

; --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--
;******************************************************************************
; MSP430FR211x Demo - eCOMP Toggle from LPM3; eCOMP in ultra low power mode,
;Vcompare is compared against internal VREF.
;
; Description: Use eCOMP and internal VREF to determine if input 'Vcompare'
;is high or low.When Vcompare exceeds 1.47V(VREF*63/64), CPOUT goes high
;and when Vcompare is less than 1.47V(VREF*63/64) then CPOUT goes low.
;
;MSP430FR2111
;------------------
;/|\||
;| ||
;--|RSTP1.1/C1|<--Vcompare
;||
;|P2.0/COUT|----> 'high'(Vcompare>1.47V); 'low'(Vcompare<1.47V)
;||
;
;Xiaodong Li
;Texas Instruments Inc.
;Dec. 2015
;Built with IAR Embedded Workbench v6.40;******************************************************************************
#include <msp430.h>
;-------------------------------------------------------------------------------RSEGCSTACK; Define stack segment
;-------------------------------------------------------------------------------RSEGCODE
;-------------------------------------------------------------------------------
RESETmov.w#SFE(CSTACK),SP; Initialize stack pointer
StopWDTmov.w#WDTPW+WDTHOLD,&WDTCTL; Stop WDT
SetPinbis.b#BIT1,&P1SEL0; Select eCOMP input function on P1.1/C1bis.b#BIT1,&P1SEL1bis.b#BIT0,&P2DIRbis.b#BIT0,&P2SEL1; Select CPOUT function on P2.0/COUTbic.w#LOCKLPM5,&PM5CTL0; Unlock I/O pinsSetREFmov.b#PMMPW_H,&PMMCTL0_H; Unlock the PMM registersbis.w#INTREFEN,&PMMCTL2; Enable internal reference
PollREFbit.w#REFGENRDY,&PMMCTL2; Poll till internal reference settlesjzPollREFSetCOMPmov.w#CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN,&CPCTL0; Select C1 as input for V+ terminal; Select DAC as input for V- terminal; Enable eCOMP inputbis.w#CPDACREFS+CPDACEN,&CPDACCTL; Select on-chip VREF and enable DACbis.w#0x3f,&CPDACDATA; CPDACBUF1=On-chip VREF *63/64bis.w#CPEN+CPMSEL,&CPCTL1; Turn on eCOMP, in low power modenopbis.w#LPM3,SR; Enter LPM3nop
;-------------------------------------------------------------------------------COMMONINTVEC; Interrupt Vectors
;-------------------------------------------------------------------------------ORGRESET_VECTOR; Reset VectorDWRESETEND

; –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–;******************************************************************************; MSP430FR211x Demo – eCOMP Toggle from LPM3; eCOMP in ultra low power mode,;                     Vcompare is compared against internal VREF.;; Description: Use eCOMP and internal VREF to determine if input 'Vcompare';    is high or low.  When Vcompare exceeds 1.47V(VREF*63/64), CPOUT goes high;     and when Vcompare is less than 1.47V(VREF*63/64) then CPOUT goes low.;;                MSP430FR2111;             ——————;         /|\|                  |;          | |                  |;          –|RST        P1.1/C1|<–Vcompare;            |                  |;            |         P2.0/COUT|—-> 'high'(Vcompare>1.47V); 'low'(Vcompare<1.47V);            |                  |;;   Xiaodong Li;   Texas Instruments Inc.;   Dec. 2015;   Built with IAR Embedded Workbench v6.40 ;******************************************************************************#include <msp430.h>;——————————————————————————-            RSEG    CSTACK                  ; Define stack segment;——————————————————————————-            RSEG    CODE;——————————————————————————-RESET       mov.w   #SFE(CSTACK),SP         ; Initialize stack pointerStopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDTSetPin      bis.b   #BIT1,&P1SEL0           ; Select eCOMP input function on P1.1/C1            bis.b   #BIT1,&P1SEL1            bis.b   #BIT0,&P2DIR            bis.b   #BIT0,&P2SEL1           ; Select CPOUT function on P2.0/COUT            bic.w   #LOCKLPM5,&PM5CTL0      ; Unlock I/O pinsSetREF      mov.b   #PMMPW_H,&PMMCTL0_H      ; Unlock the PMM registers            bis.w   #INTREFEN,&PMMCTL2       ; Enable internal referencePollREF     bit.w   #REFGENRDY,&PMMCTL2      ; Poll till internal reference settles            jz      PollREFSetCOMP     mov.w   #CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN,&CPCTL0                                            ; Select C1 as input for V+ terminal                                            ; Select DAC as input for V- terminal                                            ; Enable eCOMP input            bis.w   #CPDACREFS+CPDACEN,&CPDACCTL; Select on-chip VREF and enable DAC            bis.w   #0x3f,&CPDACDATA        ; CPDACBUF1=On-chip VREF *63/64            bis.w   #CPEN+CPMSEL,&CPCTL1    ; Turn on eCOMP, in low power mode            nop            bis.w   #LPM3,SR                ; Enter LPM3            nop;——————————————————————————-            COMMON  INTVEC                  ; Interrupt Vectors;——————————————————————————-            ORG     RESET_VECTOR            ; Reset Vector            DW      RESET            END

Wade ZED:

回复 Susan Yang:

我这样写的,仿真不对,是否存在问题?
;——————————————————————————————————————————————————-
; 比较器引脚配置bis.b #BIT1, &P1SEL0; 选择P1.1为模拟比较器输入口bis.b #BIT1, &P1SEL1bis.b #BIT0, &P2DIRbis.b #BIT0, &P2SEL1; 选择P2.0为模拟比较器输出口

; 睡眠
SetREFmov.b#PMMPW_H,&PMMCTL0_H; Unlock the PMM registersbis.w#INTREFEN,&PMMCTL2; Enable internal reference
PollREFbit.w#REFGENRDY,&PMMCTL2; Poll till internal reference settlesjzPollREF
mov.w#CPPSEL0+CPNSEL1+CPNSEL2+CPPEN+CPNEN, &CPCTL0; Select C1 as input for V+ terminal; Select DAC as input for V- terminal; Enable eCOMP inputbis.w #CPIIE + CPIE, &CPCTL1bis.w #CPDACREFS + CPDACEN, &CPDACCTLbis.w #0x2b, &CPDACDATAbis.w #CPEN, &CPCTL1
sleepclr.w &CPINTnopbis.w #LPM3 + GIE, SR nopjmp sleep
ecomp_interrupt_service_function ;比较中断函数
;============================================add.w &CPIV, PCretijmp wf1_interrupt_pendingjmp wf2_interrupt_pending
wf1_interrupt_pendingbis.b #BIT2, &P1DIRbic.b #BIT0, &P2DIR; 比较器输出关闭bic.b #BIT2, &P1DIRbis.w #CPIE, &CPCTL1; 关闭比较中断bic.w #LPM3 + GIE, 0(SP); 修改栈区(唤醒)reti

wf2_interrupt_pendingbis.b #BIT2, &P1DIRbic.b #BIT0, &P2DIR; 比较器输出关闭bic.b #BIT2, &P1DIRbis.w #CPIE, &CPCTL1; 关闭比较中断bic.w #LPM3 + GIE, 0(SP); 修改栈区(唤醒)reti
;——————————————————————————-COMMONINTVEC; Interrupt Vectors
;——————————————————————————-ORGRESET_VECTOR; POR, ext. ResetDW RESETORGPORT1_VECTOR; 外部中断DW port1_interrupt_service_functionORGECOMP0_VECTOR; 比较器中断DW ecomp_interrupt_service_function

Susan Yang:

回复 Wade ZED:

很抱歉,我很少用汇编,所以也不太确认您的问题。
或许您可以去 e2e.ti.com/…/ 发帖询问

Wade ZED:

回复 Susan Yang:

好的,谢谢你

赞(0)
未经允许不得转载:TI中文支持网 » 比较器中断唤醒CPU的例程 /FR2111
分享到: 更多 (0)