April 24, 2024, 08:10:51 AM

SHIELD-LCD16x2 new firmware

Started by Laurence123, March 27, 2024, 02:38:20 PM

Previous topic - Next topic

Laurence123

I have identified a number of issues with the 16x2 LCD and fixed them with a new firmware build for the PIC16F722A.
This is attached as a zip. Initial testing shows it is much faster, but the UART functionality has not been fully tested.
https://workupload.com/file/yupRn6mV78J
I2C has been tested at 100kHz. 400kHz seem to result in issues, appears related to the I2C peripheral on the PIC, which is in 100kHz mode by default. This can be swapped to 400kHz mode, but then according to the PIC16F datasheet there is a hardware timeout that will cause timeouts with bit-banged data exchange.

LubOlimex

Nice but can you give some details about what tools are used to compile it to build it? There is no project file.
Technical support and documentation manager at Olimex

Laurence123

#2
I used MPLAB-IDE, this new version is cleaned up and will hopefully load into the IDE as a project.
https://workupload.com/file/ypjLT3YxZMJ

LubOlimex

It compiles now and seems to work fine but we are a bit lost what does the changes do. Many changes and will take us a lot of time to understand everything. Care to explain what are the main improvements in your firmware?

Maybe we will provide it as alternative option on the web-site if someone else wants to test it.
Technical support and documentation manager at Olimex

Laurence123

#4
The main change was to fix the time delays so they are correct (stock firmware has very long time delays, so the Arduino library needs delays of tens of milliseconds when talking to the screen). I have now also modified the Arduino library to have no delays apart from a 2ms delay when clearing the screen.
 I also moved the LCD communication out of the interrupt service routine and into the main loop. This avoids the risk of an ISR being un-serviced, which seemed to be the cause of lockups if the delays on the I2C communications were too short (this problem has also been described in previous forum posts). There is now a command buffer between the ISR and the main loop, but at only 100kHz I2C clock speed, it will never get very full. If 400kHz I2C is used then it will start to fill, but currently my firmware does not support >100kHz I2C due to the I2C config register settings on the PIC16F. I haven't tested 400kHz I2C clock as it is not required for my application, but my understanding of the PIC16F datasheet is that when 400kHz mode is configured then there are some hardware timeouts that may cause issues with bit-banged I2C on the Arduino, but I haven't tested this.
 The third change was to avoid use of standard string libraries to save flash on the PIC. I also rewrote the UART string handling logic to reduce SRAM use. As a result it's now possible to compile the full code with MPLAB IDE and still have space left over to implement the command buffer between the ISR and main loop.
 As a final guard against lockups, I enabled the watchdog timer on the PIC16F and set the timeout to 500ms. It is reset every main loop iteration.