Thanks for the responses.

Whilst I was waiting I fiddled a bit more and it turned out that the problem
was to do with not waiting for the timer to fully execute.  So basically
executing the timer 3 times consecutively gave the net effect of just one
timer execution. 

To solve the problem, I slowed the timer down, as well as started using the
TIMER_REPEAT option instead.  Now I have a counter that stops the timer when
I have reached the number of flashes I require - for example:

  event result_t yellowTimer.fired()  {
    flashCount++;
    call Leds.yellowToggle();
    if (flashCount == currentDestination * 2)  {
      call yellowTimer.stop();
      }    
    return SUCCESS;
    }

Not elegant, but it works!  Its horrible to get stuck on such a mundane
task, but I guess the up side is that I know not to rely on timers too much,
and in particular, take care with their execution.

Thanks for all the help (Jacob, Andrea and Hannes), it was much appreciated.

Alex.



________________________________________
From: Jacob Sorber [mailto:[EMAIL PROTECTED] 
Sent: 21 November 2005 16:37
To: [EMAIL PROTECTED]
Cc: [email protected]
Subject: Re: [Tinyos-help] Quick question about tasks

Alex,

There is a limit to the number of tasks you can post (see
tos/platform/sched.c), but I don't think that is your problem.  My guess is
that your problem is how things are being interleaved.  I think you want it
to run like this.

led on
set timer (25ms)
timer fired
led off
set timer (25ms)
timer fired
led on
...etc

what is probably happening is this

ledon
set timer (25ms)
ledon
set timer (25ms) //this writes over the last timer.
ledon
...etc

Instead you should wait until the timer fires before posting the next task. 
Also, make sure you wait after turning it on and after turning it off.  You
might also want to make your timer a little longer while debugging. 
Flashing at 40Hz is getting pretty close to being imperceptible  (and you
might not be able to tell how many times if flashed).

If you insist on doing it in a for loop, you could use TOSH_uwait, but
nothing else will be able to execute while you are waiting.

Hope this helps,


Jacob Sorber

Computer Science Department
University of Massachusetts, Amherst

On 11/21/05, Alex Mason <[EMAIL PROTECTED]> wrote:
Hi,

Probably a very simple question (as usual!) but I can't seem to find an
understandable answer.

I was creating a small demo with my motes to show radio comms receiving,
performing a task and then acknowledging completion.  In doing this, I 
wanted to flash the Leds quickly in succession.  So, I created a task to do
this - for example:

  task void flashGreen()  {
    call Leds.greenOn();
    call greenTimer.start(TIMER_ONE_SHOT, 25);
    } 

...

  event result_t greenTimer.fired()  {
    call Leds.greenOff();
    return SUCCESS;
    }

Then, I can just use "post flashGreen" to flash the Led.  However, the
problem I have is that I want to flash the Led 'n' number of times so I 
tried:

for (i = 0; i < n; i++)  {
  post flashGreen;
  }

However, this just flashes the Led once, regardless of the value of 'n'.  I
have the feeling the problem is because of the task being posted too many 
times in quick succession - but on the other hand I was under the impression
that tasks are processed FIFO, so I'm a little confused.  Of course, this
isn't a major problem (I don't need the Leds to flash in practice) but it 
would be nice to know what is causing the problem for future reference.  I
have tried atomic execution also, but this made no difference (unless I am
using it incorrectly).

Cheers,


----------
Alex Mason
Postgraduate Research
RFID & Wireless Sensor Networks
Liverpool John Moores University

Email: [EMAIL PROTECTED]
Phone: +447886389484

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help



_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to