PSOC5 LP Control 16x2 LCD Backlight using a Timer (maybe using 4x4 Keypad trigger)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello Community,

 

I am trying to implement a control functionality for the LCD backlight in my application, where the backlight of the LCD needs to be switched OFF after an interval (~10sec) maybe using an interrupt, without affecting the program's execution.

The system consists of a PSOC5 LP, 16x2 LCD, a temperature sensor over ADC, and a pushbutton (or a 4x4 keypad - I know the method of detecting the keypress is different), which can act as a trigger.

I think the approach is to use the timer, and trigger it with a pushbutton (or 4x4 Keypad - preferred) to generate an interrupt after a period has elapsed and then turn off the LCD backlight, without halting the execution of the program completely (like printing the temperature value continuously even after backlight is OFF), which I think would be to use the One-Shot mode of the timer. 

Using the One-Shot does help with triggering and turning the LCD backlight OFF only once, but no response after that. The main application is a MENU system, where the LCD would need to go OFF on different screens, so the timer needs to have a reset of the Period once the ISR is finished - to then be able to trigger again and so on.

I would like to get some help with this application and I am unable to comprehend on how to reset the timer for the above-mentioned application.

Attached is the firmware with One-Shot Timer and ADC.

Hope someone can help.

Regards,
Yash

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I modified my sample project to reflect your request.

(1) During initialization, backlight is on

(2) Each time a valid button is pressed, backlight lights for "BACKLIGHT_DURATION" ms.

moto

P.S. If this works, may be I post the project in Code Examples, later.

View solution in original post

16 Replies
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:
A PWM is a better choice than a timer for this application.
Configure the PWM as a one shot, single trigger. With the appropriate clock, the output will be the pulse width you want (10 sec). Set PWM period to longer than 10 seconds. Set the compare value equal to the period minus 10 seconds. The PWM output routes directly to BL. Depending on the BL polarity you need, you may have to add an inverter. This way you use zero interrupts and zero software interaction. You might consider an interrupt at the end of the temperature calculation to start the PWM rather than using a button. This would be minimal execution time, not interfering with the rest.
Give it a try. If you can't get it to work, I'll build a sample project and send it to you.
---- Dennis Seguine, PSoC Applications Engineer

0 Likes
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi Dennis,

 

The attached firmware with this reply is a sample of the firmware with the implementation that you suggested using the PWM instead of a counter. But that didn't work out, even though setting the One-shot with a single trigger, and since it's PWM, the LCD stays ON for 2sec and turns OFF for another 1sec, but again comes back ON (which is not intended).

 

My application requires the Backlight of the LCD module to timeout after 10sec if there is no activity/input from the keypad, but comes back ON when the user presses any key on the 4x4 matrix keypad.

The base firmware of my application is from this link by @MotooTanaka san, and the older thread link is from here.

Hope this gives better clarity regarding the final application.

Regards,
Yash

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:

I gave you some bum information last time. OOPS. The PWM should be one-shot, multiple trigger. Single trigger requires the PWM to be reset in software after each trigger, multiple trigger allows restarts after the terminal count of the period. Next, the trigger for the button on the -059 kit should be set to falling edge. Finally, PWM's CMP value type 1 should be 'More.' This allows the PWM to go high at the trigger, then go back to Vss when the compare value it reached. The period should be set to the length of time that you want to hold off multiple triggers. In this example, it is set to 4999 to achieve 5 second lockout after trigger. The compare value is set to 2000. The difference between period and compare is the length of the output, in this case 3.0 seconds.

You can't trigger the one-shot with software. If you need a software trigger, put in a control register with the output to the PWM trigger input; write a suitable value to trigger the one-shot.

The project works like a champ. The entire code is one line of PWM_1_Start and nothing at run time. This will not interfere with any processing, communication, or interrupt code you may have running. I'm typecast as an analog hardware engineer; this is my kind of simplicity.

---- Dennis Seguine, PSoC Applications Engineer

0 Likes
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi Dennis, 

I tried the above firmware and implemented similar changes to the ADC_LCD_PWM project as well and can confirm that it works as you explained.

But I wanted to know if there was a way to have the Pulse_Out (being used as the LCD backlight) HIGH at the start (or POR after being programmed), and when the Trig is pressed, the Pulse_Out stays HIGH (for the intended period) and then goes LOW (according to the compare value) and stays LOW?

