Motherboard Forums


Reply
Thread Tools Display Modes

How to improve turning ON light for set amout of time.

 
 
janii
Guest
Posts: n/a
 
      11-07-2011, 11:37 PM
Our embedded target board needs to support delayed/egress lighting. If th
target board is sleeping, the wakeup switch input (when "closed") will b
used to wake up the target board and turn ON the light. Once ON, th
light would stay ON until either the switch input "opens" OR a 2 minut
timer expires.

This will have to function via the wakeup switch input, as well as when th
target board is powered up via the traditional means.

Please see Code below. The function I wrote below will be called ever
40ms.
How can it be improved?

When switch is "closed", light will turn ON and then may turn OFF. Is i
possible to do one or the other in "if' body.

When switch is "open", timer will reset and light will turn OFF. Doin
this every 40ms seems to be waste of CPU.


Thank you!




void light_update(void)
{
static unsigned on_timer = 3000;

/* Is switch closed? */
if ( closed )
{
/* Turn ON light */
output = 1;

if (on_timer != 0)
{
on_timer--;
}
else
{
/* Turn OFF light */
output = 0;
}
}

else
{
/* Reset Timer */
on_timer = 3000;

/* Turn OFF light */
output = 0;
}

}



task(40ms)
{
light_update();
}


---------------------------------------
Posted through http://www.EmbeddedRelated.com
 
Reply With Quote
 
 
 
 
Thad Smith
Guest
Posts: n/a
 
      11-09-2011, 12:50 AM
On 11/7/2011 4:37 PM, janii wrote:
> Our embedded target board needs to support delayed/egress lighting. If the
> target board is sleeping, the wakeup switch input (when "closed") will be
> used to wake up the target board and turn ON the light. Once ON, the
> light would stay ON until either the switch input "opens" OR a 2 minute
> timer expires.
>
> This will have to function via the wakeup switch input, as well as when the
> target board is powered up via the traditional means.
>
> Please see Code below. The function I wrote below will be called every
> 40ms.
> How can it be improved?
>
> When switch is "closed", light will turn ON and then may turn OFF. Is it
> possible to do one or the other in "if' body.
>
> When switch is "open", timer will reset and light will turn OFF. Doing
> this every 40ms seems to be waste of CPU.


Yes, it is doing unneeded processing, but that probably doesn't matter. I
suspect that is true of your application.

If you want to minimize the processing, use event-driven processing. Interrupt
on switch changes. When you need to service something after a given amount of
time, generate a timer interrupt when you need to do work. Sleep otherwise.

That said, most interrupt-based delays of long intervals will require counting
shorter interrupt intervals.

Thad
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
first set of SATA working fine, second set broken? MSI 875P-Neo FIS2R clock3d MSI 0 08-11-2007 02:20 AM
Edlite Slim Light Box/ / Edlite Ultra slim light box jenny Soyo 0 04-23-2007 09:25 AM
Turning off sleep light? techno guy Apple 7 12-03-2006 08:24 PM
screen is turning the white areas light blue randomly blukes ATI 1 08-26-2005 07:16 PM
Switch between ARM instruction set <-> Thumb instruction set Martin Maurer Embedded 6 09-05-2003 11:10 PM


All times are GMT. The time now is 03:15 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment