UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
5,143 Views
Registered: ‎05-21-2009

PowerPC 440 float divison problem

Jump to solution

Hi.

 

I don't know if this is an SDK issue or PowerPC issue, so I'm posting it here.

 

I wrote some code in SDK for PID control. To test this control, I'm running it on the SDK by using the hardware debugger and stepping through the code.

 

The problem is I can't step past the line marked "Problem Line" (T = 1.0/fs). Initially I got a window saying "Source not found", but after changing a bunch of stuff, I'm not even getting that window again. Now the program suspends at that line, and if I step again I get the error: "Single stepping until exit from function _start, which has no line number information." Even if I step numerous times, the SDK never steps past that line.

 

Anyone have any ideas what is going on? Did I do something wrong in the SDK? Should I add anything to use floats? I thought the issue was I had no FPU, but the problem stayed the same after adding the FPU. Did I maybe add it wrong?

 

Any help will be appreciated.

 

Thanks

 

 

// #Includes #include "method_1.h" #include "method_2.h" #include "method_3.h" #include <math.h> //#include "stdio.h" //#include "float.h" // Defines #define METHOD (1,2,3) // Constants float fs = 20000.0 ; // Sampling frequency // PID parameters int Kp = 20000 ; // Proportional gain int Ki = 3 ; // Integraton constant int Kd = 38 ; // Differential constant // PID control variables long a0 = 0 ; long a1 = 0 ; long a2 = 0 ; long b1 = -1 ; long b2 = 0 ; float a0_f = 0; float a1_f = 0; float a2_f = 0; // Other variables float T ; // Sampling period // Edit: changed from "int T" int x = 0 ; // PID input value int y = 0 ; // PID output value // Arrays long m[3] = {0} ; // Array to store intermediate values // Counter declaration int k = 0 ; // Memory pointers volatile signed int *mem_pter = 0x0; unsigned int mem_counter = 0x0; signed int readpointer = 0 ; signed long writepointer = 0 ; // Function declarations long method_func1(signed int x, long *m, long b1, long b2, long a0, long a1, long a2) ; int main() { // Initialization T = 1.0/fs ; // <========== Problem line ==============

a0_f = Kp + (Ki*T/2) + (Kd/T) ; // a0 = 780000 a1_f = -Kp + (Ki*T/2) + (2*Kd/T) ; // a1 = -1540000 a2_f = Kd/T ; // a2 = 760000 a0 = (long)a0_f; a1 = (long)a1_f; a2 = (long)a2_f; for (mem_counter = 0x11000000 ; mem_counter <= 0x11001000 ; mem_counter += 4) { mem_pter = (unsigned int*) mem_counter ; readpointer = 0 - *mem_pter ; writepointer = method_func1(readpointer, m, b1, b2, a0, a1, a2) ; //method_func2(Kp, Kd, Ki, fs) ; printf("%ld\n",writepointer) ; } return 0; }

 

 

Message Edited by rikusleroux on 07-13-2009 01:52 AM
Message Edited by rikusleroux on 07-15-2009 07:55 AM
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Explorer
Explorer
6,360 Views
Registered: ‎05-21-2009

Re: PowerPC 440 float divison problem

Jump to solution

Hi JM.

 

Thanks for your reply, but thats not the problem. I made a slight copy and past error, my bad... The code I was using at this stage (as given in my other post, http://forums.xilinx.com/xlnx/board/message?board.id=EDK&message.id=9873#M9873) had T as a float, but Kp, Ki and Kd wasn't. But since the SDK wouldn't even step past the T = 1.0/20000.0 line, this wasn't the problem. Thanks for pointing it out, though. This was fixed in the mean time.

 

After much struggeling, I (kind of) solved this problem, but I am unsure on why this happens. I've upgraded to SDK 11.1 and the code works fine if I just run the code instead of stepping through it. Every once in a while the compiler still crashes, but after a few retries, it manages to run through the code perfectly. In SDK 10.1, I couldn't even step past the troublesome line, where SDK 11.1 is actually able to step past that line and I could see the division working.

 

 

Message Edited by rikusleroux on 07-15-2009 07:56 AM
Message Edited by rikusleroux on 07-15-2009 08:43 AM
0 Kudos
3 Replies
Explorer
Explorer
5,120 Views
Registered: ‎05-21-2009

Re: PowerPC 440 float divison problem

Jump to solution

I tracked this error down to the SDK. Rubbish SDK 10.1. I've downloaded the trail version of 11.1, but it is still not that much better.

 

I can't believe no-one experienced this error before.

0 Kudos
Contributor
Contributor
5,117 Views
Registered: ‎02-27-2008

Re: PowerPC 440 float divison problem

Jump to solution
1.0/2000.0 cast to T which is an "int" gives 0.

On the next line, Kd/T is a division by 0. If it is not the problem, it will be.
So:
1) protect the division
2) change the types of T, Kp, Ki and Ki to "float".

Cordialement
0 Kudos
Explorer
Explorer
6,361 Views
Registered: ‎05-21-2009

Re: PowerPC 440 float divison problem

Jump to solution

Hi JM.

 

Thanks for your reply, but thats not the problem. I made a slight copy and past error, my bad... The code I was using at this stage (as given in my other post, http://forums.xilinx.com/xlnx/board/message?board.id=EDK&message.id=9873#M9873) had T as a float, but Kp, Ki and Kd wasn't. But since the SDK wouldn't even step past the T = 1.0/20000.0 line, this wasn't the problem. Thanks for pointing it out, though. This was fixed in the mean time.

 

After much struggeling, I (kind of) solved this problem, but I am unsure on why this happens. I've upgraded to SDK 11.1 and the code works fine if I just run the code instead of stepping through it. Every once in a while the compiler still crashes, but after a few retries, it manages to run through the code perfectly. In SDK 10.1, I couldn't even step past the troublesome line, where SDK 11.1 is actually able to step past that line and I could see the division working.

 

 

Message Edited by rikusleroux on 07-15-2009 07:56 AM
Message Edited by rikusleroux on 07-15-2009 08:43 AM
0 Kudos