Skip to content

lcd_hd44780: Set data lines before raising E - #7444

Open
catawalks wants to merge 1 commit into
Klipper3d:masterfrom
catawalks:hd44780-data-before-enable
Open

catawalks wants to merge 1 commit into
Klipper3d:masterfrom
catawalks:hd44780-data-before-enable

Conversation

@catawalks

Copy link
Copy Markdown

This moves the D4–D7 update in hd44780_xmit_bits() to before E is raised HIGH.

The existing sequence appears to meet the HD44780 write timing: data needs to be valid only for tDSW before E falls. However, the WINSTAR display tested here appears to require valid data when E rises. With the change, the data is stable for the entire E pulse. This is also the sequence used by Arduino’s LiquidCrystal library and Repetier-Firmware’s HD44780 driver.

Changing just the order would bring up an issue on slower AVR MCUs that didn't require a delay. ndelay() is a no-op, so the E pulse width came from the time spent updating the data lines while E was high. With the data lines set up before the E toggle it basically would have put the toggles back to back and not had enough time delay. Adding the nop delay (the same as in sensor_cs1237.c) adds the needed time delay back for AVR boards allowing proper timing. This is calculated by disassembly but is otherwise untested as I don't have an AVR board to test with.

Tested on a XYZprinting da Vinci 1.0A with a SAM3X8E mainboard and stock WINSTAR 1604 (16×4) display, configured as:

[display]
lcd_type: hd44780
line_length: 16
hd44780_protocol_init: True

The board’s LCD R/W line is held low with a static_digital_output.

Results:

  • Klipper default E raised HIGH before data, default Klipper pulse: Display commands inconsistent, text garbled
  • Klipper default E raised before data, lengthened 5 µs pulse: Stayed in one-line mode, text also garbled
  • Data set before E is raised, default Klipper pulse: Correct text and line mode, display fully functional

The display works at the existing timing after both FIRMWARE_RESTART and a cold power-on, including menu navigation. Increasing the E pulse by more than 20x did not resolve the issue with the original sequence.

I’ve only tested this one display, so reports from owners of other HD44780-compatible displays would be helpful. This change should not negatively affect any HD44780 compatible screens, theoretically it should only increase compatibility of clones.

Update the D4-D7 data lines before toggling E high in
hd44780_xmit_bits(), instead of raising E first and changing the data
lines while E is already high.  On non-AVR boards the E pulse width
and all other timing are unchanged.

A WINSTAR 1604 (16x4) display, as fitted to the XYZprinting da Vinci
1.0A, showed garbled characters with the previous ordering, and could
remain stuck in its power-on one-line mode.  Lengthening the E pulse
to 5us with the previous ordering did not help.  With the data lines
set before E rises the display works at the existing timing, both
after a FIRMWARE_RESTART and after a cold power-on.

This is still within the HD44780 write timing (the data remains valid
well before E falls), and matches the order used by the Arduino
LiquidCrystal library and Repetier-Firmware.

On AVR, ndelay() does not delay, so the E pulse width came from the
time spent updating the data lines while E was high.  Add a short nop
delay there (as in sensor_hx71x.c and sensor_cs1237.c) so the E pulse
is not shortened by this change.

Signed-off-by: Joel Pratt <catawalks@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant