1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Delay function

Discussion in 'Arduino' started by rascupanamuha, Apr 1, 2014.

  1. rascupanamuha

    rascupanamuha Member

    Joined:
    Nov 4, 2012
    Messages:
    169
    Likes:
    0
    I have a small problem and i dont know hot to solve it (and is it even possible)

    *I want to update my 20x4 lcd every 500ms
    *I want to send different PWM signal to motor every 1ms or faster (very important)
    *I want to recognize key press at any time (keys are not connected to the interrupt), or every 1ms with debounce delay of 20ms

    For now everything is working with just one 200ms delay, but screen is refreshing too fast and motor recieve information too slow

    How can i get it working in the way i want, please help me :)
     
  2. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,369
    Likes:
    974
    Location:
    Loveland, CO USA
    don't update the entire LCD every pass. Update just one line, or one variable.
    OR
    Update part of the LCD every 5 passes.
    OR
    Update only one character of the display every 1mS.
    OR
    Set a timer to interrupt every 1mS.
    >survive the motor and key and (return form interrupt).
    In the background do the LCD.
     
  3. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    Run the timer interrupt to satify the fastest pace, say every 1ms. Inside the interrupt, use several counters. Say, for the display, count from 500 to zero. When it goes to zero, set a flag for the display update and set the counter back to 500.

    In the main loop, test the flag. Once you see it set, update the display and clear the flag. Do the same with other devices.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. rascupanamuha

    rascupanamuha Member

    Joined:
    Nov 4, 2012
    Messages:
    169
    Likes:
    0

    Thank you, i used millis() timer and now everything is working like i wanted :)
     
  6. dreamtale

    dreamtale New Member

    Joined:
    Oct 29, 2014
    Messages:
    18
    Likes:
    0
    hi
    I think your idea is difficult to simultaneously achieve perfection.Why not use interrupts´╝č
     
  7. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    252
    Likes:
    20
    Location:
    West Chester, PA
    Warning (learned from my own experience). If you update the LCD too fast, the cursor on the LCD doesn't have time to blink as it seems to restart a blink cycle after every update. That doesn't matter for an informational display only where the cursor is hidden, but in my case I wanted to use the display to edit various parameters. With out the default LCD cursor, I had to create my own cursor character and provide the character space for them.

    Next time I will only update the LCD as needed, and not at a rate of 10x per second as I did on that project.
     

Share This Page