Adjusting LCD contrast by PWM

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to adjust LCD contrast using PWM. Waveform generated using a 8-bit timer running at 16MHz (no prescaler) in fast PWM mode.

If I connect PWM pin directly to V0, sometimes LCD shows some garbage characters or skips some commands; probably because of the noise which PWM waveform generates.

I tried RC low-pass filter but it didn't help unless I increase resistance a lot which caused a reduced contrast range.

I wanted to create another type of filter; so I inserted a 470Ω resistor between PWM pin and V0 before other steps. Surprisingly, LCD started working perfectly! No more garbage character or command skipping even while printing characters very fast. Contrast adjusting also worked perfectly.

What's going on? How did a simple resistor solve the problem?

This topic has a solution.

Slow and Steady!

Last Edited: Fri. Oct 16, 2020 - 09:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried RC low-pass filter but it didn't help unless I increase resistance a lot which caused a reduced contrast range.

Why do you neglect to say what size cap you are using?

 

The results depend on the current drawn by the LCD pin (including any pull up/down resistors or dividers they use) & any cap they might  include ( they may assume you connect a noisy pot or voltage.

 

A 10uF cap & 1k PWM resistor gives a 10ms time constant....so  even 1 KHz or more PWM would be plenty fast & smooth....the "low" 1k should be low enough to  drive anything they put on their board.

 

  How did a simple resistor solve the problem?

You accidentally created an RC with the stuff on the LCD.   But create your own RC, so you have known values.  Sounds like you are just guessing.

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's possible that merely current-limiting the PWM made a difference too.  Less current, less power, less noise.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:
What's going on? How did a simple resistor solve the problem?

 

SHow your connections/schematic.

 

Traditionally Contrast adjust is done with a 10k pot.  Either manual, or digitally controlled.

 

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Why do you neglect to say what size cap you are using?

Sorry; I forgot it. For RC low-pass, I used 300nf (3 parallel 100nf) capacitors and 5K resistance (2 parallel 10K). It was better than nothing but didn't fully solve the problems. Also high resistance limited contrast range.

 

avrcandies wrote:

Sounds like you are just guessing.

Not just guessing. I used "f = 1/(2πRC)". However, I started changing resistance and capacitance to get better results. No RC configuration performed like this simple resistor. I tried another 470Ω resistor and same thing happened. Multimeter also confirms it is a 470Ω resistor (not self or etc.).

 

jgmdesign wrote:

Show your connections/schematic.

Connection is simple: ATmega328P pin OC0A (PD6) to a 470Ω resistor and resistor to LCD V0 pin. Nothing else (capacitor, etc.) in between.

 

jgmdesign wrote:

Either manual, or digitally controlled.

I know traditional manual potentiometer method; but how should I adjust contrast using a potentiometer and digitally? Using a servo motor? frown

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PWM is perfectly fine...you just need a low ohm source & some good filtering get a few uF going and maybe 1K.

You can use an SPI pot but that might be $$$, though your needs are extremely minimal in terms of accuracy & resolution---basically zilch, so the cost can drop for a cheapo part.

 

When you adjusted your PWM did you scope the signal after the RC?? Was it well-filtered?  What  voltage range did you get at the LCD pin -- min to max?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In practice,  you need about VCC - 4.6V on the VO pin.    e.g. when VCC = 5V you need 0.4V on the VO pin.   (VCC = 3.3V needs VO = -1.3V )

 

If your product is powered by USB or mains power VCC will be a known value.

Battery powered devices will have a falling VCC.

 

The easiest way to produce 0.4V on a 5V LCD is with a 1k0 variable resistor between VO and GND.  

This forms the bottom leg of a potentiometer with the 10k pullup that is already on the LCD.

You can "calibrate" the best contrast with the variable resistor.   Replace variable with a fixed resistor.    470R is going to "work" on any 5V LCD.

 

The "typical potentiometer" between 5V and GND is unnecessary.   You only need the "bottom leg" i.e. variable resistance.

 

The only reason for using a filtered charge pump with PWM is if you need a negative voltage e.g. when VCC = 3.3V

Or if you are using a battery.    In which case you would measure VCC and adjust PWM as the battery voltage falls.

 

David.

Last Edited: Mon. Oct 5, 2020 - 07:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found something strange: LCD prefers non-filtered PWM.

If I provide non-filtered PWM (just resistor) to V0, Background of some characters will be gray. However there is no glitch.

If I apply RC low-pass filter on PWM, those gray backgrounds get transparent and quality improves. However, LCD will perform incorrect command or show incorrect characters sometimes.

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please just follow my advice.  i.e. 470R between VO and GND.    Try different fixed resistors.    Or use a 1k0 variable resistor.

 

PWM should work if correctly filtered.   e.g. 470R x 100nF = 47us.

8-bit PWM on OC2A has a period of 16us

10-bit PWM on OC1A has a period of 64us

 

470R x 300nF = 141us.   So will probably be ok with 8-bit PWM.

 

But the whole exercise is pointless unless you do not have a steady VCC = 5V

How have you connected the 470R and 300nF ?

 

David.

Last Edited: Mon. Oct 5, 2020 - 08:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:

jgmdesign wrote:

Either manual, or digitally controlled.

I know traditional manual potentiometer method; but how should I adjust contrast using a potentiometer and digitally? Using a servo motor? frown

 

good grief!
google DIGITAL POTENTIOMETER.

 

jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

good grief!
google "price of 270R resistor".

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I apply RC low-pass filter on PWM, those gray backgrounds get transparent and quality improves. However, LCD will perform incorrect command or show incorrect characters sometimes.

It sounds like you aren't paying any attention to your hookup----setting the contrast should have no effect on the data.  What filter cap are you using on the LCD power pins?  Show your exact schematic.   

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

SHow your connections/schematic.

 

Traditionally Contrast adjust is done with a 10k pot.  Either manual, or digitally controlled.

+1

The OP will get far better answers if they show a schematic as Jim requested, this can be done by printing your schematic to a pdf and uploading it or taking a picture and posting that.

As they say, one picture is worth a 1k words!!! 

Tell us why you think you need digital control of the contrast of your display?  Normally a simple manual contrast control will work fine.

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

google DIGITAL POTENTIOMETER.

I didn't know about these. Thanks.

 

david.prentice wrote:

google "price of 270R resistor".

I want digitally adjustable (variable) contrast. eg. changing contrast in settings menu of device.

 

avrcandies wrote:

It sounds like you aren't paying any attention to your hookup----setting the contrast should have no effect on the data.  What filter cap are you using on the LCD power pins?  Show your exact schematic.   

I also think this is strange. I have no schematics. Just an Arduino UNO and an LCD on a breadboard connected by wires. Here are connections between Arduino and LCD:

 

    LCD pin               Arduino UNO pin

 

    VSS                    GND

    VDD                    5V

    VO                       470Ω resistor to 6x100nf grounded capacitors to pin 6   (PWM)

    RS                       7

    RW                      8

    E                         9

    D0..3                   -

    D4..7                   10..13

    A                         5    (PWM)

    K                         330Ω resistor to GND

 

RC low-pass:

My breadboard is kinda old. Could it cause these problems? I'm not sure but I feel it got better after I changed the position of LCD on breadboard.

 

Slow and Steady!

Last Edited: Tue. Oct 6, 2020 - 12:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are using Timer0 for PWM.    The Arduino "system clock" uses Timer0.   (I think @ F_CPU / 8 ).   Which gives you an 8-bit PWM period 1 / (16MHz / 8 / 256 ) = 128us.

470R x 600nF = RC  = 282us.

 

So I would expect OC0A PWM to need better filtering ok for VO.

You don't need to filter OC0B PWM for LEDA.   But even at 100% duty the LED is only going to receive 6mA.   Which is not going to be a visible backlight.

 

I still reckon this is a pointless exercise.   If your product has a steady 5V e.g. from mains power the contrast only needs setting once.    And the backlight on your BLUE display can be lit 24 hours a day.

 

It is a bit like providing your customers with bandages and crutches so that they can shoot their feet.

 

When it is a lot more sensible to not give them a gun.

 

Seriously,   have you tried a fixed resistor between VO and GND ?  e.g. 220R, 270R, 330R, 390R, 470R

Do you own a variable resistor ? e.g. potentiometer.

 

David.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  1. I use Atmel Studio to write and compile code and AVRDUDE to burn it to Arduino. I have full control on everything including clocks. CPU is clocked at 16MHz. no prescaler applied on timer0 so it is also clocked at 16MHz. Timer0 is 8-bit so PWM period is 1000000/(16000000/256) = 16us.
  2. Backlight dimming using unfiltered PWM works perfectly and has no problem. frown
  3. The device is going to be used in different ambient light conditions. So user may need different contrast and brightness levels. There are some other variable parameters in my device also and I don't want to add a potentiometer for each. I don't want my device look like a sound system! laugh
  4. I used potentiometers for this purpose a lot and used resistors (voltage divider) for constant contrast sometimes. However, this time I need it to be digitally adjustable.

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

you sound confused:

 

I want to adjust LCD contrast using PWM.

 

Are you trying to adjust the LCD contrast or the LCD backlight?  The backlight should just be hooked to your power supply.  You adjust the contrast to suit your viewing angle needs.  That is a low current control signal input.

 

Use at least a few uF for your cap, get serious and use some filter capacitance---why play around with 0.1uf?

 

You have neglected to say what voltages you are measuring at your contrast pin with your different PWM settings.  Use a scope to see that the voltage is steady/flat, after filtering.

 

If you are PWMming LEDS, no capacitor should be used--the high freq on/off/on/off won't be visible, unless you are a cyborg.

 

Note---depending on the  particular LCD...the AVR may not be able to direct drive all of the backlight leds (if they draw 70-100ma), then you use a transistor.  You need to check the datasheet to see how much current the backlight draws, or hook A & K & resistor (if needed) up to a power supply (NOT the avr, since any AVR limitation will affect the reading) and measure using a meter.  Then you will know what is required & whether the AVR can drive it (up to perhaps 30 ma--you go look).

 

you can see this mentioned  for a lcd board:

Backlight Current The maximum allowable backlight current varies widely, even for modules with the same format. For example, for different 20x2 modules, the maximum current ranges from 20 mA to 210 mA! The EDP-I software cannot account for these variations. Therefore, the EDP-I is shipped without a shunt on H2. This ensures that a current limiting resistor is in series with the module’s backlight and will limit the backlight current to around 75 mA. This is still enough to damage some modules. Check with your LCD datasheet before running the module at full brightness.

 

 

I have no schematics.

Then you are playing games, get serious &  draw one up--you will feel better. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Oct 6, 2020 - 05:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If someone is determined to shoot her own foot,   who are we to discourage them?

 

The contrast depends on VCC.   It will not alter with the moon or daylight.   You set once and forget.   In practice a whole batch of 16x2 or 20x4 will work with a single fixed resistor.

PWM wastes a pin and extra board space for a capacitor.

 

You can use PWM on the backlight.   You can adjust between very dim and very very dim.   (but should be acceptable on a dark night)

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
The contrast depends on VCC.   It will not alter with the moon or daylight.   You set once and forget.

I agree with the first two sentences.  The third, not so much, especially if this is not a handheld device and easily re-oriented.

avrcandies wrote:
You adjust the contrast to suit your viewing angle needs.

This.  A lot of these small LCD modules have a fairly narrow viewing angle.  Having the ability to adjust contrast to accommodate different viewing angles can be quite useful.

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

you sound confused:

I'm controlling both contrast and brightness (backlight) using two separate PWMs. Contrast wave is filtered; backlight wave isn't.

 

david.prentice wrote:

If someone is determined to shoot her own foot...

You can use PWM on the backlight.   You can adjust between very dim and very very dim.   (but should be acceptable on a dark night)

1- You meant hissmiley

2- I've seen many devices with an LCD display with a digitally adjustable contrast. So looks like many people are shooting their own feet everyday! cheeky

3- Backlight is really bright if I set pulse width to maximum; almost as bright as when I connect it to +5V and GND with a 330Ω resistor in between. Why very dim and very very dim? frown

 

avrcandies wrote:

Then you are playing games...

My project is based on ATmega328P. I'm using Arduino UNO for testing and prototyping because it uses ATmega328P and it's easy to connect wires to its pins. I won't include Arduino in my device.

After the code is ready, I'll start drawing schematics and PCBs. Hardware of device isn't complex.

 

digitalDan wrote:

This.  A lot of these small LCD modules have a fairly narrow viewing angle.  Having the ability to adjust contrast to accommodate different viewing angles can be quite useful.

Right. yes

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm controlling both contrast and brightness (backlight) using two separate PWMs.

Why do you wait until post #20 to say so?  Go back and look at post #1 ...does it say anything like this?

You continue to refuse to provide your contrast pin voltage measurements, so don't expect results. 

 

Why very dim and very very dim?

Have you bothered to look at the waveform, or measure the voltage?  Also, note the current draw limit mentioned in post 17 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:
2- I've seen many devices with an LCD display with a digitally adjustable contrast. So looks like many people are shooting their own feet everyday! 

 

jgmdesign wrote:
google DIGITAL POTENTIOMETER.

 

Problem solved..... at least that part.(the contrast part)

 

Traditionally I use an analog pot and it is mounted on the PCB and there is a small hole in the front panel for a small screwdriver to make the adjustment as Contrast is usually a set once and forget it.

 

But if you MUST digitally control the contrast heres an exmple of what can do the job:

https://www.mouser.com/datasheet...

 

Jim

 

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Why do you wait until post #20 to say so? 

...

Have you bothered to look at the waveform, or measure the voltage?  Also, note the current draw limit mentioned in post 17 

Because problem was contrast; brightness was OK. I don't know why you're worried about backlight. I set brightness PWM to 255 and voltage between backlight pins is about VCC. No under-current problem. Backlight is OK. Don't worry about it. wink

Also, I don't have access to any oscilloscope now. frown

 

jgmdesign wrote:

But if you MUST digitally control the contrast heres an exmple of what can do the job:

https://www.mouser.com/datasheet...

Good news: Problem solved after I changed LCD position on breadboard some times. I probably should buy a new one.

However, as Jim suggested, DAC or digital potentiometer are better options than PWM. Maybe I use them.

Thanks everyone. heart

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I've done the PWM to adjust contrast thing before (post date says 2009). It worked very well I thought...

 

https://www.avrfreaks.net/commen...