Help needed for AVR LED and Switch Matrix - Page 1
Forum section: electronics / general

author: Pferd
author_rank: Contributor
timestamp: August 21, 2021, 05:51:57 pm
content: Hello,I´m new here and I need some help with my project, because I am not an expert with Microcontrollers.I have started a project here where I use an Atmega164P to control my circuit. It is the "user interface" I need help with. It multiplexes 4 7-segment displays and drives 16 leds for 16 push buttons through the same multiplexing routine.My Program runs fine just displaying some data through the displays, but correctly reading the switch-positions is a problem for me, as the switch matrix (2 rows x 8 columns) is part of the display-routine itself.For you guys to understand my problem better I wrote down my schematic and post a picture of the actual arrangement of my digital board. Maybe my problem is more on the electrical side rather than the software. I would be really thankful if someone has the patience to look over my circuit here.

author: mariush
author_rank: Super Contributor
timestamp: August 21, 2021, 06:41:44 pm
content: Probably not the reply you're gonna expect, but is there a reason why you make your life harder with multiplexing so many things?By the time you waste so much pcb space for diodes and traces and resistors and transistors, you could just spend a few cents on either a couple 16 channel led driver chips that you can put in series, or a single higher channel led driver , and then you can simply shift 32 bits to the leds drivers and be done with it, using just two io pins on your arduino.For example, see IS31FL3236A, a 36 channel led driver :TQFP :https://www.digikey.com/en/products/detail/lumissil-microsystems/IS31FL3236A-TQLS4-TR/14308337QFN :https://www.digikey.com/en/products/detail/lumissil-microsystems/IS31FL3236A-QFLS4-TR/14308348It's 1$ at LCSC :https://lcsc.com/product-detail/LED-Display-Drivers_ISSI-Integrated-Silicon-Solution-IS31FL3236A-QFLS2-TR_C246443.htmlConnect to it using i2c, shift 36 bits and you have all segments current limited to the maximum value you set through a single resistor, and you also have commands to adjust brightness in 256 steps for each channel and/or scale each channel as 1/2 , 1/3 , 1/4 of maximum current set.There's also specially made chips to control 4 such digits, see for example the 15 cents CH455G (and lots of clones available with same footprint and pinout) :https://lcsc.com/product-detail/LED-Display-Drivers_WCH-Jiangsu-Qin-Heng-CH455G_C89818.htmlSee figure 8.2 in the datasheet at page 7 for example circuit on how you would wire the 4 digits :https://datasheet.lcsc.com/lcsc/2008191806_WCH-Jiangsu-Qin-Heng-CH455G_C89818.pdf

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2021, 07:21:59 pm
content: What's with the <expletive> .odt file? To get something vaguely resembling your actual main.cpp, I had to remove the double spacing and runb it through a code autoformatter!Quote

author: Pferd
author_rank: Contributor
timestamp: August 21, 2021, 09:17:50 pm
content: Thanks for the answers so far!I do in fact have the equivalent PNP-Darlington Transistors at hand, the BC516. I have been thinking about changing them before, but I wasn´t sure if it would be good to have the anode drivers controlled active low. Just imagine the controller being in reset state, when all its ports are low, it would turn on all leds at once, which could possibly overload it. Correct me if I´m thinking this wrong.The thing with the reverse biasing is an interesting point... And the photocurrent could explain why I was reading strange ramps at the Controller-PortA when the switches were active. How do I effectively get rid of that charge?

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2021, 09:28:57 pm
content: Quote from: Pferd on August 21, 2021, 09:17:50 pmThat's not so. The DDR and PORT registers are cleared by a reset and on powerup, so GPIO pins start off as hi-Z inputs with no pullups so wont turn the digit drivers on.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 21, 2021, 09:36:22 pm
content: Quote from: Ian.M on August 21, 2021, 07:21:59 pmIf you open it in LibreOffice (free, open-source office suite:https://www.libreoffice.org/), then you don't need the formatter. But it still has the double spacing. Not sure why.Why the OP didn't give us a plain text file instead of a complex formatted thing, I don't know either. I've heard of people being unaware of what "a plain text file" is, and insisting on sending proprietary formats while *calling* them "plain text" because they haven't bolded it or something like that...but you couldn't get one of those to compile, and so the OP wouldn't have gotten as far as he did.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 21, 2021, 09:47:57 pm
content: Quote from: Ian.M on August 21, 2021, 09:28:57 pmYep! That's true. Just remember to set the initial output data before *making* them outputs, and you won't have any spurious signals either.As an extension to that, you can make a "poor man's open-collector" output, on a chip that doesn't have one explicitly, just by setting the data low and then using the direction instead. It works the same for both polarities, if you ever need to pull high or float.

author: Pferd
author_rank: Contributor
timestamp: August 21, 2021, 09:50:13 pm
content: Ok, so that won´t be a problem, I see... I´m right now changing the NPN for PNP. Then I invert the PORTC bits in software.The thing with the text file is I just copy pasted it into an odt file to post it here. I´m new to the forum stuff, I bet there´s a simpler way to post code. I work in atmel studio so I have a project file and a cpp. Somehow I wasn´t able to attach a cpp to my post.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 21, 2021, 10:04:34 pm
content: Quote from: Pferd on August 21, 2021, 09:50:13 pmThat's weird. And you're right, the list of allowed types does include some OpenDocument formats (odt and ods), and their equivalent M$ versions, but not a cpp source file. It does take C source and plain text (txt), so maybe you can just change the extension?And the mods can add C++ files to the allowed formats?Barring that, you can click the # button above the editor here and copy/paste your code between the tags that it creates.

author: Pferd
author_rank: Contributor
timestamp: August 21, 2021, 10:20:12 pm
content: So, Transistors changed. I can definitely see an improvement in the led brightness! Using my oscilloscope and measuring at one PortA Pin, I can see the remaining charge that looks like a floating pin when the switch rows are active. I need to somehow get rid of that. The next thing I try is reducing the resistor values as Ian.M mentioned before. No wonder this obscures my switch readout.Here´s the code again, hope this time it works:Code:/** VGP.cpp** Created: 15.08.2021 13:20:51* Author : Valou*/#include <avr/io.h>#include <avr/interrupt.h>#define F_CPU 10000000UL/*characters:{0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14}{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -, E, C, H, }*/char character[]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xBF, 0x86, 0xC6, 0x89, 0xFF};/*variables*/int i=0;uint8_t segment_1, segment_2, segment_3, segment_4, row_led_1, row_led_2, row_sw_1=0, row_sw_2=0;int main(void){/*initialization*/DDRA = 0x00;PORTA = 0x00;DDRC = 0xff;PORTC = 0x00;DDRD = 0xff;PORTD = 0x00;MCUSR &= ~(1<<WDRF);WDTCSR |= (1<<WDCE) | (1<<WDE);WDTCSR = 0x00;sei(); // enable global interruptsTCCR0A = (1<<WGM01); // Timer 0 mode CTCTCCR0B = (1<<CS01) | (1<<CS00); // Timer prescaler /64OCR0A = 0x55; // set output compare to 200 HzTIMSK0 = (1<<OCIE0A); // enable output compare match interrupt Awhile (1){segment_1 = character;segment_2 = character;segment_3 = character;segment_4 = character;row_led_1 = row_sw_1;row_led_2 = row_sw_2;}}ISR (TIMER0_COMPA_vect){if (i==7){i=0;}else{i++;}switch (i){case 0:DDRA = 0xff;PORTA = segment_1;PORTC = 0xFE;break;case 1:DDRA = 0xff;PORTA = segment_2;PORTC = 0xFD;break;case 2:DDRA = 0xff;PORTA = segment_3;PORTC = 0xFB;break;case 3:DDRA = 0xff;PORTA = segment_4;PORTC = 0xF7;break;case 4:DDRA = 0xff;PORTA = row_led_1;PORTC = 0xEF;break;case 5:DDRA = 0xff;PORTA = row_led_2;PORTC = 0xDF;break;case 6:PORTA = 0x00;DDRA = 0x00;PORTC = 0xBF;row_sw_1 = PINA;break;case 7:PORTA = 0x00;DDRA = 0x00;PORTC = 0x7F;row_sw_2 = PINA;break;default:break;}}

author: AaronD
author_rank: Frequent Contributor
timestamp: August 21, 2021, 10:36:59 pm
content: Quote from: Pferd on August 21, 2021, 10:20:12 pmMuch better! And I would swap the initial PORT and DDR assignments, so that you're setting the data first, before you output something unintended for one load/store cycle. Yes, it's short, but it's still unintended, might cause problems in some situations, and easy to fix.In the example that you posted just now, the PORT assignments are all defaults anyway, but it's a good habit to get into, so that you never know that the alternative would have been bad because it "just works" and you move on.It's also a good habit to design your physical circuit so that all Hi-Z is okay. (random reset, long boot-time, held in reset for programming, etc.) Again, your specific example here doesn't have that problem, but I've seen some that would have if it weren't for an explicit pull-up/-down or something similar.And you might want to consider clearing all of your enabled interrupt flags after configuring them, and before enabling interrupts globally. The configuration can create a false flag, and you probably don't want to respond to that. Like my other points here, that's not so important with what you've posted so far, but in something that relies on what it did previously, it could mean the difference between working perfectly, not at all, or working sometimes, which is the worst to track down.

author: Pferd
author_rank: Contributor
timestamp: August 21, 2021, 10:49:26 pm
content: Thank you for your reply! It's good to hear that my programming isn't total garbage:).The Port and DDR assignments, do you mean I should swap them in the initialization or in the ISR? Or both?I am currently trying to simulate possible other circuits for wiring up my push buttons. The way it is now it somehow shorts something together, according to the oscilloscope on a PortA Pin; eg when a button is pressed while a display segment is active, which is impossible to avoid at a refresh rate of 200Hz. And if two buttons are pressed simultaneously, it gets even funnier... In the end my circuit has to be immune against such use, otherwise it would just end up being a bug-system.

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2021, 11:59:12 pm
content: Add a small signal Schottky diode*in series with each button and it prevents multiple button presses causing any shorts, even if you remove your isolation resistors. If you don't have any Schottkys, 1N4148 will probably work but its fairly high typical Silicon PN Vf will compromise your logic levels.The switch rows don't need driver transistors, so as I said earlier, I'd drive the current row directly low with PC6 or PC7 so I could enable the port A pullups during switch read so unselected columns don't float. Ensuring the LEDs are reverse biassed during this could be handled by 100K pulldowns on the collectors of the new PNP digit drivers. Worst case an AVR pullup 'looks' like a 50K resistor, so as long as the total LED's photocurrent doesn't exceed 20uA, it wont compromise the logic levels. As LEDs make pretty poor photodiodes#its fairly safe to assume it will be OK unless the user tortures it with a big camera flash or similar. If that's going to be a problem, turn it (and the diodes) around - drive the port A pins low one at a time, and read a pair of switches at a time on PC6 and PC7 with their pullups enabled.* BAT43 is good for breadboarding it, but if you use SMD dual diodes e.g. BAT54C (common cathode) or BAT54A (common anode) or anything vaguely similar, you can halve the no. of diode packages needed on the final board.# I've just taken the largest 7 segment LED I have handy (0.8" AlGAs high intensity redHDSP-C8E3and applied 10V reverse bias (twice the nominal abs.max.) and a 5W 3000K white LED spotlight 1" from the face of it. My measured photocurrent was 0.25uA.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 22, 2021, 12:06:31 am
content: Quote from: Pferd on August 21, 2021, 10:49:26 pmThe initialization for sure. The ISR depends on what you're actually doing and what the state of things is when you come into it. Simulate it step by step with "wacky" data, and see if the order makes a difference.Quote from: Pferd on August 21, 2021, 10:49:26 pmWith 16 buttons, you might do a 4x4 grid. (they don't have to be arranged that way physically) That exactly fills an 8-bit port, and I see that you still have two of those to spare. Set 4 bits as outputs and 4 bits as inputs with pull-ups. Try the internal pull-ups to start with, and if it's too noisy, add them physically. Then you can scan each set of 4 just like you're scanning everything now, and put two consecutive nybbles into one byte if you want.Or, you can do like I did with a different project, and use all 8 bits as inputs with pull-downs. Still on a 4x4 grid. Each button pulls both a row and a column high via a diode for each. No scanning in that case; just watch the port for anything non-zero and then decode it. It requires two diodes for each button though, so that can get to be a pain.The reason to use that polarity is because of the logic thresholds. Your voltage level when pressed will be a diode-drop short of the supply rail, so you need to make sure that that's still reliable. And the logic-high thresholds are usually farther from the positive rail than the logic-low thresholds are from the negative rail.Both methods are only partially able to detect multiple buttons being pressed simultaneously (in the diode version, for example, how would you decode 2 rows and 2 columns all being high, for 4 bits total?), so that might be a problem for you.And both keep them separate from the LED's. (or at least their input lines are kept separate) That separation alone should fix the crosstalk, no matter how you actually read them.---Or, you can do like I did in a different part of that same project (I was trying to shrink a ribbon cable, not necessarily to save I/O), and use a set of shift registers on SPI. You can have as many ins and as many outs as you want at that point, all from that one peripheral with 4 pins (MOSI, MISO, SCK, /SS), and each of those endpoints gets its own dedicated circuitry in the shift register with no need to multiplex.The clock and slave select go to all of them, and the data daisy-chains through all of the inputs, through the SPI peripheral in master mode, and then through all of the outputs. Read the datasheets carefully for the parallel-in and parallel-out shift registers (2 different kinds) so you can write your driver accordingly. Choose them well, and you can use the same /SS line for both.* Then the rest of your code just deals with an array of inputs and an array of outputs that "magically just work". Your logical I and O counts probably need to be equal or off by one byte though, depending on how your driver ends up working, simply because the SPI peripheral inherently requires that equality, real or dummy.*I ended up needing a dummy byte to make the input work. The chips that I used for that had a mux for each internal flip-flop, between its own input pin and its neighbor's output, and still needed the same clock to actually do it. So I clocked a dummy byte with the /SS in that position, which actually captured 8 times in a row, which is fine, and then shifted everything in. The outputs had an additional set of flip-flops that were edge-triggered from the commit pin (the datasheet called it something else), so they didn't care what that signal did as long as it changed periodically. That dummy byte had me throw the first one away on the input side and shift the first one "off the end" on the output side, which is perfectly okay. I thought about putting a 7-segment display at that end, to show a version number or something like that, but I didn't get around to it.In your case, you'd need 2 bytes of input and 6 bytes of output and, using the same chips that I did, your transaction would be 7 bytes long. 6 bytes if you make it smarter than I did, seeing that you have more outs than ins.

