Implementation of virtual timers

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

Moderators: RoccoMarco, lbednarz, tfAteba

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

Implementation of virtual timers

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Implementation of virtual timers

Post by Giovanni »

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

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Implementation of virtual timers

Post by Giovanni »

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

Giovanni
Post Reply