I RECALL A THREAD about controlling the LCD brightness

Status
Not open for further replies.

MrDEB

Well-Known Member
I would like to eliminate the 10K pot for adjusting the LCD brightness.
I recall a thread using PWM or maybe a voltage regulator.
 
It's easy to do - 1K resistor from PIC PWM pin to contrast pin of LCD, and a 10uF electrolytic from contrast pin to ground (making a low pass filter for D to A). Then just set the PWM to provide the voltage you want out - in the case of the displays I'm using I set the default value to 10 (it's stored in the data EEPROM) - it can be altered in a menu on the product, and is automatically stored to EEPROM if you do. However, for our displays 10 seems spot on, and never seems to require adjustment.

Changing to this method made our product more versatile, and cheaper to make - as it removes the step of setting the pot up (the default value is in the source code).

The 10uF cap I use is a very small through hole component.
 
how to program the desired PWM voltage and what program?
I am using a Pickit3, Swordfish and either a 18f2221 or 18f43k22 (2 different applications)
 
I downloaded Multicalc but keep getting error message
MSSTDFMT.DLL
the error says this must be installed
 
I downloaded Multicalc but keep getting error message
MSSTDFMT.DLL
the error says this must be installed
What's that got to do with anything?.

I can't help you with the code because you use an obscure language and compiler, but you simply need to set one of the PWM channels to output PWM on the pin you using - depending on the PIC, this might be restricted to specific pins, although most modern devices allow a high degree of pin movement.

I would imagine there are Swordfish examples on how to set PWM hardware? - it also requires a timer to run it.
 
MrDEB
I am not clear whether your question is about contrast of the LCD characters or brightness of the backlight, as implied in the title. Either can be controlled from your MCU, but the approaches are a bit different. If it is the backlight, you may need more than the 25 mA a PIC can typically supply. Some displays need 100 mA or so. If it is contrast, then one needs to know a little more about the LCD you have. I suspect from context that your display has an onboard negative voltage generator. If not, that too can be done by the MCU.
 

As he specified the 10K pot to adjust the display it's pretty clear he's talking about the contrast, as 5K or 10K are the standard pot values used.

LCD modules requiring negative voltages are pretty historic now, and certainly not something the OP would be messing with.

While it's not going to help the OP, as he doesn't use C, these are the PWM routines used in my code, using PWM6 and TMR2 on a 16F18557.

C:
// set tmr2 for pwm6 (for contrast adjustment)
    T2CLKCON = 0x01;
    T2HLT = 0x00;                                                               // T2PSYNC Not Synchronized; T2MODE Software control; T2CKPOL Rising Edge; T2CKSYNC Not Synchronized; 
    T2RST = 0x00;                                                               // T2RSEL T2CKIPPS pin; 
    T2PR = 0x65;
    T2TMR = 0x00;
    PIR4bits.TMR2IF = 0;                                                        // Clearing IF flag.
    T2CON = 0x80;                                                               // T2CKPS 1:1; T2OUTPS 1:1; TMR2ON on;

// PWM routines for contrast adjustment
PWM6_Init(void)
{
    PWM6CON = 0x80;   

    // DC 12;
    PWM6DCH = 0x0C;   

    // DC 2;
    PWM6DCL = 0x80;   

    // Select timer
    CCPTMRS1bits.P6TSEL = 1;
}

PWM6_Duty(unsigned int duty)
{
    if(duty<1024)
    {
        PWM6DCH = (duty & 0x03FC)>>2;
        PWM6DCL = (duty & 0x0003)<<6;
    }
}

PWM6_Start(void)
{
    T2CONbits.TMR2ON = 1;
}

PWM6_Stop(void)
{
    T2CONbits.TMR2ON = 0;
}
 
I downloaded Multicalc but keep getting error message MSSTDFMT.DLL
If you're trying to install the old mister-E PIC MultiCalc utility you're likely missing some of the required DLL's, which you'll have to download and install.

See https://www.picbasic.co.uk/forum/showthread.php/4994-New-PIC-Utility.-PICMultiCalc for more info on which ones and how to install them. Good luck.

There are examples of using PWM with Swordfish. See

Again, good luck. I know what you really need is a line-by-line example of exactly how to do this for exactly the device you're using, but you're on your own this time. It's all in the datasheet.
 
As he specified the 10K pot to adjust the display it's pretty clear he's talking about the contrast, as 5K or 10K are the standard pot values used.
jpanhalt said:
If it is contrast, then one needs to know a little more about the LCD you have.
I don't disagree, but it will still help to know which LCD he is using. Assuming it's the common Hitachi variant (HD44780 compatible) may not be correct.
 
I don't disagree, but it will still help to know which LCD he is using. Assuming it's the common Hitachi variant (HD44780 compatible) may not be correct.
But the odds are greatly in favour of that - if you hear hoof beats, think horses nor zebras
 
If you control contrast pin on LCD be very careful you observe power sequencing on display
when system powered up. Work to the wise.

Datasheet will cover that requirement.


Regards, Dana.
 
That document is 30 years old and probably out of date. In fact, it says exactly the same as mine regarding character displays,


I suppose there's a (slight to none) chance that a TFT display is involved but I think modern displays won't have these requirements.

Mike.
 
Y'all know you might as well be talking Chinese for all the good your comments will do MrDEB.

The basics. As Nigel said, you need an RC low pass filter. He suggested 1k and 10uF, which gives a cutoff frequency of 15.9 Hz. I might suggest 1k and 1 uF to make the capacitor smaller, which gives a cutoff frequency of 159 Hz.

The PWM frequency should be 10× the cutoff frequency or greater. This calculator will show the options for a given clock speed. Pick one that's greater than 10× the cutoff frequency and plug the whole number (i.e., integer value) into the PWM module SetFreq() command. (You can probably plug in any value you want without calculating a value, but using a calculated value assures it's within the possible range).

Include the PWM2 module (available on the Swordfish page if you don't have it already).


Steps – figure out the exact syntax by looking in the PWM2 module (sorry, not at my computer):

Set frequency

Set duty cycle from 0 to 100%

Start PWM


Varying duty cycle from 0 to 100 will vary voltage from 0 to 5 volts (supply voltage).


DO NOT change FREQUENCY. It stays fixed.


Another useful calculator is here.

Back on ignore mode for MrDEB.
 
Thanks, popcorn that explains it a lot.
My end goal is to still read the LCD display ( Hitachi variant (HD44780) when the battery starts going low.
Even considered experimenting with using a 7555 PWM circuit and read desired voltage using the pot then make adjustments but the 7555 will use more battery resources than just using the PWM on the pic.
 
Why not just use a digital pot?? You only need an 8 bit one and SPI (2 pins) as you dont need to read.
Or a 555, why use the micro when you can add additional chips?

My apologies if that was sarcasm.

Mike.
 
With a digital pot you can contol it ratiometrically from software.. He did just say about creating a 555 circuit.

I think quite a few members here overestimate MrDebs electrical prowess. Simple and quick.
 
But isn't a PWM output with a simple RC filter basically the same as a digital pot? And cheaper?

How do you write to a digital pot? I²C SPI? Both far more complex than a simple PWM pin.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…