author: Pferd
author_rank: Contributor
timestamp: August 22, 2021, 09:53:45 am
content: Thanks, that's a lot of advice!I think it would be indeed really cool if I wouldn't have to multiplex the display. What kind of shift registers were you using? The old 74 series ones like 74ls595? Or are the spi controllable ones more specific? Because my initial plan was to use off the shelf and easy to get parts, so making a shift register work that the rest of the world is using might not be a bad idea...As you can see in the picture I posted earlier, I am already planning on using 4094 shift registers to create static outputs of 48 individual bits (pin header at the top). If your spi registers could work like that aswell it would be amazing, so I only had to use one type for outputs and one type for inputs. The 4094 are not ideal, I know, but I planned on running the serial lines through a simple level shifter so their outputs can be +/-5V. This is important since these 48 bit lines control 4016 switches which are on a symmetrical supply.

author: Ian.M
author_rank: Super Contributor
timestamp: August 22, 2021, 10:41:42 am
content: 74HC595 and CD4094 are very very similar. Both are SPI compatible, but not true SPI because they don't tristate their serial data out when /SS is de-asserted. That can be fixed with a tristate buffer, but its more usual to simply leave the final serial data out disconnected and write to them 'blind'.Where they differ is the speed and output drive capabilities. CD4094 has a max shift clock frequency of 1.25MHz @5V, and it would be unwise to push it much over 1MHz. Its also only good for a few mA of output current at 5V.The 74HC595 has a max shift clock frequency over 20MHz and is good for over 8mA.I wouldn't anticipate any problems using them in the same design driven by a MCU SPI peripheral with separate strobe (/SS) signals.However another simple option that might save the day cheaply (assuming you have a good reason for not using the two ports you appear to have spare), would be to add a 74HC138 3 to 8 line decoder to drive your PNP digit drive transistors. That would free up three pins on port C, giving you five to run the matrix totally independent from the multiplexed display.Another option would be to look at theMAX7219, which can drive up to eight 7 segment +dp digits or 64 individual LEDs in a 8x8 matrix or any mix in between. Its got a daisychainable SPI compatible interface like the shift registers, and only needs one resistor to set all the LEDs max. currents.

