This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Optimization Assembly Problems

Hello everyone,

I am currently having an issue with some code I have that seems to vary based on optimization:


In CommBuff ISR:



if (commData == 0x61)   /* 0x61 = 'a' */
{
        if(DAC1DifVoltn==1)
        {
                DigPressure1 = DiffPressure1;  // Enters this section, problem here
        }
        else
        {
                DigPressure1 = Pressure1>>3;
        }
        COMBUF = DigPressure1>>8;
}
else if (commData == 0x62)      /* 0x62 = 'b' */
{
        COMBUF = DigPressure1;
}

Currently, DAC1DifVoltn is set to 1. When the COMBUF register gets a 0x61, it updates DigPressure1 and puts out the MSB on the COMBUF. When it receives 0x62, it sends out the LSB bits.

The problem I'm having is with the line:

DigPressure1 = DiffPressure1;

DiffPressure1 is set to 0x0FF8. When optimization is set to 4-8, DigPressure1 is set to 0x0097. When it's set to 3, it gets 0x0F97. When it's set to 2-0, it gets the correct value (0x0FF8). Realistically, this has to do with the way my code is written rather than it being an assembly issue but I can't seem to see a better way to handle this.

Does anyone have any explanations as to what I can do? If you need me to post the assembly code, I can do that as well. Any help would be appreciated. Thanks!

Parents
  • Here is a screenshot of the assembly code being executed:

    imgh.us/DiffAssemblyCode.jpg

    As far as your other questions go, I will admit, I don't know how to answer your questions regarding atomic operations or my stack (though, to be fair, I haven't had this issue in any other variable storage location, even when I try and shift a variable by 3 spaces and then place it into a variable, as shown in my else statement (which appears to work correctly).

    Regarding variables and interrupts, I have a pressure value that is updated in an ISR, which is then processed by a separate function and stored into Pressure1. Thus far, I haven't had any issues related to Pressure1.

    DiffPressure is created by subtracting Pressure1 from Pressure2 and then processed to calculate the desired differential voltage. It is then stored in DiffPressure1 (though I am currently working with a saturated differential channel, hence the 0x0FF8). I haven't used any volatile functions at this point as I haven't needed them. Not sure if this error is a result of this but I can step through everything and all the values are correct and the program steps through without any issues but that line I mentioned in a previous post is causing an issue when trying to store 1 unsigned int into another (it didn't have any problems when I tried to store Pressure1>>3 into this same DigPressure1 so I'm guessing the issue is with the DiffPressure1 variable. Except it has the correct value, it's just unable to store it into DigPressure1 correctly, which is just odd.

    It's kind of frustrating because storing one variable into another seems to be about as easy as it gets (especially when compared to the complexity of my current code). Maybe it's a really simple solution but, unfortunately, I can't see it yet.

    Thanks for your help, Per!

Reply
  • Here is a screenshot of the assembly code being executed:

    imgh.us/DiffAssemblyCode.jpg

    As far as your other questions go, I will admit, I don't know how to answer your questions regarding atomic operations or my stack (though, to be fair, I haven't had this issue in any other variable storage location, even when I try and shift a variable by 3 spaces and then place it into a variable, as shown in my else statement (which appears to work correctly).

    Regarding variables and interrupts, I have a pressure value that is updated in an ISR, which is then processed by a separate function and stored into Pressure1. Thus far, I haven't had any issues related to Pressure1.

    DiffPressure is created by subtracting Pressure1 from Pressure2 and then processed to calculate the desired differential voltage. It is then stored in DiffPressure1 (though I am currently working with a saturated differential channel, hence the 0x0FF8). I haven't used any volatile functions at this point as I haven't needed them. Not sure if this error is a result of this but I can step through everything and all the values are correct and the program steps through without any issues but that line I mentioned in a previous post is causing an issue when trying to store 1 unsigned int into another (it didn't have any problems when I tried to store Pressure1>>3 into this same DigPressure1 so I'm guessing the issue is with the DiffPressure1 variable. Except it has the correct value, it's just unable to store it into DigPressure1 correctly, which is just odd.

    It's kind of frustrating because storing one variable into another seems to be about as easy as it gets (especially when compared to the complexity of my current code). Maybe it's a really simple solution but, unfortunately, I can't see it yet.

    Thanks for your help, Per!

Children