1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

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

Discussion in 'Embedded' started by janii, Nov 7, 2011.

  1. janii

    janii Guest

    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
     
    janii, Nov 7, 2011
    #1
    1. Advertising

  2. janii

    Thad Smith Guest

    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
     
    Thad Smith, Nov 9, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blukes
    Replies:
    1
    Views:
    351
    www.piaodown.com
    Aug 26, 2005
  2. Martin Maurer
    Replies:
    7
    Views:
    3,429
    divyasijo
    May 10, 2014
  3. jenny
    Replies:
    0
    Views:
    1,245
    jenny
    Apr 23, 2007
  4. techno guy

    Turning off sleep light?

    techno guy, Dec 1, 2006, in forum: Apple
    Replies:
    7
    Views:
    161
    Simon Slavin
    Dec 3, 2006
  5. Merwyn Welcome
    Replies:
    15
    Views:
    357
    David Empson
    Nov 29, 2007
Loading...

Share This Page