author: Pferd
author_rank: Contributor
timestamp: August 22, 2021, 02:32:57 pm
content: The Max7219 sounds like a one chip solution for my display, and simple to control aswell. If only it wouldn't be that expensive! Well I'd only need one, so maybe it isn't that costly after all ...I didn't know I could control the 4094 using SPI. I always thought I would have to come up with my own selfmade control for it. But now that you mention it, I might use the 74HC595, they simply seem to be the better chips here.About the Ports I have to spare, I do think I can free up one of them, but I just don't want to "waste" so many portpins just for the user interface. Maybe I don't see the forest because of all the trees, as we use to say here.Maybe it also helps if I describe the whole project I'm after.It is going to be a guitar preamp that is able to store patches and select them over a midi bus.So the control circuitry consists of 7 digital potentiometers (which I built myself using an opamp and a binary controlled resistor ladder with 4016 switches to bypass the resistors, giving me 6 bit resolution per "pot". It's more like a digitally controlled damping amplifier).Besides that it only has to drive a few channel switchers (also opamps controlled by 4016 switches), and the display and button unit which is used to set the parameters. Oh and a part to receive Midi control signals (only 31.250 kHz).That's all it has to do.Maybe I switch to actual digital pots. When I'm using many of the SPI controllable chips I could even use a smaller controller, like an Atmega88 for example. But I'm really unsure about those decisions. The Pots would have to be high voltage, because the analog circuitry is +/-15V. Microchip has some with 128 and 256 steps available. Then there is analog devices, which are rather expensive! But if they are worh their money quality wise I might look into them aswell

author: AaronD
author_rank: Frequent Contributor
timestamp: August 22, 2021, 09:10:47 pm
content: Quote from: Pferd on August 22, 2021, 02:32:57 pmAlmost any clocked serial thing can be used with the SPI peripheral. It doesn't have to say "SPI" on it to work; it's just a byte-oriented clocked serial line, implemented in hardware so the CPU can do something else in the meantime.Quote from: Pferd on August 22, 2021, 02:32:57 pmIf all of your I/O is slow and bit-banged, then you can use SPI-controlled shift registers for everything. My update rate was 30Hz, for example, which is plenty fast if it's not multiplexed (look at video frame rates for comparison), and I had 16 bytes each direction. You can figure out the required clock rate from there.Then the MCU itself only needs the SPI peripheral (3 pins + the appropriate select lines), a power supply, a clock (which could be internal), and a way to program it. Also, when reading that slow (30Hz), I didn't need to debounce my buttons, so that's another plus.Quote from: Pferd on August 22, 2021, 02:32:57 pmNice!Quote from: Pferd on August 22, 2021, 02:32:57 pmOr a "poor man's VCA"? (sorta) I assume that you're just playing with the feedback resistors of an otherwise textbook-designed audio opamp?Quote from: Pferd on August 22, 2021, 02:32:57 pmMIDI has that weird baud rate precisely because it divides nicely into a 1MHz clock. If your clock is a "nice" multiple of 1MHz, then you too can hit it dead-on using the UART peripheral. But you might have known that already.And don't forget the optoisolator for the MIDI input! That's so you never have to worry about a ground loop. (at least not from any standards-compliant MIDI gear - the mess of cheap Chinese junk is another matter...) But you might have known that too.I keep thinking about creating and detecting <break> characters, using the UART's frame-error flag to detect, and disabling the transmitter to send (which unmasks a pre-set port configuration to output the "active" state until the Tx is re-enabled)...but that's for DMX, not MIDI. MIDI synchronizes using the byte values themselves; no <break> characters anywhere. Specifically, the MSb of each byte is reserved as a sync flag, leaving only 7 bits for the actual data or to say what command is just starting.Also, don't forget about MIDI's "realtime commands", which are all 1 byte each, and can interrupt anything else in progress. The remainder of what was interrupted continues afterwards as if nothing happened. If you don't account for that, it might mess you up someday.Quote from: Pferd on August 22, 2021, 02:32:57 pmYeah, digipots are usually limited to their own supply, which is itself usually limited to 5V single-ended. That makes sense from a chip-design standpoint, but why there aren't (slightly) more expensive ones that can control a 15-0-15V signal is beyond me. It seems like there'd be a big market for them, but I just don't see them. A quick search on Mouser turned up exactly one that can handle a traditional serious analog signal range, and they want $9.00 for it (USD):https://www.mouser.com/Search/Refine?Keyword=700-MAX5439EUDI've heard some good things about THAT Corporation's Blackmer-cell-based VCA's (http://www.thatcorp.com/Blackmer_Voltage-Controlled_Amplifier_ICs.shtml), that use current inputs and current outputs and take a quite small analog control voltage, but my only known experience hearing them is in an Alesis 3630 dual-channel compressor as a live mixing engineer. I thought they were good there, but the primary demand in that setting is to not be worse than the venue's acoustic mess, which is usually not a challenge at all!You drive a Blackmer cell's input through a resistor and capacitor in series - the cap to block DC, and the resistor to convert the input voltage to the current that it wants; size the resistor first to set the input gain, and then the cap for the low-freq cutoff with your chosen resistor - and you run the output through what looks like an inverting opamp but without the input resistor because that resistor's job is already done by the VCA itself. The output opamp is inverting, but the VCA itself is also inverting, so it comes out right. The opamp's feedback resistor, of course, sets the output gain, and the overall equation for zero control voltage is simply an inverting opamp with the feedback and input resistors, neglecting the VCA entirely (except that the sign of the equation is reversed by the VCA being there).The control signal can be any raw magnitude that you want, because you'll probably have to attenuate it anyway to drive the cell. And you might as well lowpass it too, by adding a capacitor to the attenuating voltage divider, both to reduce the amount of analog noise that gets into the control input, and to reduce the "zipper" sound when changing a DAC quickly without being synchronized to the audio signal (which you probably won't be).True VCA's like this can be nice, but they *are* expensive! Mouser wants $5.50 for a THAT2180C and $9.50 for a THAT2180A. The only difference is in the accuracy of the factory trimming, which affects distortion. The externally trimmable version, 2181, has a surprisingly similar price range. And there's also the 43xx series, which includes the same VCA cell and some other toys in the same package...but the one that uses 15-0-15Vandhas all the toys is discontinued.Depending on when and how much you adjust it, your 6-bit ladder in the feedback of an opamp (if I understand you correctly) might be just fine as well.Quote from: Pferd on August 22, 2021, 09:53:45 amMy shift registers were SN74HC166 and SN74AHCT595. Mouser still has both of those, several years later, for $0.50 each (USD), compared to $10.00 for the MAX7219. That's not quite a direct comparison though, because the shift registers don't set the LED current like the dedicated driver does. And because each LED has its own dedicated output now, you'll also need a dedicated resistor for each one.With the number of resistors that you're going to need for that, I'd recommend a DIP, SOIC, or other dual-inline package with 8 isolated resistors in it, at least for prototyping, just to reduce the total number of parts to get loose on the bench and then hold down individually while you solder them!If you want to adjust the brightness easily like the MAX does, then you can replace those resistors with current followers. There are transistor arrays just like there are resistor arrays...At some point, if you want all the features of the dedicated chip, it becomes cheaper to use the dedicated chip; if not, then it's easy to beat a specialized Porcshe with a collection of Volkswagens.

