Audio bar graph.  Small! - Page 1
Forum section: electronics / beginners

author: paulca
author_rank: Super Contributor
timestamp: March 29, 2018, 12:44:12 pm
content: I'm looking into creating a small audio bar graph. I'm struggling to find how to make it as small as possible though.The LM3914/5 is only in DIP and no longer manufactured. I can't find a modern equivalent or a surface mount variant.Looking to drive something like these:https://uk.rs-online.com/web/p/led-displays/2465689/So, I think my only options are:Use the LM3914/5 in DIP and mount the LED bar to the other side of the board.Use something like a TLC59282, voltage divider, half recitifer and an MCU. Sounds a bit expensive for a basic audio meter.I would like it to be, fairly accurate, logarithmic and importantly calibrate-able so I can decide what 0dB is.My project will have potentially 5 of these mounted on a panel, I'm hoping to keep the whole project enclosure to 4" square. I suppose to save space I could put all the meters onto one board and use one MCU to run them all.Surely there are self contained audio bar graphs that meet these requirements easily available, I'm just not looking in the right place.

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 29, 2018, 01:11:47 pm
content: Yes, there are boards available, but typically none of them are designed for minimal footprint. As you say, the LM3915/16 are EOL (but the linear LM3914 appears to be still current?) I bought something like 100 LM3915 chips (assuming they are not counterfeit) and there still seems to be a reasonable supply of them. Unless you are designing something for commercial sale in mass quantities.If you are looking for multiple channels, here in 2018 using a small microcontroller is likely the best solution in terms of size. Appropriate microcontroller chips and shift-register LED drivers are available in very small packages. Even microcontrollers with multiple analog inputs and internal multiplexing. The largest components would likely be the filter capacitors for the audio input envelope detection circuits.

author: Cliff Matthews
author_rank: Unknown
timestamp: March 29, 2018, 01:41:54 pm
content: A low cost 30x90mm size could be achieved with 3 of these16-pin 8x8 mini matrixLEDsWith what Richard said, it would likely require 3 stacked PCB's behind it though..

author: paulca
author_rank: Super Contributor
timestamp: March 29, 2018, 02:01:21 pm
content: Quote from: Richard Crowley on March 29, 2018, 01:11:47 pmYes the idea to combine multiple channels came late in the day, middle of my message actually. I kind of excluded a uC because it would be expensive, but if I create a panel mount PCB with 5 bar meters on it and feed them from headers on the main board one ATMega could run all the bar graphs. As I ditest multiplexed displays I could use TLC59282s to run 16 LEDs each.For audio level, I have done the less than accurate cheating type for reading audio level (diode half rectifier, then loop 10 readings and take the max). I gather this would make the meter a peak meter, which thinking about it probably fine for my purposes. An RMS meter might be a bit more tricky.On impedance of the meter, so it does not interfere with the audio signal progressing to the amplifier, if I make the required voltage divider from high value resistors of 100k+ is it likely to interfere? Given that the opamp has a higher impedance input, will the level meter not alter the signal?

author: paulca
author_rank: Super Contributor
timestamp: March 29, 2018, 02:02:51 pm
content: Quote from: Cliff Matthews on March 29, 2018, 01:41:54 pmInteresting, one of those would do. A single MCU to drive it, but a mess of current limit resistors or an LED driver and a multiplexer.Actually the 8 works quite well as I want 3 mono levels and one stereo, so I can use the as L-L-L-LL.EDIT: Actually the lack of colour is an issue. Want green-yellow-red.

author: Cliff Matthews
author_rank: Unknown
timestamp: March 29, 2018, 03:15:22 pm
content: Bi-color matrix LED's are available.. I don't know if there's a library for them though.. *especially since getting the right shade of yellow requires even more code, so a Holtek or similar driver could work?https://learn.adafruit.com/adafruit-led-backpack/bi-color-8x8-matrix

author: MarkF
author_rank: Super Contributor
timestamp: March 29, 2018, 06:37:53 pm
content: If you are going to be using a MCU, just use a small OLED display and draw the number bars in the proportions and colors you want. For example the1.27" OLED Breakout Boardfrom Adafruit. Imagine the color bars in the attached photo on their side with breaks between each color band. You could draw each bar to look like VU Meters with or without segments. A display would also allow you to add some annotations for each bar.They're larger1.5" OLED Breakout Boardis square and would allow for text below each bar.They are a little expensive but generate all the necessary voltages needed for the OLED and provide 5V compliant signal levels. I have a couple and like them very much.

author: ebastler
author_rank: Super Contributor
timestamp: March 30, 2018, 10:39:21 am
content: Some nice ideas regarding display option. But it seems to me that the challenge may not be around the display (paulca would be happy with the LED bars, right?), but around the A/D conversion?Paulca -- would the built-in ADCs of typical microcontrollers be good enough for your purpose? You mentioned log scale, but did not specify the dynamic range you are after.If µC ADCs are adequate, I would defnitely suggest a suitable µC. Then either display via SPI on an OLED, or via matrix drive or charlieplexing (directly from the µC) on discrete LEDs.

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 30, 2018, 11:06:05 am
content: Even 4-bit resolution is adequate for 16-step linear display. 8-bit resolution is more than enough for logarithmic,10-step display. Linear to log conversion can be done with simple integer arithmetic or lookup-table. Even ballistics can be done digitally with a microcontroller of modest power. And average/RMS + peak display, etc. The 10-bit resolution of even the cheapest Arduino is overkill for this application. And sample rate of 100 Hz is more than adequate for a modest 10-step display. So even a microcontroller costing <$1 would do the job for at least 2-channels of stereo and a display 2-3x the steps that @paulca proposes.The benchmark for digital display of audio levels is the Dorrough loudness meter....https://youtu.be/yI3_BCDmnzw

