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?
Implementation of virtual timers
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- 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
Hi,
Probably the problem is in the code you are not showing. This is only about LED2.
Giovanni
Probably the problem is in the code you are not showing. This is only about LED2.
Giovanni
Re: Implementation of virtual timers
// 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.
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.
- 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
You added nothing, he problem is not with virtual timers, you get the 2 seconds for LED2.
Giovanni
Giovanni
Who is online
Users browsing this forum: No registered users and 19 guests