author: Pferd
author_rank: Contributor
timestamp: August 22, 2021, 09:49:39 pm
content: Good to know that the SPI Interface can be adapted, this might save me a lot of trouble!I was planning on using an 8MHz clock, because divided by 256 this gives me exactly the 31250Hz of the Midi. But before I can run the Midi stuff I need to get everything else running...And you're right, I don't really have anything super time critical in that thing, it could theoretically be a real snail of a controller...After thinking about it some more, I may connect the buttons in the 4x4 array to one port, and handle all the led control and bit send via 74HCxxx registers. I find it pretty that way, being a lover of the dip packages;)It is sort of a VCA, but not quite. I spent weeks developing a solution that lets me avoid digital pots. The original circuit I partly try to replicate used long obsolete Toshiba volume control ICs with their own special protocol (real early 90s digital stuff).The Opamps in my configuration work in a damping way, so they go from passing the signal through with an amplification factor of 1 to nearly completely blocking it. This happens with 64 steps. I got to use 6 bit because 4 bit is too less in my opinion and 8 bit is lind of overkill, makes it unpleasant to use, too many options. So for example for a bass control it can range from -31 to +32, a reasonable amount of steps I think.I'll attach a picture of my circuit. It is wired as a differential Op-Amp, so if all the 4016s are on, it "conducts" and if all of them are off the total resistance is somewhere around 98k. I didn't make it exactly 100k on purpose because if you accidentally end up having more than 100k there because of the tolerances the opamp will swap the phase around.For the tone controls it uses an extended version with two opamps, so it can amplify and damp at the same time, because one does exactly the opposite of the other, the sum of both always stays the same.The channel switchers work in the same way. Just that they only have one 4016 switch to either make the resistor 100k or short it out.I've ran some tests this evening again and unfortunately the 4016 switches somehow capacitively couple the higher frequency signal through even when switched off.But I might have another way of fixing this... Maybe I could use two of the 4051 multiplexer ICs to form a 8x8 resistor ladder which gives me 64 steps aswell... This could solve a few problems aswell. E.g. they have level shifters built in so I can control them using my normal 0 to 5V digital signal even though they get supplied a symmetrical +-5V. And I would always have a definitive potential in the ladder, nothing flowing around in the air, if you know what I mean;).A 74 series shift register in front and it's done!

