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.
Hello everyone,
I am using a MSP430F2417 Device and CCE. I am working on a time critical code and while checking the timing of the code I observed that the controller is taking an unusually long time to execute the floating point arithmetic code. I am posting the code below, please have a look.
for ( I_Uch = 0; I_Uch < 18; I_Uch++)
{
TEMP2_Fl = sin( 0.0872664626 * I_Uch );
TEMP3_Fl = cos( 0.0872664626 * I_Uch );
TEMP0_Fl = (signed int)SAMPLE_ARRAY_Intr_SInt[I_Uch];
TEMP2_Fl = TEMP0_Fl * TEMP2_Fl;
TEMP3_Fl = TEMP0_Fl * TEMP3_Fl;
FUND_SIN_RMS_Fl = FUND_SIN_RMS_Fl + TEMP2_Fl ;
FUND_COS_RMS_Fl = FUND_COS_RMS_Fl + TEMP3_Fl ;
TEMP1_Fl = TEMP0_Fl * TEMP0_Fl;
WAVE_RMS_Fl = WAVE_RMS_Fl + TEMP1_Fl;
}
Can anyone help me on this issue?
Thanks!
I do not know what you mean by "unusually long time"? As compared with what?
The execution time depends on (a) the CPU you use, (b) the way you write the code, and (c) the compiler you use.
For (a), you could try to use MSP430F5xx, ARM, MIPS, etc. For (b), you could improve a lot too.
I only have KickStart, I tried the code you shown with some random SAMPLE_ARRAY_Intr_SInt[18] (the execution time is data dependent). And it took ~6.7 msec (~107,000 MCLKs at 16 MHz). What did you get with CCE?
If I change you code, I think it could run much faster.
Hi there,
Thanks for the reply.
By "unusually long time" I meant that the code execution on the MSP430F2417 was quite long as compared to the MCS51 architecture processors. Actually I am trying to port a code from a 8051 based controller to the MSP430F2417 controller.
In my code at 16Mhz, it takes approx 10 ms to execute.
And how do i change the code to make it run faster?
Thanks!
Depends on the time line, you may want to change to F5xx chip. The CPU is the same as F2417.
The peripherals in F2417 are also in F5xx, except some are improved and some new ones are added. There are more Flash and RAM. The max clock rate is faster. And the price is lower.
The cons for F5xx are: (a) F5xx parts are too new and (b) the tools may not be ready to take advantages of the new features.
The code you posted previously is a typical Multiply and Accumulate (MAC) operation commonly used in Digital Signal Processing (DSP).
F5xx has a 32-bit * 32-bit hardware multiply and accumulate peripheral (an improvement over the 16-bit * 16-bit one in F2417). But the current version of KickStart does not take advantage of it.
I have a few different F5xx parts. The max MCLK is only 18MHz, with 192-256 KB Flash and 16KB RAM. I will get some 25MHz parts as soon as they are available. I will try to develop a MAC subroutine for DSP application. I will write it in assembly but make it callable form c- for KickStart. When finished, I will post my results here, probably under a new subject. Hopefully, someone else will port that to CCE.
I do not have CCE. I use assembly most of the time. I got KickStart years ago (it does not limit code size in assembly). I already got used to its idiosyncrasies. Thus I have no motive to switch to CCE and endure the suffering of yet another set of idiosyncrasies.
As for F2417 and CCE, I think (but not sure) you can reduce the execution time to <1.5 msec by (a) pre-calculate sine and cosine functions of the 18 fixed values (b) put those results in your source code as const float SIN[18]={…}; const float COS[18]={…}; and (c) simplify the code in your loop and use the pre-calculated SIN[] and COS[]. This speed-up is not much of a gain, but there is not much of a pain in make this change.
Hi old_cow_yellow,
Thanks for the post!
I cannot change to the F5xx chip due to the cost factor. Actually i wanted to keep the cost to the minimum possible. Thats the reason i selected F2417.
I have already changed the code and put Sin and Cos value tables but still I am not able to achieve the required speed performance. I am sure we should be able reduce the execution speed by using the hardware multiplier for the floating point calculations but I do not know how to do it?
Do you have any idea on this?
And Thanks a lot for all the efforts you have decided to take for me!
Regards!
You said: "I cannot change to the F5xx chip due to the cost factor. " May I ask how much do you pay for F2417?
According to TI Web-site, the "Approx.Price" for F2417 is $7.60 while that for F5418 is $4.15. If you are a big volume user, you usually can get much lower actual price then the TI posted price.
You said: "I am sure we should be able reduce the execution speed by using the hardware multiplier for the floating-point calculations...”
I think KickStart already did that. Or, at least sort of did it.
I told you a while back that KickStart took ~6.7msec to execute your original code snippet and you told me that CCE toke ~10msec. I think the difference is KickStart uses (or sort of uses) the hardware multiplier. The improvement is about a 3:2 in speed.
It is certainly possible to make further improvements by re-writing the floating-point library. But I have no intention to go inside that Augean Stable. I rather use fixed point.
Did pre-calculating Sine and Cosine improve speed by 6:1?
old_cow_yellow said:You said: "I cannot change to the F5xx chip due to the cost factor. " May I ask how much do you pay for F2417?
According to TI Web-site, the "Approx.Price" for F2417 is $7.60 while that for F5418 is $4.15. If you are a big volume user, you usually can get much lower actual price then the TI posted price.
Hi,
I am sorry, I had not checked on the 5xx device prices. i had decided on this controller 3 months back. I guess this was the cheapest of the lot then!
I am not sure when these new 5xx devices were launched? was it recently? And why are these devices cheaper although they offer more processing power than 2xx?
Thanks!
old_cow_yellow said:You said: "I am sure we should be able reduce the execution speed by using the hardware multiplier for the floating-point calculations...”
Did pre-calculating Sine and Cosine improve speed by 6:1?
I am not sure kickstart did use HW multiplier? you can check in the assembly language code generated by the compiler? I think the FP calculatiom algorithm might be more efficient there!
Sine and Cos tables did improve the execution speed but I am still not able to achieve the required execution speed? May be I can do something else?
Thanks!
Mrt_Nsk said:I am sorry, I had not checked on the 5xx device prices. i had decided on this controller 3 months back. I guess this was the cheapest of the lot then!
I am not sure when these new 5xx devices were launched? was it recently? And why are these devices cheaper although they offer more processing power than 2xx?
Thanks!
TI has to compete with other uC companies. In stead of reducing prices of existing product, they introduce new products that are better and cheaper. F2xx are better and slightly cheaper than F1xx. F5xx are much better and much cheaper.
F5xx was introduced in Jun 08, http://focus.ti.com/pr/docs/preldetail.tsp?sectionId=594&prelId=sc08060
I got samples of silicon rev. L almost a month ago. Some of the new features in are not working yet.
Be aware that some third parties (other than IAR) are badmouthing F5xx. I question their motivation thou, they do not support F5xx. I only have KickStart and it has a few small bugs.
Can CCE simulate F5xx? Can you try it without getting the real chip? KickStart does and is free. (slac050t.zip)
Mrt_Nsk said:I am not sure kickstart did use HW multiplier? you can check in the assembly language code generated by the compiler? I think the FP calculatiom algorithm might be more efficient there!
Sine and Cos tables did improve the execution speed but I am still not able to achieve the required execution speed? May be I can do something else?
Yes, I did check the object code (I always do that when I use c-). KickStart did use the hardware multiplier to help speedup floating point calculation. It gained by ~ 3:2 ratio in doing so.
Did pre-calculate sine and cosine gain execution speedup your loop by ~ 6:1 ratio? Is it ~ 1.5msec now? What speed are you after?
If you decide to stay with F2417, I have other ways to speed it up. There are more than one way to skin a cat. But what kind of cat is it? Is the code snippet you have shown the real thing? What is the max number of MCLKs that is acceptable?
**Attention** This is a public forum