author: ebastler
author_rank: Super Contributor
timestamp: March 30, 2018, 11:15:00 am
content: Quote from: Richard Crowley on March 30, 2018, 11:06:05 amI fully agree that you can fill a 10-step log display in a meaningful way using 8 bit input data. But we don't know what paulca is after, right? Also, paulca mentions the need to adjust the 0dB level (which should be done in software, I think), and we don't know the desired headroom for adjustments.

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 30, 2018, 11:26:44 am
content: The most intriguing audio level display circuit IMHO is this one which uses a simple comparator and a string of shift-registers.https://www.eetimes.com/document.asp?doc_id=1225971

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 11:54:31 am
content: So, I'm still working through numbers (struggling with some of them).For now I'll pick 0.615Vrms as 0dB. So that means a rectified VPeak of 0.870V (minus diode drop)... which straight away I can see is a problem requiring a good schokty.... or I just give the MCU the negative and let it ignore it and hopefully not fry it.This gives me the following values for the LEDS:Vrms Vpp VpkVref 0.615 1.740 0.870dB-12 0.154 0.437 0.219 Blue-9 0.218 0.617 0.309 Green-6 0.308 0.872 0.436 Green-3 0.435 1.232 0.616 Green0 0.615 1.740 0.870 Green3 0.869 2.457 1.229 Yellow6 1.227 3.471 1.736 Yellow9 1.733 4.903 2.452 Yellow12 2.448 6.926 3.463 Red15 3.458 9.783 4.892 RedWhich nicely fit under the +5V max. With an 10 bit resolution of 4.8mV and the smallest step (-12dB to -9dB) being 90mV I should be more than fine with the AVR 10 bit ADC.This covered "internal levels" of the project based around the Line level -2dB figure of 0.615Vrms taken as the 0dB reference.For the master output level things are different. I calculated the sound pressure levels of my headphones based on their sensitivity and found that -15dB is not going to cut it. To give me a usable indication of "loudness" I would need something like:Given dbSPL = sensitivity(db/V) + 10*LOG10(Vpk)db Vrms Vpk-120 0.000 0.000 - 53dB (quiet conversation)-100 0.000 0.000-80 0.000 0.000-60 0.001 0.002-40 0.006 0.017-20 0.062 0.1740 0.615 1.740 - 113dB ( loud rock concert )20 6.150 17.397 - 124dB (Dumb and dangerous! Not possible with the circuit I should add and it will be diode clamped much lower)And there is the problem. Anything much below -40dB would not be measurable by an MCU with a 5mV resolution, but I can't gain it or the 0dB level will bust the 5V limit.Might need to reconsider this meter or abandon it altogether and just use another Line level meter.Of course, as I said, I'm stuggling a little with the maths, so some of my calculations could be out.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 12:13:03 pm
content: This has to be wrong..dbSPL = sensitivity(db/V) + 10*LOG10(Vpk)Surely.-120dB sound level should be practically muted.Resulting in 1uV through 76Ohm = a few nano amps so it can't produce "conversation level" through headphones.I'm missing part of the puzzle obviously.Hmmm.. Anyone know how to calculate db SPL when given:Sensitivity 114.6 dbSPL / Vand a Vrms or Vpk?

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 30, 2018, 03:24:19 pm
content: Quote from: ebastler on March 30, 2018, 11:15:00 amRight. @paulca has not revealed his application. For example, my application is to monitor recording levels for audio and video production. It is quite common in modern digital gear to put 0dB at the top of the range. Hence the term dBFS (deciBels Full Scale).The old traditions of some reference voltage/impedance/power for "0dB" is relegated to ancient history of telephone lines 100 years ago. And analog (mag tape) recorders of 50 years ago. But this is the 21st century and we aren't constrained by tape saturation, etc. What we ARE constrained by is the very hard limit of the analog to digital converter. When you have reached Full Scale, you are out of bits and hard clipping ensues.Nobody who is doing any kind of practical recording cares about -120dB because that is "down in the mud" of the noise floor of the circuits in the signal chain (starting at the microphones). So is @paulca trying to design some kind of Sound Pressure Level (SPL) meter? Even those don't have a continuous range from -120 to +120dB. They use segmented ranges for better circuit optimization and measurement/indication resolution. So, we are all just shooting in the dark trying to imagine what @paulca is trying to do here???

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 03:58:57 pm
content: The purpose is to show line level at different stages in a mixer circuit. Post pre-amp, post mixer amp, post master volume. Primary purpose is to flatten the gain structure to around 0dB.Richard, if the db scale is not reference to an arbitary value, what exactly is it referenced to? Have I missed the point of dB completely?Forget the output level meter. I was trying to show the full range of output that would go to headphones. I was considering putting a meter on the headphone output level, but as per my last post the headphone amp will be working in much lower db levels.Also I think my equations where wrong. The effective SPL values don't make much sense.The -15db to +15db line level meter is the important one.As that equates to a range maxing out at under 5V I should be fine with the AVR 10bit ADC.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 04:36:40 pm
content: So if I have a bunch of 10 segment LEDs for the bar charts. Some AVR code using the ADC, that leaves 3 things.1. Meter impedance2. Rectification3. Correct measuringFor 2, my options are, just put both the positive and negative side of the audio signal directly onto the MCU pin and hope it doesn't upset it or half wave rectify it with a diode and factor the voltage drop. The later raises questions about the meter cutting out below the Vf of the diode. The former raises questions as to how much negative voltage the MCU pin will take before bad stuff happens.For 3, is it acceptible to measure peak voltage by looping and taking the max, or is a correctly sized capacitor/resistor required to measure effectively RMS voltage.2... I don't want the meters to interfere with signal. The signal in all monitoring points will be between opamps, so should I put something like a 4 Meg resistor on the meter signal input. EG:Measure point --> 4Meg --> AVR ADC Pin.Is this enough to prevent any alteration to the signal?Am I missing the point entirely?

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 05:33:42 pm
content: Slowly think things through. Remember you have a MCU with ADC. You will be able to do simple math with the sampled signal, sampled at CD audio bandwidth, since you may want to have software filtering and total control and even extended features with the source audio analysis. Also remember about input current and biasing, maybe an optional LPF if you aren't sampling at full bandwidth.Also remember, MCUs are cheap. Do not try to save 2$ on one if a double speed, or 32 bit one is available.If you get to a schematic stage, you'll get plenty of additional help here.

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 30, 2018, 05:42:11 pm
content: A Bel (or as we use it more commonly, a 10th of a Bel or a deciBel) is:QuoteYou seem to be measuringdbV? (decibels relative to 1V)https://en.wikipedia.org/wiki/Decibel#VoltageOr perhaps other audio-specific values?https://en.wikipedia.org/wiki/Decibel#Audio_electronicsMeter impedance is pretty much a relic of 60-80 years ago when they had a standard dBm (relative to 1 milliwat across 600 ohms where 0.775 volts = "0dB". You seem to want to measure audio voltages at various points in the signal path where a high-impedance voltage-referenced measurement would make the most sense.Simple fast-response analog rectification and basic filtering/integration would seem to be the most appropriate to produce a DC voltage that accurately represents the audio signal envelope. You can do other things (like "ballistics", peak-indication, etc.) in software.Correct measuring (presumably you mean calibration?) is just a matter of setting the analog gain and software arithmetic so that your indicator reads what you want. This can be done in hardware (trim-pot) and/or in software (gain setting values) etc.Note that a measurement reference of exactly 1.0V may not be ideal for whatever you are doing. Perhaps your full-scale reference should be set at the maximum signal your circuit is capable of before clipping. That probably isn't exactly 1.0V

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 05:53:28 pm
content: Quote from: Richard Crowley on March 30, 2018, 05:42:11 pmQuote from: Richard Crowley on March 30, 2018, 05:42:11 pmJust doeverything, A->Z, everything you can possibly imagine under the sun, even theoretical physics, even destroy the universe, all in software... Take this leap, and you will thank me in the future. Go with the first option above, and you will never know...

