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
2,899 Views
Registered: ‎05-31-2015

variable in microblaze C code unexpected behaviour

Hello,

 

      I am using spartan 6 FPGA with microblaze. Microblaze is running C code. In C code  have written a for loop incrementing variable i from 0 to 26363. After executing the code I find that the statements after for loop is executed , but the for loop has executed incrementing variable from 0 to some smaller value only. Sometimes i is 63,sometimes 173 ...like that. But the program is not halted or stuck there since following instructions are executed. The variable i is not updated anywhere else. I have assured that. The issue is i increments from 0 to some smaller value, when I want it to increment from 0 to 26363.

 

Any suggestions to improve this.

 

Thanks in advance.

 

With Regards

Shalini

0 Kudos
3 Replies
Explorer
Explorer
2,894 Views
Registered: ‎11-24-2013

Re: variable in microblaze C code unexpected behaviour

Hello,

 

maybe the compiler is trying to optimize the code in a way that is causing this behavior. Have you tried declaring the variable as volatile? Example:

 

volatile int i;

 

Regards,

Ignacio

Tags (2)
0 Kudos
Scholar u4223374
Scholar
2,873 Views
Registered: ‎04-26-2015

Re: variable in microblaze C code unexpected behaviour

Can you post the code?

 

The obvious explanation for a function leaving a loop early is that you've got something in teh loop telling it to leave early - either a break or a goto statement. If the loop contains function calls then it's also possible to mess up the stack badly enough that it'll return to somewhere outside of the loop - especially on something like Microblaze where there's not a whole lot of memory protection.

0 Kudos
Explorer
Explorer
2,856 Views
Registered: ‎05-31-2015

Re: variable in microblaze C code unexpected behaviour

Hello,

 

   The problem was solved when I disabled my timer interrupt. May be the timer interrupt may have interrupted the loop. But I have no idea how the loop got stuck.  

 

   I tried volatile and tried with small numbers for stack overflow. But the issue was this. Thanks for suggestions.

 

With Regards

Shalini

0 Kudos