author: AaronD
author_rank: Frequent Contributor
timestamp: August 22, 2021, 10:42:32 pm
content: Quote from: Pferd on August 22, 2021, 09:49:39 pmDon't forget administrative overhead, like decoding commands, shuffling data around with a reformat or two along the way, etc. Most of the time, that doesn't take much, but it can still balloon on you sometimes.Quote from: Pferd on August 22, 2021, 09:49:39 pmAh! Okay, so my original idea turned out to bealmostright. I was going to guess that you had a classic non-inverting amp with a voltage divider for feedback, and you were just shortening the grounded tail. But that wouldincreasethe gain when you said you were damping instead. So I generalized it. Turns out you're doing pretty much exactly that, but as a pre-attenuatorbeforethe amp!Might want to revisit the 4016's though. If your signal can swing up to 15-0-15V (check the opamps' and regulators' datasheets), then U18A and U20B might see more than they're designed for. Maybe not by much, but it's generally not a good idea to chance it at all. There's an unavoiadable parasitic thyristor in most chips that can be triggered in that case, and it shorts out the power supply until the current is stopped.Quote from: Pferd on August 22, 2021, 09:49:39 pmThe datasheet that I found has the 4016's feedthrough capacitance at typically 0.2pF. No min/max and no temperature range. Normally, I wouldn't be too worried about that, but since you've seen a problem and it doesn't seem to be a controlled parameter, then maybe it could be a few orders of magnitude higher in your case??? If that's really what it is, then simply reducing the resistances all around (watch the current when you do that!) might be enough to fix it.(I had a similar problem with stray capacitance on a VGA video processor that I had naively used audio-valued resistors for! What looks like a near-short-circuit for audio is actually necessary for something that high-speed, just to brute-force the stray capacitance out of the way. And the amplitude is low enough there, that the fear of massive current with such low impedance doesn't play out.)Quote from: Pferd on August 22, 2021, 09:49:39 pmI'm not sure what you mean by using two 8:1 bidirectional switches to form an 8x8 ladder. Is it a 2-dimensional grid with 64 different-valued resistors - one at each intersection - and you simply choose one of them?At that point, you might be better off with a 2-resistor ladder and a fast switching-type FET to short one of them: PWM that FET to get anything you want in between the 2 extremes, as long as the switching frequency is well above audible and you lowpass it again after the chopper.Or, use a CdS cell as your variable resistance and shine an LED on it, all buried in black epoxy or something like that. PWM the LED to control the resistance, possibly with a lowpass between the PWM and the LED.You might also spend a few weeks looking around this site:https://sound-au.com/That's almost not an exaggeration! There's a TON of good analog audio stuff there. Scroll down past the latest additions to get to the complete Projects and Articles pages.

author: Pferd
author_rank: Contributor
timestamp: August 23, 2021, 03:13:20 pm
content: Wow, that's a ton of great ideas!I think you have a point here, with the 4016s 18A and 20B being able to see a too high voltage. according to the datasheet it has clamping diodes to the power rails on "all" pins, but so far I couldn't confirm this through measurements. For example, it seems to be a general confusion with the multiplexer chips aswell... 4051, 4052 and 4053. The original circuit was feeding an audio signal with roughly 10Vpp from a valve stage directly into a 4053 for channel switching. Well, this setup worked for 30 years so far, and it indeed has no measurable protection diodes on the analog signal lines. I think I remember one 4053 datasheet even saying that the signal can be 20Vpp.The capacitive problem could also well be a result of my breadboard prototyping design. I cramped so many traces together and am using a ton of wired connections on the top of the board aswell, so I don't directly blame the 4016s. Maybe I can post a picture later of the whole prototype, a wire madness:).Sorry, that was a misunderstanding. By 8x8 resistor ladder I meant having two 8-resistor ladders cascaded. Theoretically this could give me 64 steps and might be even possible with all same value resistors. But your idea with the fast switching fet sounds like a very elegant solution. I have been simulating circuits aswell using current mirrors, fets, and all different stuff to be able to control the analog signal in steps using a dac or r2r network. But it always failed when it got too complex to compensate for the transistors nonlinearity. Is the PWM-Method more linear? Is it a lot of effort to design a working prototype of that sort? I mean, fast switching shouldn't be a problem in the age of microcontrollers.I've heard the solution with the ldr and led before. It is also a tempting solution, but I guess it is very hard to get your hands on some specialized optocouplers. Building them myself is too much of a homemade fix to be honest, Even though I've seen that before in some commercial designs. Just a led and Photodiode connected through a black shrinking tube.I'll definitely check out that site!

author: AaronD
author_rank: Frequent Contributor
timestamp: August 23, 2021, 04:41:35 pm
content: Quote from: Pferd on August 23, 2021, 03:13:20 pmNothing says the chip can't be redesigned to serve the same basic function with modern manufacturing, and given the same base part number. (the 555 timer, for an excellent example of this) The different manufacturing process will have different "gotchas" though, and this might be one of them.Quote from: Pferd on August 23, 2021, 03:13:20 pmYeah, you're probably right. It's not hard at all to get a few pF by accident between parallel wires. If you can make a PCB, then you can put a ground trace between sensitive stuff, and a few other tricks, but you still have that capacitance to ground, so the impedances still matter.Quote from: Pferd on August 23, 2021, 03:13:20 pmSo each of two modules has 8 different resistors connected to a common bus, and the other ends connected to the switch? Then put two of those modules in series? That sounds a lot better in terms of resistor count and wiring layout!Quote from: Pferd on August 23, 2021, 03:13:20 pmIn theory, it shouldn't care about the transistor's non-linearity at all, because it barely spends any time there. The transistor itself is designed specifically for switching, so it's awfully non-linear as a side-effect...if you can manage to keep it there. It's designed to slam open and slam closed, with not much in between, and you often use a FET driver IC to dump a ton of current into the gate to make it even faster. (charge and discharge the gate capacitance)Considering that it's practically *only* ON or OFF, it's a little bit easier to see what it's supposed to be doing, and why you need to lowpass the audio afterwards.As for fast switching, the transitions are handled as above, and the switching frequency is handled by the microcontroller's PWM module. Set up its required resources, give it a clock divider for the frequency and an "on-time" (with units of the divided clock) for the duty cycle, and it just runs with that until you give it something else. No CPU usage at all except to update it.Do be aware though, that the end effect on the audio signal will probably be linear with duty cycle, and you probably want a logarithmic response to the user setting. You can do that math (big balloon in processing effort, but you might afford it in this case), or you can use a pre-computed lookup table.Quote from: Pferd on August 23, 2021, 03:13:20 pmRod Elliott (the owner and maintainer of that site) has spent an entire career in electronics, mostly audio related, and now makes some retirement income from bare-PCB sales of most of his projects. (source your own parts and build it yourself) The designs and explanations of those projects are right out in the open.He does say, in several projects that use an LED/LDR combination, that they used to be easy to find but not anymore, and that it's not hard at all to make a good one yourself.

author: Pferd
author_rank: Contributor
timestamp: August 23, 2021, 06:53:02 pm
content: That´s what they probably did. It´s the only way to explain why the same chip number has different designs. Btw did you know there´s a new version of this chip called the 4316? It is the same just that it has level shifters built in to the control lines. Unfortunately it´s just SOIC packaged.I´ll attach a picture of the project, which is a real ratsnest of wires... And to this point I only have half of the connections wired up. I really don´t know why I didn´t design a real prototyping pcb before this, you can perhaps imagine how many nights I soldered through to create this, just to find out it stray-capacitates itself to death:) But besides, the boards you see are as follows: Top left just analog OPamp stuff like tone controls and various amplifiers and filters. top middle is the board with all the channel switchers and "VCAs", so it´s stuffed with 4016 and TL072. Then on the right there is my power supply (I managed to get +/-15, +/-6.3, +/-5 and 250V as outputs from my supply. Without using a specialized tube amp transformer. Mains voltage where I live is 230V. Bottom left is the first preamp board with the high voltage tube circuitry. And bottom middle is as you know the digital part.I plan on creating a pcb for prototyping with attention to short traces and to avoid all these wire connections. They really suck!Yes, that´s the idea! I´ll draw the 4051 circuit later and share it here, so you can give me feedback on it;)The PWM option is something that I´ll definitely keep in mind!

