I have an analog switch (DG408) that has three input pins for channel selection.
I'm cycling through the channels with a switch function (from an Arduino uno), but as I have to set pins separately there are very short times when the wrong state is selected. This produces 500us “pops” on the output.
(On the common pin of the switch is 5V, so on each output there should be a HIGH output as long as the step is selected. This is intended to be used for audio routing in the end, I’m using DC signal for simplicity)
Is there a way that I can do port manipulation to switch the state of 3 pins at the same time, but leave the rest of the port untouched?
What "Enable"? If the control pins select input pin signals and channel them to one input pin, don't you read the input pin? The Arduino inputs are in a "don't care" state unless you actually read them.
If this doesn't instantly make sense, it is time for you to post a schematic diagram.
I see what you meant now, but it's not connected back to the arduino, the switch is for external use (audio routing in a modular system), so the arduino is receiving a clock signal, then on each step it outputs data on 2 pins to the switch to select the channel (the switch is patchable, it has 4 i/o and 1 common i/o.)
What is the actual problem? Not the thing that you think you need to do to make it work, instead, what is the undesired behaviour that it is exhibiting? What is this mystery IC?
It’s a DG408 IC, the problem is that sometimes when it switches channel, there is a 500us “pop”, as the pins align up so that it switches to the wrong channel for a moment. If I could switch the pins controlling it simultaneously, I suppose the problem would be solved.
(BTW I realise that I wrote 2 pins in the original post, but this project of mine also has a DG409 in it controlled separately, which I mixed up, whatever, the problem is with the DG408 (8:1))
I thought so. I actually don't believe that simultaneous switching will help much. What makes a channel "wrong"? In other words, why would the "right" channel pop and another channel not pop? How are you handling the DC offset and/or any remaining charge on DC blocking capacitors?
There will be selections where only one select pin changes, like the switch from 000 to 001 or 000 to 010 or 000 to 100. What happens in those 3 cases? In these cases, there can be no delay separation because, well, a pin change can't be separate from itself. For these, there can not be any difference between using port writes and digitalWrite() calls. If you test this, you will know for sure.
In some CMOS switching circuits I've seen, there is a soft muting circuit that kicks in while the switching is happening.
Afterthought - there is another nasty problem that sometimes occurs. If there is some leakage path from digital to analog circuitry, the switching transitions can be translated to audio spikes. Separate digital and audio grounds are sometimes part of a design scheme to avoid this.
antumbra:
I agree that those cases are totally fine, the problem comes when the following happens
I am trying to move this discussion away from theoretical hypotheses. Did you perform the experiments I suggested, and what exactly did you observe? It's not clear from your words whether this actually happens, or whether you just expect it to happen.
For example, can you tell me with respect to the table above, did you hear a pop when switching between Step 1 and Step 2? Between Step 5 and Step 6? and so on...
Also, there are many important questions in reply #8 that you haven't answered. Perhaps you could post a schematic?
I believe you want to switch 2 pins at the same instant with port manipulation instead of sequentially.
Which Arduino pins are connected to DG408 pins A0, A1, A2? Not the serial pins D0 & D1, I hope.
There are no pops on those steps, they are fine. I have this module built and I experience this problem, I also have a scope and can confirm it happens on those steps.
The pins are connected to:
SW1_A0 to PB0
SW1_A1 to PB1
SW1_A2 to PB2
Thank you for the due diligence and report. It makes it easier to give a meaningful answer.
Okay, then you should look at the port to pin mapping of the device you're using. It looks like you found some pins that correspond to adjacent bits in the port. The rest is really standard stuff... just search on "port manipulation" in the search box at the upper right of the forum page.
Lucky for you, the PBx and PDx bits don't need to be shifted, just masked. What makes you think it's okay to mix 12V and 5V logic? Okay, nm, I see now.