how to use pic16f877a and lm3914

ErnieM

Joined Apr 24, 2011
8,377
My first guess is you don't.

Both chips share having analog inputs, digital inputs, and digital outputs, plus of course either can or could drive LEDs.

What is not there is an analog output from the PIC to drive the LM3914.

Just what are you trying to accomplish?
 

adam555

Joined Aug 17, 2013
858
can i use PIC digital output pwm
I was asking myself the same question, and I think that if you add a capacitor to the PWM output it might work.

but what value to turn 1 led , 2 led if i have osc 4mhz
For the values you need to divide the maximum value of the PWM by the number of LEDs, and multiply it by the value you want to output; assuming that Vcc lights all LEDs and 0v lights none. For example: to light LED 3, given that the maximum value of the PWM output is 256, would be:

256/10 * 3

Just tested it with an Arduino and a 100uF cap on the PWM output and seems to work; I get a fairly steady DC voltage output from 0v to 5v. I have no idea if it will be good enough for the lm3914; it's just a matter of giving it a try.

...

Edit: I assume you know already that you have enough output pins on the 16F877a to drive the LEDs without the need for the LM3914.
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
You have a PIC with 40 pins, why not use 10 of them to drive these 10 LEDs and ditch the LM3914?

Otherwise you set the LM3914 to use the internal 1.2V reference, and the PWM to output a pulse with a DC average between 0 and 1.2V

Each segment turn on at a multiple of the 1.2V reference, or 0, .12, .24,.36... 1.08, 1.2 volts. Note these are the transition points, so if you put say .12 volts in you cannot be sure if the lowest segment is on or off.... but it is definitely ON when you put in .12 + .12/2 or .18 volts, so base your increments on a base of .18 volts, or:

.06V+ N*(.12V) where N is the highest LED you want ON.

To produce the DC average you have to set the PWM to an appropriate setting. The general formula for the DC average is:

Avg = Vdd * N / 1023 where Vdd is the supply voltage of the chip and N is the PWM setting.

Thus for an N of 511 you get a DC average of just about 1/2 of Vdd. You can work out the N settings for the 11 states (no LEDs on thru 10 LEDs on) to work with this.

Also you need a "RC" network here not just a C between the PWM output and the LM3914 input. You need a break frequency (1.6/RC) above the PWM frequency more is a better DC but a slower reaction to any change.
 
Top