author: Richard Crowley
author_rank: Super Contributor
timestamp: March 30, 2018, 06:00:07 pm
content: @BrianHG, how we would get an accurate measurement of the audio envelope with only positive-responding inputs to an ADC in a uC? Especially when audio waveforms are notoriously asymmetrical. I completely agree that here in the 21st century we should as much as possible in software. But I am not seeing how to do that with your average DC ADC?And, sampling the raw waveform would require a much higher sampling rate to accurately catch short peaks which would require a faster (more expensive) ADC and/or uC would it not?

author: Bassman59
author_rank: Super Contributor
timestamp: March 30, 2018, 06:15:32 pm
content: Quote from: paulca on March 30, 2018, 03:58:57 pmThis is standard in audio mixers. The most important test point is right after the preamp, before the fader, which is why the button is called "pre-fader listen" or PFL.QuoteInside a mixer, the levels really arbitrary. Pull up the user manual of any analog mixer. It should include a diagram of the internal gain structure. The input level meter (either on the channel strip, or the main meter when you press PFL) has a 0 dB position, or unity. This level represents a compromise between noise performance and clipping. That is, not enough preamp gain up front means you might be pushing the output levels up, boosting noise. Too much preamp gain means you risk clipping not only the preamp itself but the summing amps downstream. That second point is often not understood. You have to allow for more mix bus headroom when you're mixing 40 channels than you need when mixing only 16. A lot of people say, "Well, on the Midas H3000 you have to run the inputs way up into the red to get it to sound good." Well, that's because the thing is designed to handle, what, a hundred inputs to mix? You have to goose up the input gain to get something to come out the output!See the attached, it's the gain structure for an Allen & Heath GL4000. Conveniently, its internal gain structure is 0 dB = 0 dBu (or 0.77 Vrms).So the point, of course, is that you set all of your input gains such that all of the inputs are at the same level on the PFL meter. And then you use the faders to set the mix level for each input.

author: Bassman59
author_rank: Super Contributor
timestamp: March 30, 2018, 06:23:43 pm
content: Quote from: Richard Crowley on March 30, 2018, 06:00:07 pmYou have to drive the ADC appropriately. If the ADC has a 4 V span and a 2.0 V offset, your ADC driver has to level-shift the audio up 2 V while likely attenuating to fit within the span. Configure the micro's ADC to give you a 2's complement result, and then the standard absolute-value function gives you a positive result which you can averageQuoteCheap micros have 10-bit ADCs that run at 250 ks/s or 500 ks/s. With the former you should be able to mux and sample four channels.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 06:25:12 pm
content: Quote from: Bassman59 on March 30, 2018, 06:15:32 pmThis is exactly why I want these meters.The Small signal audio design book uses resistor divider ladders, LEDs and BJTs. For 5 meters this will result in a board about 4" square. Much like a meter panel on a large desk.I want it in 2" square or so.Using "one" and PFL or "meter select" switches is an option, but LED bar graphs are fairly cheap and small.

author: Bassman59
author_rank: Super Contributor
timestamp: March 30, 2018, 06:26:47 pm
content: Quote from: paulca on March 30, 2018, 06:25:12 pmThe size of the meter board will be dependent on the size of the LEDs used for the display. You can fit the micro and support circuitry on the back of the board.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 06:30:39 pm
content: Quote from: Bassman59 on March 30, 2018, 06:23:43 pmInteresting. Can I just AC couple it with a cap and lift the ADC side with a virtual ground to +2V. I'm thinking Arduino 10bit 0-5ish volt ADC.Is the difficult bit not then calibrating it? That virtual ground would need to be very accurate. to get accurate readings or am I over thinking it? If I make the virtual ground the AREF that might work.

author: Bassman59
author_rank: Super Contributor
timestamp: March 30, 2018, 06:42:49 pm
content: Quote from: paulca on March 30, 2018, 06:30:39 pmUse your Google. There are plenty of examples of level-shift circuits out there.QuoteIf you want accuracy, you need an accurate voltage reference.

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 06:50:36 pm
content: Quote from: Richard Crowley on March 30, 2018, 06:00:07 pmOk, step #1, looking at the source signals, the OP wants to analyze at least 4 stereo sources, line out, headphones out, line in gain, second line in, that 8 sources. (Ok, you may be forgiven that since I know this project is designed to fit into his pre-amp with headphone project...)He wants to save space. How many op-amp/diode/filter bridges will be needed here? I still agree using 2 low voltage R-R quad j-fet input opamps, biased to 1/2 vref or VDD in voltage follower mode, series fed through DC blocking cap and 100k or 1 meg resistor.Step #2, AC biased fed into 8 channel ADCs just means in software, he only needs to read the absolute value of the ADC reading to get a positive only peak info, but we can obviously take this further.Now to the grunt of your question, processing power. Take for example a Microchip ATSAM4S2AB in 48 pin QFP, it has 12 bit ADC, 1MSPS, with 8 inputs (definitely fast enough for 8 channel at 44.1khz sampling), running a ARM Cortex-M4+ CPU at 120 mips for 3$. With this chip, forget silly VU meters, he can run 8 parallel, 256-point full spectrum analyzers in parallel with that small OLED full color display.Now, if 3$ is too expensive, he can go the Microchip's 1.50$ ATSAMD20G14B, but it's 48mips core but the ADC with 350Ksps, say he can safely sample 6 channels at 44.1khz, or 8 channels at 40khz, and only produce 2 channel 256point fft spectrum analysis.It even catches me off guard how much can be achieved with a 3$ MCU today with 32 bit, 120 mips as I still look for analog simplification for some designs thinking I have only a few hundred samples/second speed as a limit. Back in 1988, on my Amiga 1000 with a 7mhz 16 bit 68000, averaging 4 clocks per instruction and an 8 bit sampler on the parallel port, the best we could do was a mono 64 point real-time FFT bar scope on display with a 20khz sample rate. Today's 3$ MCU with many 32 bit instructions taking 1 clock at 120Mhz, consuming a few ma at 3.3v, with 128k flash rom onboard would run circles around my old favorite computer.Ok, look, enough said here. I know a 3$ 48 pin TQFP IC may be too much for some to deal with sampling sound, or how to use a cap ad a DC filter to bias the audio coming in at 1/2 VDD. All I know it it will take many more parts, board space & give you less opertunity to go with a similar priced or more expensive much slower MCU with slower ADC and work out 8 copies of an analog front end so the MCU samples just a peak signals just to drive a display when the math involved to take the ADC reading and convert it to an absolute value & do any log computation to give you a true peak can be readily adjusted all so easy in software with nothing more than 1 gain figure & 1 decay time value for the meter drop down decay speed.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 07:08:16 pm
content: Brian. You are always trying to tease me to the extremes.I am too jaded by my career to be that kind of engineer. I know the 80/20 rules. 20% the effort gets your 80% the results. The other 20% takes you at least another 80% of your time and effort.To be honest I don't think I even have the ability to detect the 20% difference.This probably flies in the face the standard EE grey beard approach, but for a first iteration of a concept I just want "close". I don't want to create an audio reference meter that is +-0.5% across all temperatures and bandwidths, I just want to know if I have any signal, if it's a quiet signal, I'm at unity gain, pushing it a bit or flashing red warning lights.Thus, sampling 3 mono inputs (left channel will do), one stereo master, gives me 5 channels and the sample rate will be whatever I can get an ATMega to do.

