Author Topic: PIC 18f25k80 interface with LCD VU Meter  (Read 1254 times)

0 Members and 1 Guest are viewing this topic.

Offline Sai ShobyTopic starter

  • Newbie
  • Posts: 9
  • Country: sg
PIC 18f25k80 interface with LCD VU Meter
« on: October 19, 2020, 01:56:32 am »
Hi all,
i am using pic18f25k80 to receive adc audio signal at pin 2(Adc Pin) and want to display the audio range in LCD Display(VU Meter).
I dont know how to start write a code for this. my VU dc ranges from 0-1.17,1.18 to 1.20.... please help me understand and write a code for that.

Thank you
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7544
  • Country: fi
    • My home page and email address
Re: PIC 18f25k80 interface with LCD VU Meter
« Reply #1 on: October 19, 2020, 10:39:03 am »
I've never used a PIC18F25 myself, so I'm basing my comment on the datasheet and the programming specification.  (Note that PIC18F25K80 belongs to the PIC18F66K80 family.)

VU meters indicate the peak-to-peak signal amplitude, with a decay around 0.3 seconds from maximum to zero.

Your microcontroller has a 12-bit ADC, and both single-ended and differential inputs.  It can only sample voltages between AVss (which must be within 0.3V of digital ground) and AVdd (which must be within 0.3V of digital supply); it cannot directly sample negative voltages.  If the signal is actually bipolar – and audio signals usually are –, you'll need to add some resistors and capacitors to shift the input by about 2 volts.  (Why two?  Because then you can use the internal 4V voltage reference, and your input signals must be within ±2V).

Basically, you obtain a chunk of ADC samples (typically about 1 ms of worth), only remembering the minimum and maximum samples.

If the difference is larger than current VU value, you increase VU rapidly – typically setting just VU to the difference.
Otherwise, you decay the current VU value, usually by subtracting a constant value from it (unless it is smaller than the constant, in which case it is just set to zero).

To repeat, typical decay rates (constant) are such that it takes about 0.3 seconds for the VU meter to decay from maximum to zero.

You'll want to use 16-bit (unsigned integer) variables for the samples and the VU meter.
 

Offline Sai ShobyTopic starter

  • Newbie
  • Posts: 9
  • Country: sg
Re: PIC 18f25k80 interface with LCD VU Meter
« Reply #2 on: October 20, 2020, 05:55:52 am »
Thank you, Do u have an idea of setting bargraph of vu voltage, I have set of 10 VU voltages.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7544
  • Country: fi
    • My home page and email address
Re: PIC 18f25k80 interface with LCD VU Meter
« Reply #3 on: October 20, 2020, 07:47:41 am »
To be blunt, I personally would use a dot/bar driver IC designed for this purpose instead, like LM3914.  There is even a helpful article at LearningAboutElectronics, in which an LM3914 is used to display an input voltage (controlled by a potentiometer) between 0 and 5V.

All PIC18F25K80 output pins cannot source or sink enough current to light the LEDs directly.  If you use only PORTB and PORTC (and maybe PORTA7 and PORTA6), you can drive the ten leds with under 20mA each, say at 15mA (=0.015A) each or so.  (These would be pins 9-18 and 21-28 – so almost all! – on the 28-pin SSOP/SOIC/PDIP package; see the datasheet for other packages pinouts.)  For each LED, you'd have a current-limiting resistor; for driving at 5V, 220 Ohm is a very typical choice.  (Assuming a typical 2V forward drop in each LED, the current is (5V - 2V)/(220 Ohm) = 0.0136136A ≃ 14mA.)
Using 10 LEDs with 14mA each you source a maximum of 140mA.  The PIC can source an absolute maximum of 200mA all pins combined, so the ten LEDs at 14mA each is already a bit much.

However, the LED driver ICs designed for this purpose have current-limited outputs, so they don't need any resistors at all.  (Well, you'll need a small potentiometer, or two resistors, to set the current used for each LED, and some resistors and capacitors for the input.)

Of course, there are also LED driver shift registers, like STP16CPC26, which can drive up to 16 LEDs.  Again, a small potentiometer (in voltage divider configuration), or two resistors, are used to set the current used for each LED.  On the PIC, you use SPI (pin 11 for SCK and pin 13 for SDO, on the 28-pin SSOP/SOIC/PDIP package) – and you can chain more than one STP16CPC26 for more LEDs –, and two additional output pins (any GPIO pins will work): one for latch enable, and one for output disable, common to all STP16CPC26's.  So, on the PIC, you only use four pins for any number of LEDs you want to drive.  These work fine with 10-LED bargraphs, but you are not limited to "bars", you can control each LED individually.



To recap, I would personally just use an LM3914, probably with an RRIO opamp like OPA348 to amplify the signal to 0-5V range, a Schottky barrier diode with a very low forward voltage at low currents (say, BAT54 or CUS10S30) to clamp negative voltages to 0V via a resistor... maybe a second Schottky to clamp voltages over 5V to Vdd rail, too.  Input would be capacitively coupled to the opamp, with the clamping diodes between the capacitor and the opamp, so it'd be quite robust for all kinds of audio inputs, I think.

Is there a specific reason you want to use a PIC18F25K80?  Are you writing the code in C or directly in assembly?

If using the PIC is the key, then I'd use two STP16CPC26 and two 10-16 LED bar graphs (for stereo audio!).  For the two audio inputs, I'd use the resistor-capacitor circuit I mentioned earlier to shift the input signal range to around 2V, two clamping diodes to limit the swing between 0V and Vdd, followed possibly by a OPA2348 or similar dual opamp to buffer the input voltage.  (The ADC on the PIC wants less than 2.5k input impedance; the opamp has two inputs in unity gain configuration, providing a low impedance outputs for the PICs ADC.)  The opamp may be overkill, as the ADC really does not need more than 5 useful bits (0-31).  But I like overkill.  The software would again find peaks (ADC minimum and maximum) in each chunk spanning about 0.001 to 0.003 seconds (1 to 3 ms) at say around 10000 samples/second sample rate.  In each chunk, the difference between minimum and maximum is used to update the VU meter state.  (I already talked about the details on that.)

(There are different visual ways for LED bar VU meters to work.  Some are just a continuous bar, some have the peak LED decay slower (so that the bar often has a space and then a single LED);  the bar can be centered instead of starting at the bottom or top; and so on.  I guess this part would be fun to experiment with.)

So, can you use an STP16CPC26 or similar to drive the LED bar?  Or do you need to drive individual LEDs from the PIC directly?



It is difficult to help you, because you provide so little information on your problem.  You say what you want to achieve, but almost nothing about the limitations or requirements you have; this makes helping you difficult.  I recommend you read Eric S. Raymonds How To Ask Questions The Smart Way; there are several translations of it there, too.  It has an emphasis on Open Source, but most of it applies to all sort of technical projects; it's a very useful guide.  If you were to ask your questions in the way recommended in that guide, you'd probably get more answers than from just me; I'm just another hobbyist, and there are lots of experts here.  The experts just don't have the time to try and guess what exactly you are asking, you see, that's why how you ask a question matters.
 
The following users thanked this post: diyaudio


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf