PC Services"From Payroll to Body Scanners"Established 1994 |
PC Services (Electronics)Arduino - Liquid Crystal library |
Tel: 0118 946 3634 |
Gallery of Liquid Crystal libraryWhilst working on scheduler, it was discovered that the standard LiquidCrystal library was excessive on time delays and was blocking other tasks. This library was reviewed and some results and updates are discussed here. This is also documented on the Arduino Github pull request 4550. Original Findings
Inital Task execution time on a Due (84 MHz clock), was showing an excessive amount of time taken to do a small update to LCD in a short task. Then calculated what the expected time would be for setting the LCD cursor and writing 20 characters, which from datasheet timings in 8 bit mode with no software overhead (in micro seconds) -
Set Cursor + 20 Characters However we were seeing around 3 ms or 3,000 us, which is way too long. Investigations into the code of the library revealed -
TestingTo enable correct testing a test programme was made that could be 4 bit or 8 bit mode to measure on a scope the timings by performing the following -
The test results were captured and the software modified to improve on delaying if necessary only as long as needed, reduce nibble delay to 1 us between first and second nibble, then further results taken. As these tests were done on a Due, the same code was also tried on a Mega (same clock speed as Uno) to give a comparison of the new code on a slower device. No baseline tests were done on Mega however results show the timings to be in the right ball park considering the differences in clock speed and architectures. The code used is available in package available from Github detailed at bottom of this page. ResultsThe test results are tabulated below and show dramatic speed increase which means writing to LCD does not stop other things happening. These are now into the right ball park compared to original calculations.
Scope Shots of testsThe following are scope shots of the original timings and Optimal after library update using the test programme Note Rising Edge of GPIO scope trigger used as reference point for all timings.
Click on an image for an enlarged view of the picture.
Code and DocumentationThe update files, test programme and documentation are available from Github repository. Interested in something similar contact sales. |
© 2016 onwards by PC Services, Reading UK | Last Updated: 11th April 2016 |
If you encounter problems with this page please email your comments to webmaster |