cancel
Showing results for 
Search instead for 
Did you mean: 

While problem

samiassaad
Associate II
Posted on March 14, 2011 at 19:53

While problem

13 REPLIES 13
greg_t
Associate II
Posted on May 17, 2011 at 14:27

Is the variable delay_main is of volatile type ?

__IO uint32_t delay_main;

samiassaad
Associate II
Posted on May 17, 2011 at 14:27

I use keil uv4

I declared it like this :

unsigned int delay_main;

thank you

Posted on May 17, 2011 at 14:27

do I miss something here ?

Define it as volatile so the compiler doesn't optimize it to an infinite loop. ie it changes outside the context of the current routine.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
samiassaad
Associate II
Posted on May 17, 2011 at 14:27

Thank you

is not unsigned int a volatile ? since I define it  under the include headers directly .

where can I fine the type of definisions for keil for the new lib 3.4 ?

Posted on May 17, 2011 at 14:27

is not unsigned int a volatile ? since I define it  under the include headers directly .

No, being external or publically defined is not the same as being volatile, which infers that it might change between different reads. Like a hardware register, or interrupt incremented counter.

volatile unsigned int delay_main;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
samiassaad
Associate II
Posted on May 17, 2011 at 14:27

Thank you it is solved , so is not better to define all variables as volatile ?

what is the diffrent between static and volatile  in this case ?

Thank you all in advance

Regards

samiassaad
Associate II
Posted on May 17, 2011 at 14:27

sorry I am back with new question , exuce me I am new to cortex m3 and STM

my system coreclock is 72Mhz , I want the system tike inturrept every 5ms

so how can I calculate this what is the formula?

what is the relation between tick and ms?

if(SysTick_Config(SystemCoreClock / x) )   // 5ms interrupts

x=?  the formula please .

Thank you

Posted on May 17, 2011 at 14:27

what is the relation between tick and ms? what is the diffrent between static and volatile  in this case ?

 

1/1000 th of a second is 1ms, x = 1000

5ms period is 1000/5 thus x = 200, ie 5/1000 th of a second or 1/200 th of a second.

Measured in 72 MHz cycles, where 72000000 cycles per second 72000 cycles per millisecond, and 360000 cycles per 5 milliseconds.

A static is invisible outside the current object file. You should use volatile if the value changes independent of program flow.  ie in an interrupt. If you call a subroutine it is assumed variables will change. You could also turn off optimization, and then the compiler wouldn't hold variables in registers, or reduce loops.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
samiassaad
Associate II
Posted on May 17, 2011 at 14:27

Thank you alot Clive 

if(SysTick_Config(SystemCoreClock / 360000) )   // 5ms interrupts

returns an error that cant load it ; any solution for 5ms interrupt? I am using the new library 3.4.

Regards