cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
3,172 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
Highlighted
Explorer
Explorer
3,167 Views
Registered: ‎11-24-2013

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
Highlighted
Advisor
Advisor
3,146 Views
Registered: ‎04-26-2015

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
Highlighted
Explorer
Explorer
3,129 Views
Registered: ‎05-31-2015

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