- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a NIOS-1 design that I am having some trouble with. My tools are a bit dated, because I had to use NIOS-1 (because of the older FPGA on the board that I was forced to ue) -- So I am using SOPC builder 2.7 on Quartus 4.1 My problems are so silly that I am sure it is a reflection of my errors, and not the compiler itself. Anyway, Here is my problem.. I have an ISR that runs a PID loop for controlling a motor. The P,I,D and Total_output values are global floating point var’s that are updated in the ISR (run by a timer at 20 loops per second) . I print the value of the terms in the “foreground” – in a big while(1) loop that runs my rs-232 based command parser. I initially set all 4 values to zero in main(), before the ISR starts to run. If I print the values in the command parser I get a result that looks like “P=0 I=0 D=0 Total_output=NaN” What is this “NaN”? -- in addition, I have a command that I can execute that assigned all 4 vars to zero in the command parser, and then things start to work.. My question is why? Is there some issue that is causing the compiler to not assign the values to zero in main()? I have added the zero-assignments to other sections of the code as well, and none work, until I hit the one in the command parser.. Also, I am using nios-build to compile my code. Is there any way to change the optimization level with a command line arg to nios-build? Thank you, ---Lou lou@faustini.com ps: a bit more info... I am using the nios-1 EVB, booting from flash, and running out of ram.Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
NaN is for Not a Number. It seems like you might have a memory corruption, like something is setting the Total_output value to something other than zero between the time you initialized the value and tried to print the value.
If you happen to have an FS/2 black box, you could set a trigger to go off when the memory location of Total_output is written. This could indicate what code is overwriting your value.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To change the optimization level using something like this (type nios-build --help in case I messed up this line).
nios-build --base=<base address> -O<optimization level> -o<output file name> -O0 is no optimization -O3 is maximum optimization -Os is a size optimization (which often turns into a speed optimization as a bonus). Like I said I would check the help first since I haven't compiled for Nios I in a while.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
OK, now is there a way to "see" where the compiler put the initialization values for global vars? I am wondering if something is getting messed up in the run-time initialization code. Something to keep in mind is that all integers seem to come up correctly.. I am using version 2.7 of the SDK, and I used SOPC builder to put RAM at 0x2 0000 and flash at 0x10 0000. I have NOT passed any special arguments to nios-build, I do pass the argument --ram_address=0x20000 to the srec2flash utility. Have I missed something? Tank you. ---Lou- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, NaN is short for "not a number", but I doubt it's occuring because of memory corruption. The string "NaN" is how the standard library formats this special floating point value, which is used to represent the outcome of a floating point calculation when the result is "not a number", such as when dividing by zero. This not a number result propagates: the result of any further floating point calculations involving NaN as an input is also NaN.
You've probably got a division by zero somewhere in your floating point expressions.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, the NaN will be printed if the value being read is all 1's except the most significant bit. Also, since setting the four globals to zero causes the code to work after initialization. It could still be a memory corruption issue at startup. However, scs is right it is likely that there is some other variable that is initially set to a value that causes an operation to divide 0 by 0. (If you divide non-zero by 0 you actually get infinity.) So if there are other initial conditions, you should check those first.
Another test you could perform to isolate the problem is to set the values to 1 initially. If scs is correct, then the display should change from NaN to infinity (I don't remember the string for infinity). This should help you isolate the problem. Just for reference, below are the defines for the floating point value checks: # define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && ((*(long *)&(x) & 0x007fffffL)!=0000000000L)) # define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && ((*(long *)&(x) & 0x007fffffL)==0000000000L)) # define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page