Skip to main content
samiassaad
Associate III
March 14, 2011
Question

While problem

  • March 14, 2011
  • 13 replies
  • 1691 views
Posted on March 14, 2011 at 19:53

While problem

    This topic has been closed for replies.

    13 replies

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

    I use keil uv4

    I declared it like this :

    unsigned int delay_main;

    thank you

    greg_t
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:27

    Is the variable delay_main is of volatile type ?

    __IO uint32_t delay_main;

    samiassaad
    Associate III
    May 17, 2011
    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 ?

    Tesla DeLorean
    Guru
    May 17, 2011
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    samiassaad
    Associate III
    May 17, 2011
    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

    samiassaad
    Associate III
    May 17, 2011
    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

    Tesla DeLorean
    Guru
    May 17, 2011
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 17, 2011
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    samiassaad
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:27

    Thank you

    my problem is this 

    if(SysTick_Config(SystemCoreClock / 1000) )   // 1ms interrupts

    now I get every 1ms an interupt;

    in the system tick handle I increment

    main_delay++;

    then in the main routine I check

    while(main_delay<3000); this should wait 3 sec

    but it wait about  10 sec .

    what could be the problem ?

    again thank you clive

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:27

    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.

     

    X = 200, You asked the value of X

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

    or

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

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..