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.

[参考译文] MSP430FR2532:在 CAPT_appHandler ()激活时向 LED2添加更长的延迟(30秒)(电容式按钮)

Guru**** 1129500 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1323047/msp430fr2532-adding-a-longer-delay-30-seconds-to-led2-while-capt_apphandler-is-active-capacitive-button

器件型号:MSP430FR2532

TI 论坛、您好!

我正在尝试在以下代码中为 LED2添加更长的延迟。 我尝试了使用__delay_cycles、但最多可以达到15秒左右。 如果我增大该值、则会编译代码、但不起作用。

我尝试实现的是以下目标、

1.用户触摸按钮(进入 CAPT_APPHAN德勒())

2.输出 LED2 (30秒始终开启、无切换)和输出 LED1 (30秒、但快速切换、以降低功耗

3.回到睡眠状态。

下面是我的代码:

/* --COPYRIGHT--,BSD
 * Copyright (c) 2017, 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.
 * --/COPYRIGHT--*/
//*****************************************************************************
// Development main.c for MSP430FR2633, MSP430FR2533, MSP430FR2632, and
// MSP430FR2532.
//
// This starter application initializes the CapTIvate touch library
// for the touch panel specified by CAPT_UserConfig.c/.h via a call to
// CAPT_appStart(), which initializes and calibrates all sensors in the
// application, and starts the CapTIvate interval timer.
//
// Then, the capacitive touch interface is driven by calling the CapTIvate
// application handler, CAPT_appHandler().  The application handler manages
// whether the user interface (UI) is running in full active scan mode, or
// in a low-power wake-on-proximity mode.
//
// The CapTIvate application handler will return true if proximity was
// detected on any of the sensors in the application, which is used here
// to control the state of LED2. LED1 is set while the background loop enters
// the handler, and is cleared when the background loop leaves the handler.
//
// \version 1.83.00.05
// Released on May 15, 2020
//
//*****************************************************************************

#include <msp430.h>                      // Generic MSP430 Device Include
#include "driverlib.h"                   // MSPWare Driver Library
#include "captivate.h"                   // CapTIvate Touch Software Library
#include "CAPT_App.h"                    // CapTIvate Application Code
#include "CAPT_BSP.h"                    // CapTIvate EVM Board Support Package

void main(void)
{
	//
	// Initialize the MCU
	// BSP_configureMCU() sets up the device IO and clocking
	// The global interrupt enable is set to allow peripherals
	// to wake the MCU.
	//
	WDTCTL = WDTPW | WDTHOLD;
	BSP_configureMCU();
	__bis_SR_register(GIE);

	//
	// Start the CapTIvate application
	//
	CAPT_appStart();

	//
	// Background Loop
	//
	while(1)
	{
		//
		// Run the captivate application handler.
		// Set LED1 while the app handler is running,
		// and set LED2 if proximity is detected
		// on any sensor.
		//
		
		if(CAPT_appHandler()==true)
		{
			LED2_ON;
			__delay_cycles(300000000);
			
		}
		else
			LED2_OFF;
		
		
		//
		// This is a great place to add in any 
		// background application code.
		//
		__no_operation();

		//
		// End of background loop iteration
		// Go to sleep if there is nothing left to do
		//
		CAPT_appSleep();
		
	} // End background loop
} // End main()

我们将感谢您提供任何支持/指导。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ty:

    如果 MCU 仅在工作模式下运行、以下方法可轻松实现这一点。  如果您使用的是 WOP 的"接近唤醒"功能,改变 CAPT_UserConfig.c 应用参数.ui16InactivityTimeout =_30sec = 1500。 这样做将强制 MCU 保持工作模式足够长的时间、以获得所需的效果。

    uint16_t LED_count;
    bool TouchFlag = false;
    
    #define _30SEC               (909)
    #define _125mSEC             (8)
    
    void main(void)
    {
    	//
    	// Initialize the MCU
    	// BSP_configureMCU() sets up the device IO and clocking
    	// The global interrupt enable is set to allow peripherals
    	// to wake the MCU.
    	//
    	WDTCTL = WDTPW | WDTHOLD;
    	BSP_configureMCU();
    	__bis_SR_register(GIE);
    
    	//
    	// Start the CapTIvate application
    	//
    	CAPT_appStart();
    
    	//
    	// Background Loop
    	//
    	while(1)
    	{
    	    if(CAPT_appHandler()==true)
    	    {
    
    	        if(TouchFlag == false)
                {
                    TouchFlag = true;
                    LED1_ON;
                    LED2_ON;
                }
    	    }
    
    	    if(TouchFlag == true)
    	    {
    	        LED_count++;
    
                /* Time to toggle LED1? */
                if(LED_count % _125mSEC == 0)
                {
                    LED1_TOGGLE;
                }
    
                /* Time to turn off both LEDs */
                if(LED_count == _30SEC)
                {
                    LED1_OFF;
                    LED2_OFF;
                    TouchFlag = false;
                    LED_count = 0;
                }
    	    }
    
    		//
    		// This is a great place to add in any 
    		// background application code.
    		//
    		__no_operation();
    
    		//
    		// End of background loop iteration
    		// Go to sleep if there is nothing left to do
    		//
    		CAPT_appSleep();
    		
    	} // End background loop
    } // End main()
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Dennis、谢谢您。 我已更新、似乎按预期工作。

    因此、为了说明这一点、我需要根据我希望 LED1和 LED2处于活动状态的时间长度来调整 CAPT_UserConfig.c 不活动超时参数。 三个问题;

    Q1结合上述调整,我必须调整以下各项;

    #define _30sec              (909)
    #define _125mSEC            (8)

    如何更改这些常数? (我尝试将8改成一个越来越小的数字、因为 LED 切换太慢、设备无法识别我的触摸。 我需要它快速闪烁)

    第2季度

    增加的不活动超时参数是否会对功耗产生影响? Im 猜测是。

    第3季度

    如果我希望 LED1快速闪烁2-3秒(以优化功耗为目的)、而 LED2保持在30秒、该怎么办? 我该如何调整哪些参数呢?

    再次感谢您、您真的很有帮助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ty:

    我必须对我的上一篇文章进行更正,内容涉及_30sec = 1500在我的评论中,这是错误的。  该值基于 .ui16ActiveModeScanPeriod = 20、而不是33。  在我的代码示例中是909、这是正确的。  很抱歉有任何混淆。

    此外、my_125mSEC 的值应为4、而不是8、原因相同。

    是的、如果您希望 LED 保持活动状态30秒、则需要将不活动时间设置为至少30秒。

    q1 -这些#define 只能在编译期间更改(分配不同的值)。  如果要在运行时"动态"更改这些值,请 改用变量。

    例如:

    uint16_t _30sec = 909;
    uint16_t _125msec = 8;

    我不知道为什么它会在您的设置中停止识别触控。  它在我的 BSWP 设置上运行得很好。  我对它进行了非常全面的测试。 ;)

    我忘了说、在 MCU 进入 WOP 模式之前、确保有足够的时间完成30秒的 LED 定时周期并关闭两个 LED。  为此,可以将.ui16InactivityTimeout 设置为略长于30秒的值。  因此、使用909而不是910。  明白了吗? 这可以保证计数器计数到高达900、并且该例程将关闭两个 LED。

    Q2 -是。  超时值越大、MCU 保持工作模式的时间就越长。

    Q3 -要控制切换 LED2的时间、您需要定义另一个计数超时并添加另一个标志。  您可以使用#define 或变量、具体取决于您是否要在运行时更改该值。  请参见以下示例。

    注:您可以使用"swite()语句"使代码更易于阅读和执行相同的功能。  这可以是一个练习,供你尝试;)

    uint16_t LED_count;
    bool TouchFlag = false;
    bool ToggleFlag = false;
    uint16_t _30sec = 909;  // Note: set .ui16InactivityTimeout = 910 to allow LED cycle to finish
    uint16_t _2sec = 60;
    uint16_t _125msec = 4;
    
    
    void main(void)
    {
    	//
    	// Initialize the MCU
    	// BSP_configureMCU() sets up the device IO and clocking
    	// The global interrupt enable is set to allow peripherals
    	// to wake the MCU.
    	//
    	WDTCTL = WDTPW | WDTHOLD;
    	BSP_configureMCU();
    	__bis_SR_register(GIE);
    
    	//
    	// Start the CapTIvate application
    	//
    	CAPT_appStart();
    
    	//
    	// Background Loop
    	//
    	while(1)
    	{
    	    if(CAPT_appHandler()==true)
    	    {
    
    	        if(TouchFlag == false)
                {
                    TouchFlag = true;
                    ToggleFlag = true;
                    LED1_ON;
                    LED2_ON;
                }
    	    }
    
    	    if(TouchFlag == true)
    	    {
    	        LED_count++;
    
    	        /* Toggle LED1 for only 2 seconds */
    	        if(ToggleFlag == true)
    	        {
                    /* Time to toggle LED1? */
                    if(LED_count % _125msec == 0)
                    {
                        LED1_TOGGLE;
                    }
    
                    if(LED_count == _2sec)
                    {
                        ToggleFlag = false;
                        LED1_OFF;
                    }
    
    	        }
    
                /* Time to turn off both LEDs */
                if(LED_count == _30sec)
                {
                    LED1_OFF;
                    LED2_OFF;
                    TouchFlag = false;
                    LED_count = 0;
                }
    	    }
    
    		//
    		// This is a great place to add in any 
    		// background application code.
    		//
    		__no_operation();
    
    		//
    		// End of background loop iteration
    		// Go to sleep if there is nothing left to do
    		//
    		CAPT_appSleep();
    		
    	} // End background loop
    } // End main()