author: schmitt trigger
author_rank: Super Contributor
timestamp: March 30, 2018, 07:30:21 pm
content: Not a small VU-meter, not a suitable VU-meter for your project, but a beautiful VU-meter design nevertheless.Using Soviet IV-9 neon bargraphs.I include it here only as eye candy:http://www.tubeclockdb.com/non-clocks/332-iv-9-vu-meter.htmlUnfortunately the kit is no longer available.

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 07:52:12 pm
content: Quote from: schmitt trigger on March 30, 2018, 07:30:21 pmNice!

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 07:59:38 pm
content: Quote from: paulca on March 30, 2018, 07:08:16 pmI didn't mean you had to go to extreme, but, feeding 8 audio lines through a 0.1uf cap with a resistor ad the ADC input to 1/2vdd to the 8 ADC inputs on the mcu, you can make the stupidest 4-5 paragraphs long meter software and it will still work. The ATMega may still be fast enough to do this as well. I was trying to get your component and PCB area and assembly cost down to 1 IC and 18 resistors and 9 caps. How you chose to read the inputs would be up to you, but, you would have 8 balanced equal loads on all your audio sources. No trimpots, no opamps, and a high enough sample rate that there would be no audible CPU noise fed back to your audio source.

author: paulca
author_rank: Super Contributor
timestamp: March 30, 2018, 08:16:40 pm
content: Okay, I starting to see what you mean.Cap with resistor to "ground" to AC couple and change the level. Each channel on an ADC pin. Do the rest in software. "Ground" being +2V.You spec 8 channels, interesting. The rest of the project has been split into modules. When prototyping I have noticed that individually they form useful boards, but present more options as individual boards. Things which in the overall project are hopefully fixed can be variable in the sub modules. In this case making a 5 channel display for a 5 channel project, easily becomes, make an 8 channel display for any project.It brings me back to MoSCoW.Must - Must have this time around.Should - If you can make it happen.Could - If it presents itself as a side effect.Won't - Have this time around, probably.I don't imagine going from 8 to 5 changes the concept though.

