Page 1 of 1

Implementation of virtual timers

Posted: Thu Dec 28, 2017 3:03 pm
by Sandeep
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?

Re: Implementation of virtual timers

Posted: Thu Dec 28, 2017 3:08 pm
by Giovanni
Hi,

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

Giovanni

Re: Implementation of virtual timers

Posted: Thu Dec 28, 2017 3:19 pm
by Sandeep
// 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.

Re: Implementation of virtual timers

Posted: Thu Dec 28, 2017 3:33 pm
by Giovanni
You added nothing, he problem is not with virtual timers, you get the 2 seconds for LED2.

Giovanni