Etantonio Electronic
Welcome to the forum.
 
Active Topics | Active Polls | Members | Online Users | Avatar Legend | Search
Select Skin: 
 All Forums
 Telecommunications
 Sensor Networks
 Blink modified for 2 timers not working

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Message Icon:                
               
Message:

Smilies
Angry [:(!] Approve [^] Big Smile [:D] Black Eye [B)]
Blush [:I] Clown [:o)] Cool [8D] Dead [xx(]
Disapprove [V] Duh! [Duh!] Eight Ball [8] Evil [}:)]
Kisses [:X] No [No] OK [OK] Oops! [Oops!]
Question [?] Sad [:(] Shock [:O] Shy [8)]
Sigh... [Sigh...] Sleepy [|)] Smile [:)] Tongue [:P]
Ugh [Ugh] Wink [;)] Wow! [Wow!] Yeah! [Yeah!]
Yes! [Yes!]      

   * HTML is ON | * Forum Code is OFF
 
 
   

T O P I C      R E V I E W
etantonio Posted - 11/26/2005 : 21:26:32
Hi all,
I'm trying to understand a little bit more about tinyos so I decide to modify Blink in a way that the green led blinks with a timer of 500ms and the red led blinks with a timer of 800ms, to do this I rerrange Blink in a way to use no more SingleTimer but TimerC, here it is the modified code for BLINKC :

//////////////////////////////////////////
configuration Blink {

}

implementation {

components Main, BlinkM, TimerC as Time1, TimerC as Time2, LedsC;

Main.StdControl -> Time1.StdControl;

Main.StdControl -> Time2.StdControl;

Main.StdControl -> BlinkM.StdControl;

BlinkM.Timer1 -> Time1.Timer[unique("Timer")];

BlinkM.Timer2 -> Time2.Timer[unique("Timer")];

BlinkM.Leds -> LedsC;

}

//////////////////////////////////////////




while this is the modified code for BlinkM :

//////////////////////////////////////////
module BlinkM {

provides {

interface StdControl;

}

uses {

interface Timer as Timer1;

interface Timer as Timer2;

interface Leds;

}

}

implementation {

command result_t StdControl.init() {

call Leds.init();

return SUCCESS;

}

command result_t StdControl.start() {

call Leds.redOff();

call Leds.yellowOff();

return call Timer1.start(TIMER_REPEAT, 500);

return call Timer2.start(TIMER_REPEAT, 800);

}

command result_t StdControl.stop() {

return call Timer1.stop();

return call Timer2.stop();

}

event result_t Timer1.fired()

{

call Leds.greenToggle();

return SUCCESS;

}

event result_t Timer2.fired()

{

call Leds.redToggle();

return SUCCESS;

}

}

//////////////////////////////////////////


The problem is that only the green led associated to Timer1 toggles, what happens?? How can I solve this problem??

Many thanks ...

Eng. Antonio D'Ottavio
2   L A T E S T      R E P L I E S    (Newest First)
cory Posted - 11/26/2005 : 21:44:50
Antonio, Lin is correct. Also, to clarify another point, in your
configuration you only need to reference TimerC once, like this

components Main, BlinkM, TimerC, LedsC;
Main.StdControl -> TimerC.StdControl;
Main.StdControl -> TimerC.StdControl;
Main.StdControl -> BlinkM.StdControl;
BlinkM.Timer1 -> TimerC.Timer[unique("Timer")];
BlinkM.Timer2 -> TimerC.Timer[unique("Timer")];
BlinkM.Leds -> LedsC;

Using the "as" keyword in a components specification doesn't create a
new timer or anything, it only renames the existing component for the
purpose of that configuration block. All references to TimerC
(aliased with "as" or not) refer to precisely the same component,
component implementation code, and component member variable frame.

The TimerC component is designed and written explicitly to manage
multiple timers, one for each unqiue("Timer") in the application.
This is a concept that takes some getting use to: all components in
nesC are "static". Components only provide a form of "instantiation"
when they are explicitly written to use the unique and uniqueCount
keywords, like TimerC.

Hope that help,
Cory
Ian Posted - 11/26/2005 : 21:39:31
>
> command result_t StdControl.start() {
>
> call Leds.redOff();
>
> call Leds.yellowOff();
>
> return call Timer1.start(TIMER_REPEAT, 500);


The command returns here so the code for start Timer2
is not executed.

>
> return call Timer2.start(TIMER_REPEAT, 800);
>
> }
>

Have fun!

 Image Forums 2001 This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000