MSP430F5438A: Issue with Variable Update in run time

Part Number: MSP430F5438A

Tool/software:

Hi,

I am currently working with the MSP430F5438A controller. During runtime, a variable is not updating as expected. However, if I place a breakpoint or add a small delay inside the function, the code works correctly. I am trying to understand why this is happening.

I have attached my code scenario, which runs inside a GPIO interrupt.

In the example below, the variable "ok" is not updating in real-time. Ideally, when the code executes, "ok" should be set to 1, but instead, it remains 0, which turns on LED2. In this condition, a load is being switched as per the schematic.

Example Code:

uint8_t ok = 0;

if (P1IFG & BIT2)
{
P11OUT |= BIT2; /*PROC_FAN */
ok = 1;

if (ok == 0)
{
P10OUT |= BIT3; /* LED 2 ON */
}

P1IFG &= ~BIT2;
}
I would appreciate any insights into why this issue occurs and how to resolve it.


Thanks & Regards,

Anbu.

  • Hi, 

    Try to add volatile to ok.

    volatile uint8_t ok = 0;

    Regards,

    Helic

  • Hi Helic,

    I tried your suggestion, but it did not work.

    Kindly refer to the previously attached section. In my case, the load is connected via P11.2. If the load is not connected, the system works fine. It also functions correctly when the load remains constantly high. However, when the load transitions from low to high, the system does not work as expected.

    Could you help me understand why this is happening?

  • Hi, 

    Although I can't get what's the load connected to.

    I guess that there is a power drop when load from low to high.

    Could you please check the power supply voltage in these three condition using a scope:

    If the load is not connected, the system works fine.
    It also functions correctly when the load remains constantly high.
    when the load transitions from low to high, the system does not work as expected.

    Regards,

    Helic

  • Hi Helic,

    Thank you for your observations.

    I have already checked the power supply voltage under the three conditions you mentioned using an oscilloscope. The voltage drop is similar in all three cases.

    However, when the load transitions from low to high, I am facing an issue with the execution of a function. The problem seems to be that the "ok" variable is not updating its value properly. Please check on your end and update me as soon as possible.

    For your reference, I have used a 24V DC fan as the load in this setup.

    Thanks,
    Anburaja A

**Attention** This is a public forum