Pumpkin, Inc.

Pumpkin User Forums

Cyclic timers

Have an idea on how to make Salvo better? Post it here!

Re: Cyclic timers

Postby jtemples » Mon Feb 03, 2003 9:04 am

I wouldn't expect the timer's function to be called unless the timer rolled over on its own.

A function to read the timer might be useful, too.

jtemples
 
Posts: 45
Joined: Tue Jul 16, 2002 11:00 pm

Re: Cyclic timers

Postby aek » Mon Feb 03, 2003 9:12 am

OK, so I'm not clear on how OSResetCycTmr() should work ...

The timers are implemented as count-down timers. So let's say CycTmr 3 has a period of 30 ticks, and it last called its function 20 ticks ago. In another 10 ticks, it will call its function again. What effect does OSResetCycTmr() have on it now?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Cyclic timers

Postby jtemples » Mon Feb 03, 2003 9:41 am

Sorry, I didn't realize they were implemented as count-downs. In that case, OSResetCycTmr() would reset the timer to its original period; 30 ticks for the example of CycTmr3.
jtemples
 
Posts: 45
Joined: Tue Jul 16, 2002 11:00 pm

Re: Cyclic timers

Postby aek » Mon Feb 03, 2003 10:01 am

OK, so the API should include services to:

Create (with optional OSDONT_START_CYCTMR)
Start
Stop
Destroy (so the tcb is freed up)
Change Period
Reset

Am I right in assuming that you'd like Change Period and Reset to work on both running and stopped CycTmrs? On stopped CycTmrs it's trivial. On running ones, changing the period (so that it takes effect on the next "iteration") is also trivial. Resetting a running timer is a little more involved, because it has to be removed and the re-enqueued into the delay queue.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Cyclic timers

Postby jtemples » Mon Feb 03, 2003 10:18 am

I'd definitely want to be able to reset running timers, though it wouldn't be a big deal if I had to do a stop/reset/start to do this (or if Salvo did this on my behalf).

I think if I wanted to change the period, I'm most likely also going to reset it. Once the condition for a period change has been met, I wouldn't want the timer to pop one more time at whatever's left on its current period. So setting the period of a running timer in the mode you describe probably isn't that useful.

Another useful function would be a boolean that returns true if the timer is running.

jtemples
 
Posts: 45
Joined: Tue Jul 16, 2002 11:00 pm

Re: Cyclic timers

Postby luben » Thu Feb 13, 2003 2:06 am

Hello,

When talking about blinking LEDs, led share my current experience. I never had problems with blinking LEDs - with current SALVO services I could make 30 and more LEDs to blink, ligh and twinkle with any frequency.

The idea is extremely simple - I don't control the LED directly, but I use a variable that holds the pattern for ligh/blinking. The variable could be 1 or more bytes long, allowing to output complicated blinks. Here is example for controlling 9 independent LEDs.

code:

static word INDIC_LED1;
static word INDIC_LED2;
static word INDIC_LED3;
static word INDIC_LED4;
static word INDIC_LED5;
static word INDIC_LED6;
static word INDIC_LED7;
static word INDIC_LED8;
static word INDIC_LED9;

.....

void TASK_LEDS(void) // control of the LEDs
{
static word mask;

mask = 1; // initial value of the mask

while (1)
{
LED1 = (INDIC_LED1 & mask)? 1: 0;
LED2 = (INDIC_LED2 & mask)? 1: 0;
LED3 = (INDIC_LED3 & mask)? 1: 0;
LED4 = (INDIC_LED4 & mask)? 1: 0;
LED5 = (INDIC_LED5 & mask)? 1: 0;
LED6 = (INDIC_LED6 & mask)? 1: 0;
LED7 = (INDIC_LED7 & mask)? 1: 0;
LED8 = (INDIC_LED7 & mask)? 1: 0;
LED9 = (INDIC_LED7 & mask)? 1: 0;

mask <<= 1;
if (!mask) // was overrun the mask
mask = 1;

OS_Delay(time_for_resolution, LABEL);
}
}

...... and somewhere in other tasks you can use the following

