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.

RTOS/MSP430F5528: A C language "if" statement fails to execute correctly

Part Number: MSP430F5528


Tool/software: TI-RTOS

Hi,     I have a simple statement in my code that is malfunctioning.  The two test variables ( temperature, hi_temp_threshold ) are both declared as float.

When I am in the debugger, and stop on a breakpoint just before the if statement,  I modify temperature to a value of 3000.   hi_temp_threshold has a value of 2285.

Despite a large number attempts, the if statement always results in a false outcome, and does not execute my subsequent code.  

if( temperature > hi_temp_threshold )

{

a0 = a0_80;

a1 = 0;

a2 = 0;

}

This looks like some sort of memory issue to me, but I am not sure how to proceed.  Any help would be appreciated.

Note:  While looking around I discovered that my BIOS.heapSize is set to zero in the project CFG file.  Just as an experiment I boosted it to a value of 512 bytes.

This did not help, so the value was restored to zero.

My total SRAM usage is at 52%,  and I have done a fresh clean / build of the project.  The code in question is executed within an RTOS Task.

Thanks

Roy   

  • What happens if you add an assign statement:

    temperature = 3000; rather than setting it via the debugger?

    What happens if you use:

    if (3000 > hi_temp_threshold)

    Did you type in your code above, or copy and paste? If you typed it, look closely for any extra semicolons.

    Turn off optimization.

    Create a small test case, test it, and post it here.

  • This works fine on my MSP432P401R:

    /* --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--*/
    /*******************************************************************************
     * MSP432 GPIO - Toggle Output High/Low
     *
     * Description: In this very simple example, the LED on P1.0 is configured as
     * an output using DriverLib's GPIO APIs. An infinite loop is then started
     * which will continuously toggle the GPIO and effectively blink the LED.
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST         P1.0  |---> P1.0 LED
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *
     ******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    
    //![Simple GPIO Config]
    int main(void)
    {
        volatile uint32_t ii;
        float temperature;
        float hi_temp_threshold;
    
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Configuring P1.0 as output */
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    
        temperature = 3000.0;
        hi_temp_threshold = 2285.0;
    
        if (temperature > hi_temp_threshold)
        {
    
            while (1)
            {
                /* Delay Loop */
                for(ii=0;ii<5000;ii++)
                {
                }
    
                MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
            }
        }
    
        while (1) {};
    }
    //![Simple GPIO Config]
    
    
    

  • Hi Keith,

    The code is working now.  

    Thank you for your help.

    Roy

**Attention** This is a public forum