Monday, May 16, 2022

How to Sweep Resistance During Simulation in Altium

I wanted to simulate an op-amp circuit with Altium Designer to determine the Vout as I sweep through RTD (Resistance Temperature Detector) values.

"But Matthew! Why not just use LTspice like all of us cool kids?"

Well first off, LTspice has the most baffling shortcut key setup. I'm sure it made sense in the late 80s or something, but in this century I expect Ctrl+C to be "copy." Also, if my MSRP $8,000 piece of software includes simulation support, seems like it ought to work.

Unfortunately, by default, Altium does not offer an easy way to simulate the response of sweeping a resistor or potentiometer. A parameter sweep is offered, but this essentially runs a new simulation for each parameter change, rather than a continuous, interpolated output curve. This would be handy if I wanted to see what happens when I sweep Vref from 0 V to 5 V, with the RTD at a few values from 1 kΩ to 1.887 kΩ, but that's not what I want here.

BUT! After some searching, I discovered that SPICE does support using DC Sweep Analysis to change a resistor value, even though Altium does not show this as an option.

Here's my solution:

  1. Create a dummy voltage source. I called it Vrtd to keep track of it, but it doesn't really matter.
  2. Note the name of your resistor you want to vary. In my example, I cleverly named it "RTD".
  3. Set up a DC Sweep Analysis, using Vrtd as the primary source.
    1. Set this up to sweep from 1k to 1.887k, with a step size of 443.5.
  4. Save all, validate project.
  5. Go to Design > Netlist for Project > Xspice.
  6. Open the resulting .nsx file.
  7. Find the line that says ".DC Vrtd 1000 1887 443.5".
  8. Change this to ".DC RTD 1000 1887 443.5".
  9. Save.
  10. Run the simulation from the .nsx file.

If all goes well, you should see the voltage curve of your desired net plotted with the resistor value along the X axis, and the resulting voltage along the Y axis.

Huzzah!

Sunday, November 8, 2020

Solutions to Common Windows 10 Audio Issues


    I have been doing a fair bit of streaming, Skyping, Zooming, and Discording over the past few months, as I'm sure you have too. As a result, I have involuntarily become a mild expert in getting audio in Windows 10 to (mostly) behave. Here are all the solutions to the problems I have encountered, and I hope it helps you from pulling your hair out.
     
    Nothing here is difficult, it's all just a matter of knowing where to look. 

    This holds true as of 2023-08-30. I will do my best to update as I encounter problems and solutions. Some of these may still work for Windows 11, but I have no desire to upgrade, so I can't tell you which are still relevant.
     

    Where to Find These Settings

    To start us out, most everything will be found in what Windows 10 calls the Sound Control Panel. My friend Brett said it best: "Rule of thumb: if the page looks like it's in the Metro interface, it is full of shit. If it looks like a Win98 menu, you are in the right place."
     
    To get to the Sound Control Menu, first go to Settings > System > Sound (or just right click on the volume adjust icon on the taskbar and click "Open Sound settings").
     
    From here, click Sound Control Panel under Related Settings as shown below. If your window is particularly narrow, you may have to scroll down to find related settings rather than it being a sidebar.
     

    Why Is My Background Audio Quiet All of a Sudden?

    In the Sound Control Panel, click the Communications tab at the top. It will probably oh-so-helpfully be set to reduce the volume of other sounds by 80%. Click "Do nothing" and apply.

     

    Why Are Random Devices Hijacking My Audio?

    (Black and white video) Has this ever happened to you? You plug your shiny new Blue Yeti in to record the premier episode of your podcast, and your headphones stop working! Or maybe you plug in your DualShock 4 to settle in with some Trials, and now nobody can hear you in Discord.

    Basically what happens is you plug your device in via USB, and it decides "I am obviously the most important thing here. Hand over the wheel!"

    This solution is less of an actual fix, and more of a mitigation. But depending on how ruthless you are with disabling your devices, it can turn into a non-issue. 

    First, figure out which devices you'll ever want to use. My desktop setup is pretty permanent, so I know that all I'll ever use for audio input and output is either my Focusrite interface for physical, or Voicemeeter Banana for virtual audio.

    Another common setup might be a Yeti mic, and computer audio for headphones/speakers.
     
    Now disable every other device. This lasts through plugging and unplugging, so you should never have to worry about it again... until Windows updates and re-enables the speakers in your three monitors that you've never once used.

     
     
    For extra neatness I recommend unchecking "Show Disabled Devices."

     
     
    Ahh... doesn't that just make you feel at peace? 

    Why Can't These Two Programs Pick Up My Mic? Or: Why Can I Only Hear Audio From One Program? Or: Why is Discord Changing My Sample Rate Without Permission?

    These problems all seem to stem from allowing programs to take exclusive control of your audio device. Unfortunately you will have to disable this on a device-by-device basis. Fortunately, if you already disabled most of them as explained above, this shouldn't take too long.

    Actually, first make sure your preferred device is set as both the default device and the default communications device. Yes, they can be different. No, I have never found that useful.

    No!

    Yes!

    Now that that's out of the way, click your device and go to Properties, then click on the Advanced tab.


    The "Allow applications to take exclusive control of this device" will probably be checked. Uncheck this box (the other checkbox will automatically disable once you do this). You may have to restart the offending applications or your computer for this to take effect.

    Why Do I Sound Like a Robot? Or: Why Does Everyone Else Sound Like a Robot?

    This tends to be caused by a mismatch between the sampling rate of your audio device and the application, or possibly an audio device buffer overflow. Fixing the sample rate mismatch can be a bit hit or miss (example below). You might be able to set it in the program you're using, or you might have to set the audio device to match the program.
     
    Where to adjust the sample rate can differ depending on your audio device. If it came with any sort of driver software package, that's the first place to look. For my Scarlett interface, the dialog looks like the following:

    For most devices, you can likely adjust it from the Device Properties > Advanced tab as reached in the previous section. Click the dropdown in the Default Format section and select the appropriate sample rate.


    Fixing a buffer overflow is a little easier. The simplest and most aggressive way is to just power cycle your audio device, whether it's unplug and replug your USB mic, or flipping the power switch on your USB audio interface. Sometimes you can do this while your program is running, but probably the most reliable method is to close the important program (Discord, Skype, etc), power cycle, start back up. 

    Why Do I Sound Like a Robot in Discord? 

    Fun fact! Despite the proliferation of prosumer audio equipment boasting sample rates of 96 kHz or more, Discord doesn't support sample rates higher than 48 kHz. Sorry to say, you're going to have to lower your sample rate down to 48 kHz, as explained in the previous section.
     
    This is only half of the solution however. Next, open Discord and go to Settings > Voice & Video. Scroll down until you reach the Audio Subsystem dropdown. Click this dropdown, and change the subsystem from standard to legacy.


    If all goes well, your problems should be solved!
     
    Caveat: sometimes my outgoing Discord audio still glitches out. After doing all of the above, I guess it must be a overflowed buffer, so I still have to occasionally close Discord, restart my interface, and restart Discord.

    Why Does My Mic Sound Blown Out?

    If you're using a separate mic and audio interface, the gain is probably too far up on your audio interface.

    On a USB mic, it's a little trickier. Go to Sound Control > Recording > [your microphone] > Levels. There's a slider that will probably be set to 100. Bring this down to 80 or 60.

    Conclusion

    While this is by no means all-encompassing, I hope this has been helpful! My plan is to update this post as I run into more issues, so please feel free to pass this on, or leave a comment with additional problems or solutions.