Author Topic: Help needed for AVR LED and Switch Matrix  (Read 9335 times)

0 Members and 1 Guest are viewing this topic.

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Help needed for AVR LED and Switch Matrix
« on: August 21, 2021, 05:51:57 pm »
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.
 

Online mariush

  • Super Contributor
  • ***
  • Posts: 5354
  • Country: ro
  • .
Re: Help needed for AVR LED and Switch Matrix
« Reply #1 on: August 21, 2021, 06:41:44 pm »
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/14308337
QFN   : https://www.digikey.com/en/products/detail/lumissil-microsystems/IS31FL3236A-QFLS4-TR/14308348

It's 1$ at LCSC : https://lcsc.com/product-detail/LED-Display-Drivers_ISSI-Integrated-Silicon-Solution-IS31FL3236A-QFLS2-TR_C246443.html

Connect 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.html
See 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



 
The following users thanked this post: Pferd

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14134
Re: Help needed for AVR LED and Switch Matrix
« Reply #2 on: August 21, 2021, 07:21:59 pm »
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
main.cpp
Code: [Select]
/*
   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 interrupts

  TCCR0A = (1 << WGM01); // Timer 0 mode CTC
  TCCR0B = (1 << CS01) | (1 << CS00); // Timer prescaler /64
  OCR0A = 0x55; // set output compare to 200 Hz
  TIMSK0 = (1 << OCIE0A); // enable output compare match interrupt A

  while (1)
  {
    segment_1 = character[11];
    segment_2 = character[10];
    segment_3 = character[7];
    segment_4 = character[4];
    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 = 0x01;
      break;
    case 1:
      DDRA = 0xff;
      PORTA = segment_2;
      PORTC = 0x02;
      break;
    case 2:
      DDRA = 0xff;
      PORTA = segment_3;
      PORTC = 0x04;
      break;
    case 3:
      DDRA = 0xff;
      PORTA = segment_4;
      PORTC = 0x08;
      break;
    case 4:
      DDRA = 0xff;
      PORTA = row_led_1;
      PORTC = 0x10;
      break;
    case 5:
      DDRA = 0xff;
      PORTA = row_led_2;
      PORTC = 0x20;
      break;
    case 6:
      PORTA = 0x00;
      DDRA = 0x00;
      PORTC = 0x40;
      row_sw_1 = PINA;
      break;
    case 7:
      PORTA = 0x00;
      DDRA = 0x00;
      PORTC = 0x80;
      row_sw_2 = PINA;
      break;
    default:
      break;
  }
}

Your schematic is *DODGY* - the high side anode drivers should be high gain PNPs or P-MOSFETs for minimum voltage drop when all segments of a digit are on (with active low drive signals).  If you haven't got any, removing (shorting) the base resistors of the NPN emitter followers that you are using would reduce the variation in voltage drop with load.

Apart from that, you need to reverse bias the LEDs when reading the switches so stored charge from when they were last on doesn't interfere with the readout, and make the switch circuit much lower impedance (e.g. reduce the 10K resistors in series with the commons , to 1K so photocurrent in the LEDs doesn't significantly affect the levels, + modify the row drive so it pulls low, so you can use the internal pullups on port A to define the switch open state.
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #3 on: August 21, 2021, 09:17:50 pm »
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?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14134
Re: Help needed for AVR LED and Switch Matrix
« Reply #4 on: August 21, 2021, 09:28:57 pm »
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.

That'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.
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #5 on: August 21, 2021, 09:36:22 pm »
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!

If 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. :-//
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #6 on: August 21, 2021, 09:47:57 pm »
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.

Yep!  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.
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #7 on: August 21, 2021, 09:50:13 pm »
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.
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #8 on: August 21, 2021, 10:04:34 pm »
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.

That'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.
« Last Edit: August 21, 2021, 10:06:59 pm by AaronD »
 
The following users thanked this post: Pferd

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #9 on: August 21, 2021, 10:20:12 pm »
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: [Select]
/*
 * 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 interrupts

TCCR0A = (1<<WGM01); // Timer 0 mode CTC
TCCR0B = (1<<CS01) | (1<<CS00); // Timer prescaler /64
OCR0A = 0x55; // set output compare to 200 Hz
TIMSK0 = (1<<OCIE0A); // enable output compare match interrupt A

    while (1)
    {
segment_1 = character[11];
segment_2 = character[10];
segment_3 = character[7];
segment_4 = character[4];
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;
}
}
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #10 on: August 21, 2021, 10:36:59 pm »
Here´s the code again, hope this time it works:

Much 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.
« Last Edit: August 21, 2021, 10:52:11 pm by AaronD »
 
The following users thanked this post: Ian.M

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #11 on: August 21, 2021, 10:49:26 pm »
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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14134
Re: Help needed for AVR LED and Switch Matrix
« Reply #12 on: August 21, 2021, 11:59:12 pm »
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 red HDSP-C8E3 and 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.
« Last Edit: August 22, 2021, 10:03:56 am by Ian.M »
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #13 on: August 22, 2021, 12:06:31 am »
The Port and DDR assignments, do you mean I should swap them in the initialization or in the ISR? Or both?

The 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.

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.

With 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.  :)
« Last Edit: August 22, 2021, 12:13:37 am by AaronD »
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #14 on: August 22, 2021, 09:53:45 am »
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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14134
Re: Help needed for AVR LED and Switch Matrix
« Reply #15 on: August 22, 2021, 10:41:42 am »
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 the MAX7219, 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.
« Last Edit: August 22, 2021, 02:42:00 pm by Ian.M »
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #16 on: August 22, 2021, 02:32:57 pm »
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
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #17 on: August 22, 2021, 09:10:47 pm »
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.

Almost 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.

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.

If 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.

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.

Nice!  8)

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).

Or a "poor man's VCA"?  (sorta)  I assume that you're just playing with the feedback resistors of an otherwise textbook-designed audio opamp?

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.

MIDI 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.

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

Yeah, 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-MAX5439EUD

I'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-15V and has all the toys is discontinued.  |O

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.

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...

My 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.
« Last Edit: August 22, 2021, 09:33:10 pm by AaronD »
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #18 on: August 22, 2021, 09:49:39 pm »
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!
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #19 on: August 22, 2021, 10:42:32 pm »
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...

Don'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.

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.

Ah!  Okay, so my original idea turned out to be almost right.  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 would increase the 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-attenuator before the 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.

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.

The 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.)

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!

I'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.
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #20 on: August 23, 2021, 03:13:20 pm »
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!
 

Offline AaronD

  • Frequent Contributor
  • **
  • Posts: 275
  • Country: us
Re: Help needed for AVR LED and Switch Matrix
« Reply #21 on: August 23, 2021, 04:41:35 pm »
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.

Nothing 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.

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:).

Yeah, 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.

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.

So 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!

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.

In 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.

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!

Rod 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.
« Last Edit: August 23, 2021, 04:46:11 pm by AaronD »
 

Offline PferdTopic starter

  • Contributor
  • Posts: 40
  • Country: de
Re: Help needed for AVR LED and Switch Matrix
« Reply #22 on: August 23, 2021, 06:53:02 pm »
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!
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14134
Re: Help needed for AVR LED and Switch Matrix
« Reply #23 on: August 23, 2021, 07:12:28 pm »
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.

« Last Edit: August 23, 2021, 08:17:22 pm by Ian.M »
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2499
  • Country: us
  • Yes, I do this for a living
Re: Help needed for AVR LED and Switch Matrix
« Reply #24 on: August 23, 2021, 08:04:41 pm »
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.

Rather than using the 4016 and hopefully-matched resistors to set attentuation, why not use the TI PGA2320?

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 clock ;)

I 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->