Continue to Site

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.

  • 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.

Delay function

Status
Not open for further replies.
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 :)
 
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.
 
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.
 
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.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top