author: Ian.M
author_rank: Super Contributor
timestamp: August 23, 2021, 07:12:28 pm
content: Don't let the non-availability of a DIP package stop you using interesting new chips. As long as they aren't excessively fast, you can get away with the cheap and readily available generic SMD <whatever> to DIL breakout boards. Available from Amazon, Ebay and the usual far east eBazar sites. For fast or high gain chips, you may need to 'dead bug' SMD decoupling caps directly on top of the chip to get them close enough.N.B. before buying a multi-package kit, check the package footprint you need is in it! I've been caught out that way with a wide (0.3") SOIC-16 ADC/DAC when I only had narrow (0.15") breakouts in stock.

author: Bassman59
author_rank: Super Contributor
timestamp: August 23, 2021, 08:04:41 pm
content: Quote from: Pferd on August 22, 2021, 09:49:39 pmRather than using the 4016 and hopefully-matched resistors to set attentuation, why not use the TIPGA2320?From your statement and your schematic, you're doing a volume control. The PGA2320 is a two-channel device that's a digital pot in front of a buffer op-amp, sorta like your U3A. While it's kinda pricey, realize that it's two channels and trimmed so the attenuation (and gain, it can go above unity) between the two channels are well matched. And it has +/-15 V rails for the analog and the logic port has a 5 V rail. You can drive the SPI port from a 3.3 V microcontroller (read the data sheet, Vih = 2 V) and you can daisy chain them. When daisy-chained, you tie all of the chip selects to the micro so all of the outputs update simultaneously.The maximum SPI clock rate is faster than your AVR's clockI did a studio monitor controller (four stereo in, five stereo outs of which one pair is a headphone amp) with four PGA2320 for volume control (one output doesn't have it, it's a "two track" passthrough) and I used DG409 dual 4:1 muxes for routing and DG403 switches for a mono function and it works as advertised.Now it is possible I don't understand your application.

author: Pferd
author_rank: Contributor
timestamp: August 23, 2021, 08:36:51 pm
content: Ok, now I´ve drawn down the idea I have. I later noticed that I might need to turn the 4051s around, otherwise it would attenuate strangely. I would only need two different resistor values. So in theory one mux handles the "tens" and one mux handles the "ones". It only has 8:1, but choosing the right values of resistors eliminates that problem. And with the metal film resistors I use, which have by standard a 1% tolerance, I don´t worry that much about them not being accurate for the job.@Bassman59, thank you for the information, I didn´t know you could still get volume control ICs. To me this always seemed like a thing of the past.

author: Bassman59
author_rank: Super Contributor
timestamp: August 23, 2021, 09:03:12 pm
content: Quote from: Pferd on August 23, 2021, 08:36:51 pmNew Japan Radio has the pandering-to-audiophile"Muses"parts, including two volume control devices. The volume controls are just two-channel digital pots with the same kind of zero-cross switching that's in the PGA2320, but they don't put the buffer amplifier on the chip. They're also as expensive as the TI parts. I've never used them so I can't comment on them other than to say that NJR's marketing is wank but their (other) parts meet spec.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 24, 2021, 01:04:48 am
content: Quote from: Bassman59 on August 23, 2021, 08:04:41 pmHuh. Couldn't ask for more turn-key than that. Now if I can get a similar kind of turn-key chip for TDM-8 audio into an 8-channel USB input...You're not kidding about the price though! WOW! Mouser wants $20.00 for just one! ($13 each if you buy 2k of them) But if it does exactly what you need without a fuss, then maybe it's worth that?

author: AaronD
author_rank: Frequent Contributor
timestamp: August 24, 2021, 01:18:20 am
content: Quote from: Pferd on August 23, 2021, 08:36:51 pmI think you've reintroduced the phase-flip problem that your original design is meant to avoid. With what you've drawn there, you can completely ground pin 3 of the opamp through A0 of both switches.And the bottom resistor of each set will always have the same potential on both sides, either because it's directly shorted, or because the string above it is shorted. That might not be a reason to remove it though, because the switch itself is "break before make", meaning that there's a brief time whenallof the switches are open. So it may have a function then.Also, what does it sound like to have the complete string of resistors in play for a brief moment between settings? Is it a short enough time to not matter? Or is it a deal-breaker?

