Etantonio Electronic
Welcome to the forum.
Username:
Password:
Save Password


Register
Select Language

Forgot your Password?
 
Active Topics | Active Polls | Members | Online Users | Avatar Legend | Search
Select Skin: 
 All Forums
 Telecommunications
 Sensor Networks
 Blink modified for 2 timers not working
Rating is not allowed for this topic.
 New Topic | New Poll New Poll |  Reply to Topic | Bookmark this Topic Bookmark Topic |  Printer Friendly
Author  Topic Next Topic: External ADC for Mica2Dot  

etantonio

Status: offline

 Posted - 11/26/2005 :  21:26:32  Show Profile  Visit etantonio's Homepage  Add etantonio to Buddylist  Reply with Quote
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

Why not ?!?

 Country: Italy  ~  Posts: 26  ~  Member Since: 10/21/2005  ~  Last Visit: 11/17/2008 Alert Moderator 

Ian

Status: offline

 Posted - 11/26/2005 :  21:39:31  Show Profile  Add Ian to Buddylist  Reply with Quote
>
> 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!

 Country: Mexico  ~  Posts: 3  ~  Member Since: 11/26/2005  ~  Last Visit: 11/26/2005 Alert Moderator  Go To Top Of Page

cory

Status: offline

 Posted - 11/26/2005 :  21:44:50  Show Profile  Add cory to Buddylist  Reply with Quote
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

 Country: USA  ~  Posts: 1  ~  Member Since: 11/26/2005  ~  Last Visit: 11/28/2005 Alert Moderator  Go To Top Of Page
   Topic Next Topic: External ADC for Mica2Dot  
 New Topic | New Poll New Poll |  Reply to Topic | Bookmark this Topic Bookmark Topic |  Printer Friendly
Jump To:
 Image Forums 2001 This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000