author: ebastler
author_rank: Super Contributor
timestamp: March 30, 2018, 08:19:47 pm
content: Quote from: paulca on March 30, 2018, 08:16:40 pmErr, no -- you will needtworesistors per channel, connected as a voltage divider between VCC and GND, to set the midpoint of your signal at 1/2 VCC (or where the ADC's operating range wants it). Then feed your signal to the junction of the two resistors, via a cap.

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 08:41:16 pm
content: Also, no matter what system you choose, when feeding audio from your pre-amp to your digital PCB, if you will be using series resistors for noise isolation, place those resistors on your pre-amp board.The 1/2 vdd v-ref bias resistors go on your digital pcb. (Note, the ADC in the MCU is configured to go from GND to VDD, I would place the 100k on your preamp board near the audio connector leading to the digital VU meter board. That resistor prevents backward noise and protects the input of your micro's ADC.)vdd ------------------------|1meg|audio-100k --- 1uf ----*------ adc pin|1meg|gnd -----------------------If your ADC is 12 bit, then no sound = 2048. With a positive signal, this number will increase to 4095, with a negative signal, this number will decrease to 0.If you want the absolute value: (This is 50% of you code right here)LOOP-----------------------------------------------------------------------------------------------------------(Sample ADC)if the ADC >= 2048, then meter_absolute_DC = ADC - 2048else, meter_absolute_DC = 2048 - ADCNow, meter_voltage = meter_absolute_DC * CONSTANT-ADC-VOLTAGE-FACTORif meter_peak > 0, meter_peak = meter_peak - CONSTANT-METER-DECAY-SPEEDif meter_peak < meter_absolute_DC, meter_peak = meter_absolute_DCRender meter changesEND LOOP-----------------------------------------------------------------Well, you can do an 8 channel array sub-loop in the loop, or make the loop sample 1 channel at a time incrementing once each call to gather all 8 meters.You only need to render meter once every few thousand samples, or, depending on sample speed.You can average a left and right meter peak together for a mono meter display.You can put the meter peak through a linear to log, or any db table when driving your display to get a dbv meter.The sampling loop can be a timer based interrupt call for smooth sampling while the render meter can be continuously drawn to the led's as fast as possible, or on a second timer.

author: BrianHG
author_rank: Super Contributor
timestamp: March 30, 2018, 08:57:38 pm
content: Also, you can place a 1nf cap to each ACD input & GND to remove high frequency noise and bounce reading on the ADC. If you are sampling at 20khz-10khz, change this to a 10nf cap to remove high frequency.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 07:28:38 am
content: Thanks for the help Brian. Think I have everything falling together.Speaking of falling, was I was considering using acceleration for the peak hold decay, but with only 10 LEDs, it won't really be that impressive a feature and probably a constant decay would look as good. If I had 25 LEDs adding gravity to the peak hold decay would look cool.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 11:36:36 am
content: That fastest I can get an ATMega to read 8 channels is at 32Khz. Which results in only 32Khz/8 per channel. 4Khz.This requires setting the ADC pre-scaler to the minimum that would still swing from 0-255 for 0V-5V without error. There are faster ADC Clock prescalers but there is not enough time for the voltage to settle and they produce errors.That would leave me using a capacitor on the ADC pins to hold the average voltage... and make the results a little unaware of higher frequency spikes/pulses. EDIT Actually, a capacitor would only work if I recitified the signal.It also reduces the resolution to 8 bits. I might push a few more kHz by using a 20Mhz crystal.Hmmm. I'm wondering if the STM32 goes much faster. Not sure I want to start learning a new micro-controller. How bad is sampling at 4Khz?

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 11:49:42 am
content: Hang on...If I spin read one channel at 32Khz for ten samples, then send the max abs value to the display, that gives me 32Khz sampling per channel to detect peaks. Just not sampled continiously, but taking the average level over a window periodically.It would give me a display update rate of something like, 320uS, call it 500uS once I write to the display. All 8 graphs updated in 2ms.EDIT: In fact as I'm only reading one channel I could probably bump the prescalar up another factor of 2 as I won't be switching between wildly different voltages. It would mean delaying between channel switches to allow the ADC to settle though.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 11:57:10 am
content: Ooops. It's worse than I thought.I forgot to include the delay caused by Serial.print();When I print the values, which delays the ADC, I only get to about 2kHz before the channels start cross talking.

author: Cliff Matthews
author_rank: Unknown
timestamp: March 31, 2018, 01:19:05 pm
content: Time to get more H.P... it'snothing 14usd can't fix and relatively painless(and Danadak would approve..)

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 02:34:29 pm
content: I was thinking more about the STM32 which has two ADCs, 16 channels and should be capable of 1Msps. It's ADC offers a lot more functionality in hardware, such as writing to memory with DMA, auto sequencing, interlacing etc.It is also quite a bit more complex to set up than the ATMega.I happen to have an STM32 Blue Pill board so I might have a play with it when the notion takes me again.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 07:28:34 pm
content: I'm getting cold feet on this full rate audio ADC method.Here is why. It's going to be a right pain getting 8 channel ADC reads to ensure I get the full 44kHz sampling of each channel. Not necessarily due to the sample rate of the ADC, but the analog bandwidth of the ADC multiplexer. With 2 adjacent channels being either muted or at full volume the ADC voltage swing has to be fast enough to swing between a high value and a low value.It's this limit I am hitting with the AVR, not the outright sample frequency which can go faster.And lets say I so achieve that, what is going to be the output of this full spectrum audio sampling? I can't update display at 44kHz, that would be pointless. So I am going to sample the data at a much lower frequency, like 100Hz by taking the max(abs()) value from 100Hz window.So I need the peak value within a 1/100Hz period.This is telling me to implement some form of peak hold on each ADC pin and sample them at a much lower frequency.A peak hold circuit with a mosfet to reset it. I can use a 8 channel multiplexer to reset the channels.Read Channel 1, Discharge Channel 1, Charge Channel 8Read Channel 2, Discharge Channel 2, Charge Channel 1....Read Channel 8, Discharge Channel 8, Charge Channel 7Then sample them in sequence at a much more modest 800Hz using an interrupt while the display routine runs at 100Hz in the main thread.It requires a reset-able peak hold circuit on each ADC pin though. Means analog electronicsLooking at peak hold circuits, it will require 2 op amps per channel, but I was probably going to end up with buffer amps so sink/source current to drive the ADC analog side faster anyway. Diode drops. Most of the complaints around speed seem to be referring to frequencies much higher than 20kHz where the charge rate of the capacitor and the current the opamp can supply become limiting factors.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 07:44:00 pm
content: I think this will help me.

author: BrianHG
author_rank: Super Contributor
timestamp: March 31, 2018, 07:52:49 pm
content: Funny that your Analog MUX & sampler doesn't do a quick sample and hold. It would be odd if the 1Mhz ADC was specifically designed not to be able to be used across multiple inputs, including a feature to sample multiple inputs automatically updating multiple registers all on it's own, otherwise, no one would ever be able to take advantage of such a high speed sampler. It would be silly if using 1 ADC input and an external 74HC4051 8:1 analog mux would work 10x better than using the MCUs internal MUX which should be identical and faster which sounds silly.Some bandwidth lowering techniques (I guess obsolete since your MCU is too slow): you can series mix L&R to mono by sending the left and right to the same ADC pin after the 100k resistor. This brings you down to 4 channels to sample. At the ADC pin, add a 10nf-47nf cap, this bandwidth limits you input to around 5khz (assuming you are using 100k series resistors) This may still be too fast for your MCU. I'm so used to using PIC which runs circles around Arduino boards. Sampling 44k 8 channels is a laugh.Even the Atmega 120mips chip I listed a page back should run circles around your needs, but, it is always easier to use a MCU you are used to.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 08:21:52 pm
content: It could be my test circuit or interruption of the measurements.To test it, I ran the ADC in Interrupt enable mode, single shot. Within the interrupt I increment the channel, increment a counter and start the next conversion.The AVR does not do auto sequencing of channels and running it in free running mode gives you race conditions with the channel switch, so you can't guarantee which channel you are reading. The datasheet suggests updating the channel while the ADC is not auto trigger or free running.In a separate timer interrupt triggered once a second I print, then zero the counter.I used this for the outright samples per second.Then to check the values where correct I connected:ADC0: GNDADC1: +5VADC2: GNDADC3: FloatingADC4: FloatingADC5: 3.3VYes I was only doing 6.... with direct dupoint jumper links between pins.And checked I got stable and sensible 8 bit values, printing them out in the ADC interrupt routine.At a clock division of 64, I was getting figures like 254, 0, 254, x, x, 171At a clock division of 32, I was getting figures like 252, 0, 252, x, x, 168At a clock division of 16, I was getting figures like 221, 22, 221, x, x, 123 <- effectively randomised by the floating pin.I thought 16 was the limit, or beyond and took it's Sps of something like 39k.However, realised the delay introduced by printing the serial values to the screen in the ADC interupt delays the next conversion, giving the ADC sample and hold circuit time to change, the actual sample rate, which was starting to error, was thus, much, much lower.I tried running the serial at 1,000,000 baud, but that just practically crashed the Arduino IDE and didn't improve much.This was tested with an Uno clone, not a raw AVR on a breadboard.

author: BrianHG
author_rank: Super Contributor
timestamp: March 31, 2018, 08:42:04 pm
content: What happens if you accumulated 1000 samples, then do 1 print?Isn't the print command way to slow anyways, I mean it has to convert binary numbers to base 10 decimal, then ascii, then all the serial port buisness. It may have been faster to convert a single set or all in sequence of the 0-256 to 8 levels, sent to 8 leds on an 8 bit io port, + a separate IO pin for a horizontal trigger & scope it & see it. If you have a high speed DAC output pin, just push the raw ADC value, you can make on your scope 8 vertical VU meters from left to right on your scope this way.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 08:43:54 pm
content: Quote from: paulca on March 31, 2018, 08:21:52 pmHang on. I was delaying, then changing the channel and immediately reading. So the effective sample rate would not be that much lower at all.Still full spectrum sampling digitally will require 352Ksps across the 8 channels, so it won't work on the AVR.

author: BrianHG
author_rank: Super Contributor
timestamp: March 31, 2018, 08:47:11 pm
content: Quote from: paulca on March 31, 2018, 08:43:54 pmYou only need 20khz/channel. 40khz is overkill and audio frequencies above 10khz are negligible VU meter wise in audio.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 08:50:10 pm
content: Quote from: BrianHG on March 31, 2018, 08:42:04 pmI considered this. Windowing. Read one channel for T time and display the peak. Then read the next.The trouble with that approach is it creates a high pass filter on the meter. To make sure and get the peak value of a 20Hz signal you have to sample for a 50ms window. At 200Hz a 5ms window. Display 8 channels at a sensible update rate would give me poor readings at low frequencies. 5ms*8 channels gives a refresh rate of 40ms, 25fps, which isn't all that bad. 50ms * 8 however is 400ms and 2.x fps, poor.

author: paulca
author_rank: Super Contributor
timestamp: March 31, 2018, 08:57:43 pm
content: The peak hold circuit simply moves the job of detecting the peaks out of the uC and into the analog space. It is the peak detection driving the requirement for high sample rate. An analog circuit even just a diode and capacitor takes that burden off the MCU for a few pence. Then I only need to sample and reset those hold circuits at the display update rate.The opamp gets rid of the diode drop. (Thanks Dave!). Most of the other improvements to make it precise probably don't interest me for the application.It does make it + peak only, but I can live with that.

author: paulca
author_rank: Super Contributor
timestamp: April 01, 2018, 10:47:09 am
content: I had a crack with a peak detector circuit, bare bones of course.First time I've used my signal gen in anger.Everything was looking like a win until I muted the input.A 300mV offset on the output. So a muted channel will read VGnd+300mV which is pants. (Yes I shorted the cap to be sure, even removed it)I suspect I need to use a different opamp, the NE5532 comes nowhere near close enough to it's rails. Depending on how you read the datasheet it could be as poor at 2-3V off the rails. I dropped the VGnd to 1V as I'm only concerned with the top half of the signal. This was due to the NE5532 reaching it's upper limit around 3.4V (on a 5V single supply).I don't want to give the opamp feeding the ADC a rail higher than the ADC input.Thus I will need to see if I have any closer to rail-to-rail opamps lying around and maybe spec one for the project. Doesn't need to be "good", but does need to be rail-to-rail.I also found on the breadboard the caps discharge a lot faster than I expected with only the scope impedance and the diode leakage as a load I had to go up to at least 1uF to get a hold on 100Hz and 10uF to get a hold on a 10Hz SyncPulse. Of course then I hit the opamp current limit and it can't charge the cap fast enough, so I don't get the absolute proper peaks. I can hopefully assume a lot of the leakage can be removed with a better diode, an output buffer amp and not building things on the breadboard.

author: paulca
author_rank: Super Contributor
timestamp: April 01, 2018, 02:06:23 pm
content: Right I went through a handful of different opamps I had.LM358 sort of tracked okay at lower frequencies, but went nuts in higher frequencies and by 20kHz was reading practically zero.TLE2142 Always seemed to read high, also seemed to have a very high input impedance as the cap didn't discharge very quickly at all. However it suffered from a DC offset at lower levels and lack of tracking at higher frequencies.LM741... just no.So I came back to my trusted NE5532 and gave it a higher rail, 9V. It definately drains the cap faster, but I think a 1uF MLCC is enough if I'm sampling at 100Hz as the peak detect is near perfect with only about 50mV droop at 20Hz. Above 10Khz it introduces a small artefact at the peak which seems like the opamp lags behind and then spikes to catch up, then oscillates, but it's a very minimal number of mV.I was hoping to keep the rails 5V so the peak detect circuit would clip anything the ADC would not like.Can anyone suggest a decent RRIO opamp for this purpose, given that the LM358 is supposed to be pretty close to RRIO but didn't work and the TLE2142 goes to Vcc- +0.1V and it produced a DC offset at low levels.Beyond that the wider project will have the higher rails for the NE5532 and I can clip the output of the peak detect circuit other ways if needs be.

author: BrianHG
author_rank: Super Contributor
timestamp: April 01, 2018, 02:43:00 pm
content: Just power your opamps from you +/-15v supply.

author: Zero999
author_rank: Super Contributor
timestamp: April 01, 2018, 07:46:46 pm
content: Quote from: BrianHG on March 30, 2018, 08:41:16 pmYou could use a virtual earth/ground IC, such as the TLE2426, or if there's a spare op-amp, that could be used to buffer a potential divider, then you only need one 1M bias resistor per input,

author: paulca
author_rank: Super Contributor
timestamp: April 01, 2018, 08:02:14 pm
content: I've decided to go with the peak detector circuit, so I don't need the virtual ground as the peak detect (in simple form) is half rectifying anyway.I did get a prototype working. With a number of caveats.Using the NE5532 as it worked best I can't approach the lower rail, so I added a virtual ground to add a DC offset of about 1.8V and ran the opamp on a 9V rail. This meant i could only measure about 3.2Vpk due to the 5V limit on the ADC.I didn't implement the multiplexer to reset the peak hold yet.When I coded it up, subtracted the offset and turned it on it is very convincing. It will need calibrated and the code ironed out a little.The Arduino ADC pulls the peak hold cap down fast, even with a 100k resistor in series. So I might need to go up a few cap sizes. In the prototype I'm only sampling one channel, so it's fine, but sampling 8 channels I need the peak to hold longer.For the actual project I am going to take Brian's suggestion and just power the peak detect opamps from the +-15V rail to avoid issues and clip the output at 5V, or maybe 5.5V so as to ensure I get the full ADC but don't upset it too much accidentally dumping a spike of +15V into it at power up/down. Clipping via diodes or LEDs with an DC offset from a trimmer.I have so many building blocks in this project, most of them progressing, I am getting more and more concerned about how to systems engineer it all together at the end. I suppose that's the point though. Set a challenge and chip away at the details until all is left is to put it all together.

author: paulca
author_rank: Super Contributor
timestamp: April 01, 2018, 08:19:07 pm
content: Excuse the horrible audio recording, but it does work! Based on the peak voltages the LEDs are fairly close to expected too.Oh and a set of Pixel LEDS was so much easier than wiring up a 10 segment bar LED.

author: Audioguru
author_rank: Super Contributor
timestamp: April 01, 2018, 10:54:36 pm
content: Paul, in your first post you mentioned the obsolete LM3914 that is a linear voltmeter. An LM3915 is a logarithmic audio level meter circuit with 3dB steps and a range of 30dB for its 10 outputs. They can be cascaded for a range of 60dB or 90dB. Many shops and kits still have some LM3915 ICs in the DIL package. Its datasheet has schematics of average and peak detectors.

author: paulca
author_rank: Super Contributor
timestamp: April 02, 2018, 05:43:15 pm
content: I'm just wondering if I can make it smaller. I would need 8 x LM3915s.It's still an option though.I looked at making the 8 x 10 segment display with an MCU and after hitting a few dead ends, I came up with this:Requires only 3 MCU pins. Allows up to 50mA per LED block, 5mA per LED.My first attempt was with 5 LED drivers and a non-multiplexed display, which would be fine and take a lot of the burden off the MCU while it samples the ADC, however the peak current consumption could be as high as 160mA even if only 2mA per LED is used. The power supply for the whole project is 200mA and I'm already concerned about it, so unless I power the meter board separately, 160mA is too much.My second attempt was to use two LED drivers to multiplex, but that was quickly aborted as all LED drivers are current sinks, not current sources.My third attempt was with the 4067 multiplexer and that limited me to 25mA per 10 digit block, due to the 25mA per pin limit on the 4067. I did consider attaching each 10 segment to two pins, then realised that's blond as the multiplexer only has one active output.So... adding a high side mosfet onto the multiplexer gets me the higher current for each 10 segment block.I'm not sure it's correct of it will work.It "should" be smaller. An 2xSSOP-24s + 1xQFP-32 + a couple of quad op amps/capacitors on the front end. That I would need with the LM3915s anyway. That should be fittable on a board not much larger than the LED bars, athough the bars are through hole which might lead to some interesting layout shenanigans.Besides doing it with an MCU means I can do cooler things with the LEDs as well... and output two channels for strips of NeoPixel LEDs and drive the master levels into half meter LED strips up the back sides of my monitor.... might be cool. Stuff like that.

author: paulca
author_rank: Super Contributor
timestamp: April 02, 2018, 05:52:59 pm
content: Acutally I'm not entirely sure the S0-S2 lines to the multiplexer will work with pull ups into constant current sink ports of the LED driver.The 5V is coming through 10k. So 0.5mA. I could make them 100k and make it 50uA. When the LED driver opens that drain it will attempt to pull the current set by iREF, which is going to be orders of magnitude higher than the 50uA, so if that theory is correct, yes it will pull the S lines low.

author: schmitt trigger
author_rank: Super Contributor
timestamp: April 02, 2018, 09:02:52 pm
content: Quote from: paulca on April 02, 2018, 05:52:59 pmI believe your reasoning is correct.The only thing I would do is to double-check the datasheet Ioh leakage current,(if any)just to ensure that S0 thru S2 will be pulled high with your chosen pullup resistor values.