/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Timer for Primer2??

Username:     
Password:     
             

Forum

# 1   2009-08-21 13:42:20 Timer for Primer2??

Tom
New member
Registered: 2009-07-14
Posts: 6

Timer for Primer2??

hello,
i am currently trying to get along with my primer2.
now my problem is that i cant find any functions concerning timers or delays.
i need a function which waits for a certain time like for example DelayMs(100) or something like that.
does something like this already exist or how could i implement this??
thanks for any help.
greets tom

Offline

 

# 2   2009-08-24 08:39:32 Timer for Primer2??

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Timer for Primer2??

The RTC counts only seconds. If your application is based on CircleOS, you have to count by yourself the calls made to your handler, but the tick depends on the CPU clock (speed) settings, that can be modifed in the Configure menu... If you need to fix it, you can, in your application, force the speed.

Offline

 

# 3   2009-08-24 08:49:42 Timer for Primer2??

Tom
New member
Registered: 2009-07-14
Posts: 6

Re: Timer for Primer2??

i know the function of the rtc, but seconds are too long for my app.
i just need some µs or ms. so how can i realize such delays?
i cant find any functions concerning timer, systick or anything else.
please help.

Offline

 

# 4   2009-08-25 06:16:51 Timer for Primer2??

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Timer for Primer2??

For some µs, you need to setup your own timer. For ms, if you are within a CircleOS application, you can just count for some dummy calls at the entry of your handler (that is called by the systick interrupt). For example:

enum MENU_code Application_Handler ( void )
   {
   if (my_delay--) return MENU_CONTINUE;

   ... your_handler..
   }

Offline

 

# 5   2009-08-25 06:53:27 Timer for Primer2??

Tom
New member
Registered: 2009-07-14
Posts: 6

Re: Timer for Primer2??

okay but how can i wait for a fixed time with this code example?
where must the value of the millisecondes be entered?

Offline

 

# 6   2009-08-25 16:21:01 Timer for Primer2??

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Timer for Primer2??

You have to initialize 'my_delay' somewhere. The handler is called by the systick (I don't remember the frequency, but you also have to make it fixed because it could depends on the CPU speed). 
Example of handler:

Code:

enum MENU_code Application_Handler ( void )
   {
   if (my_delay--) return MENU_CONTINUE;

   ... 
   if ( need_delay() )
       {
        my_delay = 25;
        return MENU_CONTINUE;
       }
   else 
       {
        action();
      }   
    return MENU_CONTINUE;
   }

Offline

 

# 7   2009-08-27 03:42:47 Timer for Primer2??

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Re: Timer for Primer2??

Can/'t you do something like this?

Code:

volatile int runFLAG = 0;

enum MENU_code Application_Ini(void)
{
//set a timer for needed delay to fire and set runFlag to 1
}

enum MENU_code Application_Handler ( void )
{
if (runFLAG==0) return MENU_CONTINUE;
...
}

I'll be working soon on making this much easier and be done by the OS.

Offline

 

Board footer