Implementation of virtual timers

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

Sandeep
Posts: 3
Joined: Wed Sep 13, 2017 2:13 pm

Implementation of virtual timers

Postby Sandeep » Thu Dec 28, 2017 3:03 pm

I 'm having trouble in generating the delay at correct time using virtual timers.

if (LED1== ON)
{
led2ON();
chSysLockFromIsr();
if (chVTIsArmedI(&close_pulse_timer))
chVTResetI(&close_pulse_timer);
chVTSetI(&close_pulse_timer, MS2ST(2000), led2OFF, NULL); // TURNS OFF LED2 AFTER 2 SECONDS.
chSysUnlockFromIsr();
}

This is my function, I'm suposed to turn 2nd LED ON for 2 seconds when 1st led is ON.
But with this code the call back function is called after the 1st LED turned OFF.
I would like to call the callback function to turnOff 2nd led when 1st Led is ON.

Can you please correct me if I'm going wrong some where?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Implementation of virtual timers

Postby Giovanni » Thu Dec 28, 2017 3:08 pm

Hi,

Probably the problem is in the code you are not showing. This is only about LED2.

Giovanni

Sandeep
Posts: 3
Joined: Wed Sep 13, 2017 2:13 pm

Re: Implementation of virtual timers

Postby Sandeep » Thu Dec 28, 2017 3:19 pm

// timer to turn off Breaker close command
static VirtualTimer close_pulse_timer;

//prototype
static void led2Off(void *arg);


// virtual timer callback to turn off close command
static void led2Off(void *arg)
{
(void)arg;;
ledOff(2);
}


//
//*************
//
void function(void)
{
if (led1== ON)
{
ledOn(2);
chSysLockFromIsr();
if (chVTIsArmedI(&close_pulse_timer))
chVTResetI(&close_pulse_timer);
chVTSetI(&close_pulse_timer, MS2ST(2000), led20ff, NULL);
chSysUnlockFromIsr();
}
}

This is m,y whole code, I'm getting the delay of 2 seconds for LED 2, but thats happening only if the LED1 is turned OFF.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Implementation of virtual timers

Postby Giovanni » Thu Dec 28, 2017 3:33 pm

You added nothing, he problem is not with virtual timers, you get the 2 seconds for LED2.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 19 guests