author: Bassman59
author_rank: Super Contributor
timestamp: August 24, 2021, 02:57:49 am
content: Quote from: AaronD on August 24, 2021, 01:04:48 amThat turn-key chip is likely an XMOS processor. Although I have a back-burner project that uses an ARM of some sort with an external bus interface and connecting it to a small FPGA that does the converter interface. (Also it would do MADI, for other reasons.)QuoteWell, that's just it. Do you want to bolt on something that was designed to do the job and get on with it, or do you want to build something out of piece parts that requires more board space, power consumption, micro port pins and whatever?I will say that I did a programmable-gain fully differential mic preamp/ADC front end that ran on single +5V rails for a USB application. It ended up being the usual diff-amp design with an 8:1 analog mux to set the resistance (and hence the gain) between the two op-amp inverting inputs as well as a switch to put a parallel resistor across the feedback resistor to set the gain range. It all worked out to get a gain range from I think 1 dB to 50 dB in 1 dB steps. The gotcha was we had to use 0.1% resistors for the lowest values as well as the best grade of analog switch chip with the lowest/flattest on resistance.The thing is we initially wanted to use the TI PGA2500 or the THAT 5171 and neither worked with +5 V-only rails (we tested them, couldn't make them work). So the choice was to generate a negative rail with a charge pump or switcher or work something out with single-supply parts.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 24, 2021, 04:55:06 am
content: Quote from: Bassman59 on August 24, 2021, 02:57:49 amI've got a thread for that already,so we can move this discussion over there and not hijack this one.Essentially, the XMOS looks to me like massive overkill for just that one job. But if that's what it takes, then that's what it takes.Quote from: Bassman59 on August 24, 2021, 02:57:49 amI wonder if that's why I'm not seeing many digitally-controlled 15-0-15V analog parts? Most new designs are perhaps 90% digital or more, with all the visible work done in a DSP, and analog is limited to a preamp and a power amp?The preamp can be derived from the digital supply with extra filtering, or just tacked onto it directly for noise-tolerant stuff (no need for a separate "high-voltage" analog supply), and the user interface (if any) fudged to readas ifit were direct gain into a 15-0-15V analog circuit, when it's really feeding a 5V ADC with a correspondingly lower level. And the power amp is in its own high-voltage world anyway, and feeds straight from a DAC. (sometimes within the same class-D chip amp, with the analog "line-level" signal (who knows what it really is at that stage, nor does it matter anymore) never exposed to the outside in that case)

author: Pferd
author_rank: Contributor
timestamp: August 25, 2021, 07:02:27 pm
content: Wow, thank you all for submitting all those great ideas! I think that's enough for me to go brainstorm what I'll actually go for.Yesterday I just had another idea come to mind. What about using an OTA like a LM13700 or a NE5517 to do volume control? I don't know I never worked with those amps, mainly because they are really rare. But the important thing is they have that Iabc Pin which allows for gain adjustment. So the idea would be hooking this pin to a r2r network through a resistor to get the needed current flowing according to the datasheet. This control voltage could even get a capacitor so every change of volume is smooth.Does anybody here have experience with OTA circuits? Maybe I need to ask in another forum section for that old analog matter.And to put this even further, I was wondering if a normal op amp could be somehow modified to be a OTA, maybe putting a discrete long tailed pair in front of it? I might be talking nonsense here but I wonder if that would work. Even if it's just out of curiosity.I think the only OTA still in production is the LM13700, but it is known to be very good as far as I've read.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 25, 2021, 08:02:02 pm
content: Quote from: Pferd on August 25, 2021, 07:02:27 pmYou mean like this?:https://sound-au.com/articles/vca-techniques.html#s52That does work, but have a look at the other techniques on that page as well.Here's even a project, using the most similar of those other techniques:https://sound-au.com/project213.htm

author: Pferd
author_rank: Contributor
timestamp: August 25, 2021, 08:19:52 pm
content: I just took a look at the project 213 real quick before going to bed. The VCA there with the control Voltage from 0 to 10 volts sounds even better than going for an obsolete OTA! I'll look into that in more detail tomorrow, but even the response curve output vs control voltage looks not too bad. I somehow just like discrete stuff. Not too much but a nicely thought out circuit always brightens my day.And my project being a guitar amp really distortion could even be welcome to some extent. Who knows, maybe it sounds acceptable in a way. Only way to find out is test it;)

author: Bassman59
author_rank: Super Contributor
timestamp: August 25, 2021, 08:29:13 pm
content: Quote from: Pferd on August 25, 2021, 07:02:27 pmOTAs as parts in the standard catalogs are pretty much dead.

author: AaronD
author_rank: Frequent Contributor
timestamp: August 25, 2021, 08:34:44 pm
content: Quote from: Pferd on August 25, 2021, 08:19:52 pmHe's got lots of other guitar stuff too. Tone stacks, intentional distortion, etc. Just do a quick search for it, and maybe you'll get some more ideas...(and some really good "clean" or "transparent" stuff too, for those that are more into home HiFi)

author: Bassman59
author_rank: Super Contributor
timestamp: August 25, 2021, 08:38:51 pm
content: Quote from: AaronD on August 24, 2021, 04:55:06 amYou don't see the digitally-controlled wide-voltage parts because ... there's little call for them. Remember that making parts on a 36 V process is not the same as making them on a 5 V process. For the high-voltage parts, the die are bigger, the power consumption is higher, all of it. And combining the digital input means adding level shifters and what-not.The pro audio world today is now, as you note, mostly digital. To get the inputs into the digital realm they need an ADC, and all of the ADCs you want to use are built on 5 V digital processes. The thing is, they don'tneedto have a 30 V input swing, as even with the reduced input ranges on the converters noise is not a problem.And if you're feeding a 5 V input, your microphone preamp doesn't need to output on ±15 V rails. It needs to work on a 5 V rail swinging about some offset. And that's why the TI PGA2500 and the THAT5171 are all low-voltage chips.

author: Pferd
author_rank: Contributor
timestamp: August 25, 2021, 08:40:15 pm
content: I'll definitely do, this site is soo nice! I bet I can also find some great audio filters there for the equalisation part!And the VCA isn't even that much of an overkill... I even have some 4558 Opamps here at hand, because I planned on using some for my project anyway.I know the OTAs are pretty much dead (just a matter of time until the LM13700 in SOIC16 goes out of production...). I don't want any obsolete parts in my design:)But I also didn't want to build a discrete OTA (have been searching for circuits and simulated a few, turned out to be a real pain).