With the current implementation, simply changing the Compare Type to LESS, and putting a NOT gate between the PWM_out and the Pulse_Out did work to keep the Pulse_Out to stay HIGH initially, and till the Period-Compare Value, and then turn LOW for the duration of the compare value, but goes back HIGH again -- which is not intended.

You can't trigger the one-shot with software. If you need a software trigger, put in a control register with the output to the PWM trigger input; write a suitable value to trigger the one-shot.
>>  Also, can you help with implementing a software trigger with the help of the Control Register for the intended use case?

Attaching the new modified ADC_LCD_PWM firmware with the thread for reference.

Regards,
Yash

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:
First things first. You just have to invert the output while keeping the timing the same.

DennisS_46_0-1664576482866.png

Works as intended. Archive attached.
I will work on the control reg next.
---- Dennis

0 Likes
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hi Dennis,

Thank you for sharing the firmware.

But unfortunately, it's not the intended firmware application that could suit my use case.

The current firmware does the following:
1. Kit is programmed, LED is ON at start (before button press).
2. When the button is pressed, the LED goes OFF for the (Period-CMP Value 1) duration.
3. After an OFF period of 3s, the LED goes ON, and stays that way until the button is pressed again.

To give a better perspective of the intended firmware:
1. Kit is programmed, LED is ON (POR).
2. When Button is pressed, the LED should stay ON for the (Period-CMP Value 1) duration.
3. Then LED should turn OFF after the active duration, and stay OFF until the button is pressed again.

I want to know a proper way to implement something similar to that of a Keyboard's Backlight on a laptop, but with the initial value as ON and then the timer for the backlight only starts when the button is pressed, which stays for the intended duration and then turns OFF.

I hope I was able to explain the use case better this time.
Would it be possible to use a combination of Timer and PWM to get the intended use case? MAYBE?

Regards,
Yash

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:
Your intended use case is still not clear to me.

If I understand correctly, you want the backlight to come on for a fixed interval at startup.
Then you want the backlight to come on after a button press for a fixed period.
Is this correct?
Do you intend to source or sink current to the LED?
Do you intend to drive the LED directly or put a transistor in between to handle more current?
The blue LED on the kit-059 is set for sourcing current.

---- Dennis

 

0 Likes
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Dennis:
My application is a modified version of an example project from @MotooTanaka san, which can be seen from here (you can have a look as a reference to understand the use case). The main change is to adapt the firmware from UART to a 16x2 LCD module.

 In my application, there are a few initializations that need to be performed, and I would need the LCD's backlight to be ON during this time. After the init's of different modules is finished, my application uses a 4x4 matrix keypad, to navigate through a menu system that has various options to access and read the various connected peripheral sensors.
To give you a better perspective, one such menu option is to read a thermistor using the ADC and display it to the LCD in a loop. This process may need the backlight to be ON for a small duration and then turn OFF in order to save power.

The entire process above involves using the 4x4 matrix keypad to navigate, select or exit from the said MENU entry. And the progress is displayed on the LCD display. 
In order to save power, need to implement the backlight timeout of the LCD's backlight to save power.

If I understand correctly, you want the backlight to come on for a fixed interval at startup.
Then you want the backlight to come on after a button press for a fixed period.

>> The backlight needs to stay ON for the duration of the initializations are finished and then when a menu item is selected using the keypad, the timer for the timeout starts (which determines how long the backlight will stay  ON from the time the button is pressed) and then timeout and stay OFF until and unless a button on the keypad is pressed again or an exit from the MENU item for which the LCD's backlight should come back up again.

