Good Morning,
I have used floating-point operations in HC08 processors for many years, but this is the first time that I have tried it with an HCS08 processor. I am trying to multiply a floating-point number and a short, and the processor simply hangs up. I have plenty of stack space and plenty of memory. Here are the significant lines of code:
float Kp;
short E;
float temp;
short Rs;
Rs = RS232RX << 2;
E = Rs - A2D0[0];
// proportional controller
temp = Kp * E; // this hangs
if(temp > 1023)
temp = 1023;
else if(temp < -1023)
temp = -1023;
PWM0 = (short)temp;
The code hangs up at the line:
E = Rs - A2D0[0];
I then tried to typecast E from a short to a float before the multiply:
float Efloat;
Efloat = (float)E; // this hangs
It hangs up on the typecast. Interestingly, if I comment out that line and set the values to constants, the typecast from float to short works fine:
PWM0 = (short)temp; // this is OK
I am using the ansitfs library. Any help would be greatly appreciated.
Thank you.
已解决! 转到解答。
After seeing my original message online, I realized that it is a bit verbose. To the point, Code written with CodeWarrior for HCS08, using the ansitfs library, seems to hang up when typecasting from a short to a float, or when typecasting from an int to a float. It also hangs up when trying to multiply a short and a float. It does seem to work fine, however, when typecasting from a float to an int or short.
Has anyone seen this problem, and is there a solution?
Thank you.
Good Morning,
I created the project using the IEEE32/32 tiny memory module, and have not changed any of the compiler settings. I have created many variables in higher memory using the #pragma DATA_SEG FAR FAR_RAM statement, and these variables do not seem to create any problems (I access them with no errors). The problem only occurs when I tried to multiply an integer and a float. I have worked around the problem by multiplying my floating point number by 64, performing integer multiplication, and then bit shifting the result to the right by 4. Using this workaround, my entire project works well, although the code is somewhat difficult to read, and I would much rather use the floating-point multiplication.
When troubleshooting the problem, I tried multiplying a float and a float – that worked fine. I then tried multiplying an integer and an integer – that also worked fine. The problem only occurs when trying to multiply a float and an integer. I then tried to typecast the integer to a float before performing the multiplication – and that is where the problem occurred.
I have attached a screenshot of the emulator screen stopped at the point where it hangs. I would also gladly send you the project, if you are interested. It is a small project, and it is not proprietary.
Thank you.
Good Morning,
In CodeWarrior v6, when a new project is created using the tiny memory module, the following message appears:
“By default all variables are in the zero page (direct memory access). Variables outside the zero page can be used with pragmas or the far keyword.”
I used pragmas to locate commonly used variables outside of the zero page (such as my PWM values, the A2D array, and other data collection variables). I also located the stack in high memory (in the .prm file). Memory location 0x246 is within my stack. This is the seventh project in which I have used this same configuration (I just create a new folder, copy the old files into it, and open this copied project as a starting point). Every project has worked with no problem – the high memory variables can be accessed, the new variables created go into low memory, and the stack works as expected.
The only problem that I have is multiplying a float and an integer (as I mentioned integer*integer and float*float works fine). The problem seems to be in casting the integer to a float (casting the float to an integer also works fine).
I have a work-around and, in fact, my work-around runs faster than the library floating point multiply routine. It just makes the code a little difficult to understand.
Thank you.
Thank you for the information. For future projects, I will try the small memory model (it is a little late for this one). It seems that the tiny memory model is really only intended for memory usage up to FF.
In the small memory model, is the stack restricted to high memory (the message states that all variables are placed in high memory)? It seems that, for the small memory model, variables placed in low memory (zero page) must be defined with a pragma. Will I have the same problem? In other words, with the small memory model, will I only be able to use high memory if I want to perform floating point operations?