Driving the LCD Contrast with pin 3 vs pin 6...

Hi,
I am fairly new to this Arduino stuff, but I have been playing with the LiquidCrystal library a bit.
I have wired the 2x16 LCD HD44780 compatible LCD as described in the Arduino Tutorials and all works well.
I wanted to drive the contrast (pin 3 of LCD) using the Digital IO and connected it to digital IO pin 6. I can then set the voltage using the analogWrite(). All seems to function fine. LCD display looks good. Problem is I moved the contrast connection to Digital IO pin 3 and the LCD words flicker really fast. From what I have read this is because pin 3 is using PWM to produce the analog value. BUT what I have also read is that my original pin 6 is also PWM, so why does it not flicker when the contrast is plugged into pin 6?
Is the PWM signal on pin 3 slower than pin 6 perhaps and the flicker is so fast that I cannot see it?
This does not stop my development it was just something that confused me.

Thanks

The contrast pin on many LCD modules produce a negative voltage that is fed back through a pot. That is why you can't just give it a variable positive voltage.
However if you have one that will work like that you need to smooth the PWM to make it a DC voltage. See:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

The contrast pin on many LCD modules produce a negative voltage that is fed back through a pot.

Mike: That's not the way I understand it.

The contrast pin (pin 3) on the character mode LCDs is an input pin that typically requires a small positive voltage applied to the pin to make the display legible. Some of these devices, especially the extended temperature range versions, require a negative voltage applied to the pin and it is up the the user to provide a source for that voltage.

The contrast pin on the graphical LCDs generally require a negative voltage and many if not most of those devices have a negative power supply on board and available at pin 18.

Don

for BRIGHTNESS, use pwm and either direct wire pwm or transistor-buffer (drive) it.

for CONTRAST, you can use a digital pot (I'm about to do that for my own projects). digital pot over spi or i2c are buyable for a few dollars. they act just like pots, too with a wiper and 'top' and 'bottom' legs.

for extra points, get a digi pot with nvram that keeps its value over power-resets.

Thanks for the many responses but, is there a difference between Digital IO Pin 3 and Pin 6, with respect to PWM?
Flickers with Pin 3, but not with pin 6.

Thanks

difference between Digital IO Pin 3 and Pin 6, with respect to PWM

Here are my observations based on arduino-0021 and -0022:

PWM pins 5 and 6 are controlled by Timer 0, which is used for lots of Arduino timing stuff, and are not as reliable (in my experience) for use as PWM outputs (unless you disable interrupts, which I really, really, really don't recommend in general).

When they are working, the PWM frequency on pins 5 and 6 is about 976 Hz.

On the other hand...

The other PWM pins are controlled by Timer 1 (pins 3 and 9) and Timer 2 (pins 10 and 11), and are more useful. The frequency on those pins is about 488 Hz. Once you do the analogWrite thing to one of these pins, the output remains at the given duty cycle until you do something else with that pin.

I'm thinking that I read (somewhere) that PWM operation in some older versions may have been different, but I don't have the means, the motivation, or the stamina to attempt other testing.

Bottom line: I, personally, wouldn't try analogWrite PWM output on pins 5 or 6, but you may be able to figure out something that works better than what I observed. See Footnote.

Here's the simplest test that I could come up with:

void setup()
{   
    //
    // When I comment out the cli() line, pins 5 and 6 go high after a brief burst
    // right after reset.  The burst lasts about 32 milliseconds and during that
    // time they show a 50% duty cycle square wave with frequency about 976 Hz.
    // After that time, pins 5 and 6 go to a high logic state and remain there.
    // When I uncomment it (so that interrupts are disabled), there is a continuous
    // square wave with 50% duty cycle and a frequency about 976 Hz.
    //
    // The other pins work the same with or without the cli() statement: Continuous
    // 50% duty cycle square waves with frequency about 488 Hz.
    //
    // Tested on a Duemilanove with arduino-0022.
    //
    // davekw7x
    //
    //cli();
    analogWrite(3, 127);
    analogWrite(5, 127);
    analogWrite(6, 127);
    analogWrite(9, 127);
    analogWrite(10,127);
    analogWrite(11,127);    
}

void loop() {}

Regards,

Dave

Footnote:
I would be really, really interested to know whether anyone else has actually tested this stuff with recent Arduino releases. I mean, I am reporting the results of my actual experiments, and not something that I just deduced/divined from the code or from something I think I may have read somewhere, but maybe I overlooked something. (It wouldn't be the first time. Not even the first time today.)

Thanks Dave,
The 50% duty cycle and a frequency about 976 Hz perhaps explains why I see flickering on Pin 3 (488 Hz), where is likely slow enough for eyes to see and do not see flickering on Pin 6 (976 Hz) where it is fast enough that is not visible to the naked eye.

Regards Mark