Display contrast in DIY4

The DIYRPN 4 calculator uses a 16×2 character LCD module. The choice of module was limited due to the desired physical width of the calculator. We chose a module made by Lumex. The module is specified for operation on a 5V supply, but we need to run it on 3.1V. This results in needing a negative bias voltage to get reasonable display contrast. We use a pulse width modulator (PWM) driving a voltage inverter to get a software-adjustable negative bias voltage. Getting the timer of the Energy Micro EFM32G “Gecko” microcontroller working in PWM mode was slightly trickier than expected.We want the display to work while the processor is in a low-power state (not executing instructions), so we have to use the “low energy timer” of the EFM32G rather than the normal timer.  The low energy timer can be run from the low-frequency (typical 32.768 kHz) crystal oscillator (LFXO) or the internal low-frequency RC oscillator (LFRCO). Because we want to have precise timekeeping, we’re using the LFXO.

My first attempt at making the PWM work failed because I had overlooked a relatively obscure note in the EFM32G reference manual which observed that the REP0 (repeat 0) register needs to contain a non-zero value, even though it is not counting down in the PWM mode. Once I added code to initialize REP0 to 1 (or any non-zero value), I could read the timer value in software, and verify that it counts down, and when it underflows, reloads the appropriate value from the COMP0 register (which sets the PWM period). However, the actual PWM pin was never changing.

I spent a lot of time studying the LETIMER chapter of the reference manual, and corrected several bugs in my code, but still didn’t get the pin to change. Finally I looked at the LETIMER application note. The text of the application note didn’t help much, but I noticed that their overly complicated example code was initializing REP1 to a non-zero value, while the reference manual had only indicated that REP1 was used in some other auto-reload mode and did not indicate that it was used or necessary for PWM.

I added a few lines to initialize REP1 to 1, and the PWM started working.  Now I can adjust the display contrast, from too light to too dark, in 16 steps. Fortunately there are midrange values that are somewhat reasonable.

Both the reference manual and the application note could certainly use some more thorough explanation of the requirements to make PWM mode work.

This entry was posted in Calculators, Hardware, RetroChallenge, Software. Bookmark the permalink.

Leave a Reply