Do you intend to source or sink current to the LED?
Do you intend to drive the LED directly or put a transistor in between to handle more current?
>>Sourcing the current from the kit directly without a transistor (Since it's the Backlight of a 16x2 LCD module).

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I modified my sample project to reflect your request.

(1) During initialization, backlight is on

(2) Each time a valid button is pressed, backlight lights for "BACKLIGHT_DURATION" ms.

moto

P.S. If this works, may be I post the project in Code Examples, later.

Hi, @MotooTanaka san,

Thank you for responding back. You were a lot of help before and still are with this latest modification to the project.

This is exactly what I wanted to implement.

Also, I see that you have used the K or GND terminal of the 16x2 LCD module for the backlight control and not the A terminal. Any specific reason?

I will try using the A Terminal and test it myself in the meantime.

Thanks a lot again.

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

For my LCD 1602A, A is VCC and K is GND for the Backlight.

And usually the current GPIO can handle is lager for sink compared with for source.

As DennisS_46-san, suggested, the GPIO may not be able to provide enough current for the backlight or even if it can it will draw rather large current from the chip, instead connecting the pin to the ground will reduce the stress to the device (I hope).

The default was 
source: 4 mA

sink:  8 mA

001-gpio.JPG

And we could select even

source: 4 mA

sink: 25 mA

002-gpio.JPG

So I decided to use K for controlling backlight.

Meantime, in my example I wrote active_backlight() as

 

void activate_backlight(void)
{
    LCD_K_Write(BACKLIGHT_ON) ;
    backlight_timeout = BACKLIGHT_DURATION ;
}

 

But if you modify  it like

 

void activate_backlight(long duration)
{
    LCD_K_Write(BACKLIGHT_ON) ;
    backlight_timeout = duration ;
}

 

you can specify the duration time of backlight for each button/event as you like.

 

moto

Edited 
Some spell correction
and Mention the DennisS_46 san's suggestion.

0 Likes

@MotooTanaka san:

For my LCD 1602A, A is VCC and K is GND for the Backlight.
>> I am also using the same RG1602A 16x2 LCD module with the same config.

As DennisS_46-san, suggested, the GPIO may not be able to provide enough current for the backlight or even if it can it will draw rather large current from the chip, instead connecting the pin to the ground will reduce the stress to the device (I hope).
>> What is the value of the series current limiting resistor that you are using with the LCD? Is connected between VCC and A or between K and pin P2[7]?

Also, in the current application, is it advised to use source: 4 mA, sink: 25 mA ort keep the default source: 4mA, sink: 8mA since VDDIO is 5V in our application??

I was going to modify the void activate_backlight(long duration) function in the firmware

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Yash-san,

As you can see the schematic page in my project,
I used a couple of 10K pots, so the value would be somewhere between 0K and 10K.
For the backlight POT (R_2) is connected to VDD, A, and GND.

P2[7] is connected directly to the K pin.

As it required some adjustment to set appropriate brightness (to me),

at least the value was not 0K nor 10K, but I did not check with my tester.

003-schematic.JPG

> Also, in the current application, is it advised to use source: 4 mA, sink: 25 mA ort keep the > default source: 4mA, sink: 8mA since VDDIO is 5V in our application??

Although I did not run a math, with the default 4mA/8mA my LCD seemed to be fine.

> I was going to modify the void activate_backlight(long duration) function in the firmware

Sounds good to me 😉

 

Best Regards,

7-Oct-2022

Motoo Tanaka

DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:
PSoC outputs can provide a limited amount of current. From the PSoC5LP datasheet:

DennisS_46_0-1664982593696.png

The outputs look resistive, worst case 150 ohm when sourcing, 75 ohm when sinking. The typical values are about half of these values. What is the current requirement of your backlight? What is the LCD part number and who is the manufacturer? It is generally not a good idea to draw more than the stated performance limit from a GPIO.
---- Dennis

0 Likes
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Dennis:

I am using the RG1602A 16x2 LCD with Yellow-Green Backlight which is generic and the datasheet can be accessed from here.

And according to this article, it says to use a 10Ohm resistor in series to the A terminal (connected to VCC +5V) while controlling the backlight operation using the K terminal (as @MotooTanaka san helped provide an implementation for). 

PS: VDDIO is set to 5V and not 3.3V.

Regards,
Yash

0 Likes
DennisS_46
Employee
Employee
100 sign-ins 50 likes received 50 solutions authored

Yash:
The article you cited mentions a 100 mA current to the backlight and shows the schematic:

DennisS_46_0-1665149944813.png
There are dozens of 1602 displays out there. The part that you chose has no specification on required current
for the backlight. The article does not specifically mention the LCD that you selected. If the backlight takes 100 mA, you will never get sufficient brightness out of the PSoC GPIO's available current. I believe that the NPN driving the K (cathode) terminal is the preferred method for the amount of current required.
---- Dennis