INDIC_LED1 = 0; // LED1 will be dark
INDIC_LED2= 0xFFFF; // LED2 will light
INDIC_LED3= 0xFF00; // LED3 will blink slowly (50% duty)
INDIC_LED4= 0xF0F0; // LED4 will blink medium rate (50% duty)
INDIC_LED5= 0xAAAA; // LED5 will blink fast (50% duty)
INDIC_LED6= 0x5555; // LED6 will blink fast with oposite phase from LED5
INDIC_LED7= 0xA800; // LED7 will blink 3 times, then pause
INDIC_LED8= 0xFFFE; // LED8 will dark for short time
INDIC_LED9= 0x1; // LED9 will blink for short time, then long dark pause

....


}


So, in my oppinion to make new service to control the LEDs is sensless. The rate they use stays in 100ms - 1s time interval. The human eye can't tell small changes in the rate, usually we can't recognize complicated sequences like: 2 short blinks, one long blink, 1 short blink, pause .... At least I'm not good in Morse coding.

I use this approach from the beginning of using SALVO. I even used this approach in my "pre SALVO" period of programming, doing this task into ISR.

In SALVO I usually I put the LED control service into the task that scans keys with some prescaller. I scan the keys with 20ms delay, LEDs resolution is 100ms. Clear an dsimple. There is no limitation for the LEDs number - depend on the RAM of uP. I usually use 1 byte per LED, that brings smooth operation. 2 bytes much better resolution (then I use 50ms rate), but in more cases you need from the LEDs:
- light
- dark
- blinking 50% filled (slow and fast blinking)
- double blinking
- short light and short dark

All this could be easy obtained with the described approach.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Cyclic timers

Postby luben » Thu Feb 13, 2003 2:11 am

BTW,

I use the same approach when controlling the BUZZER - can make short and long beeps, etc. When making beeps the service should be little more complicate - it have synchronize the BUZZER with the variable. I mean, if you change the INDIC_BUZZER varuable while short beep is executed, this could result in shorten the beep time. This requires second variable for BUZZER, that's loaded every time the mask becomes zero. The BUZZER is controlled from this additional variable.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: Cyclic timers

Postby jtemples » Thu Feb 13, 2003 9:24 am

quote:
So, in my oppinion to make new service to control the LEDs is sensless.

Using cyclic timers for LEDs was just a trivial example. Here's a more realistic one (from an actual application with an RTOS that has cyclic timers):

1) An LCD with a RTC display that's updated once a minute
2) A seconds countdown timer on the LCD that's activated on-demand by the user
3) A popup date display on the LCD that disappears after five seconds when activated by the user

All of these situations were handled with cyclic timers that sent events to a single LCD event handling task. Having a single task was much cleaner and simpler than having lots of little tasks, each doing one small thing.

The actual task had more than a dozen timed events -- all of them asynchronous and not necessarily running at the same time.

[This message has been edited by jtemples (edited February 13, 2003).]

jtemples
 
Posts: 45
Joined: Tue Jul 16, 2002 11:00 pm

Re: Cyclic timers

Postby aek » Thu Feb 13, 2003 9:26 am

Here's one more reason for cyclic timers -- marketing. Unfortunate but true ...

Plus, I'm tending towards not limiting the number of cyclic timers in Salvo Lite. In effect, they're a freebie for those who want to use them ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Cyclic timers

Postby luben » Thu Feb 13, 2003 10:16 am

Hello,

quote:

1) An LCD with a RTC display that's updated once a minute
2) A seconds countdown timer on the LCD that's activated on-demand by the user
3) A popup date display on the LCD that disappears after five seconds when activated by the user

I can add more examples like:
- to close the door automatically when some time expired after transponder removed and sensor for door close is active
- to switch off the motor when they worked some times (car doors)
- to increase the speed of inc/dec when one key is pressed longer then some time
- to enter in special mode when one key is pressed longer then some time (thus protecting the mode from easy accidental entry)
- to protect second press of the key within some period after key is released
- to generate a single event when some process took longer/shorter then some time limit
-.... I can continue....

.... the ideas you mentioned and all these examples above are ALREADY MADE (not imagined) in my past projects using just simple variables and current functionality of SALVO. So, I agree that there is a need for such timers and I fekt their absense (well, I never figured out that they could be named like new class of SALVO functions). But there is too easy way to make them with simple variables, used like count up/down counters.

I really don't see the sense of such cyclic timers. For sure if they will be a part of SALVO they will work better. BTW everything that becomes a part of SALVO will work better after that and will be optimized - maybe from this view point I agree for adding of thses cyclic timers. And if this will not make SALVO slowlier and much biger - then I see real sense.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

PreviousNext

Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 3 guests

cron