Simulating a (very simple) line level audio to digital input-compatible level interface

A little disclaimer upfront: I am completely self-taught in electronics, and never expanded beyond a very amateur level so far. I use KiCad mainly to design very simple boards in my free time. I always wanted to check out KiCad’s circuit simulation features (ngspice) more deeply.

My $dayjob involves lots of AV system integrations where I am often looking at small “glue circuits” (is this a term, like glue code?), just like this one, which is interfacing a bi-phase mark encoded signal, a LTC signal in this case, to a digital input pin:

simple A2D interface found online

(from Speed Reading LTC – Quelle Blog)

So my thought was: Hey, I know what this circuit is (supposedly) doing: Adding a DC offset so that the line level audio signal (alternating around 0V) will be shifted to a positive-only signal (0V + x). So it surprised me that after copying the schematic:

…and adding a model for the diode and the a model for the npn found online, the pulse signal is inverted (i.e. 0V - x), going below 0V:

Since I am fairly sure that the pin assignments of the diode and the npn line up between symbol and model (a common issue I learned from reading other posts), my best idea currently is that I am using the Pulse Source model wrongly (which I have added to the T/S Jack symbol):

I assume that I am missing something very basic, or made a beginner mistake somewhere, but I am currently out of ideas why I am getting this result?

I have attached my KiCad project here:
ltc-input-stage-for-digital-pin.zip (9.3 KB)

Do you have dc voltage source connected to the 5V label?

Is that like S/PDIF or AES/EBU?

I am confused by:

You have not mentioned where you are probing the circuit. It looks like Yellow is on the input connector, and red is on the node between D1 and R1. But I would have expected a 600mV diode junction threshold level over there, and I woul have expected the signal to shift upwards and not downwards. Setting up ngSpice simulations is tricky. I am guessing that the anode and cathode are switched around in between the schematic symbol and the spice model. (This is unfortunately quite common).

The red signal is not inverted, it is just level shifted.

This circuit is also supposed to invert the signal. When the BE junction of Q1 goes above 600mV, the collector also starts conducting current and the level on the collector gets lower. Polarity of digital audio is not important, and it can be inverted without problem.

And as lucas already mentioned. You need to add a voltage source for the spice simulation. The power symbol in KiCad is “just” a label, and it’s not a valid spice voltage source on it’s own.

I think I fixed your simulation. Is this output close to what you expect?

There were two issues:

  1. As I suspected in my previous comment: You have to add a DC voltage source to your +5V label. Kicad/ngspice will not automatically add any voltage sources to labels. But you have to add them explicitly.
  2. Your diode model was switched around. Unfortunately, spice convention is the opposite from what IPC norms define. I replaced the diode with the generic ngspice diode model, but adding your 4148 model back should be trivial. But for this circuit the generic model is most likely good enough.

Here is the fixed project:

tc-input-stage-for-digital-pin_fixed.zip (9.7 KB)

1 Like

Hey thanks for fixing! Yes that’s what I would have expected to see. So it was two beginner oversights as I assumed.

I remember checking the symbol properties for the +5V label and seeing something that made me assume it will act like a proper voltage source during simulation. Will double check again when I have time. But I took note that the power symbols are just labels…

What makes me wonder now is that I knew about the diode pin reversal issue before and I did check it. But well, I swapped around so many things trying to get it to work yesterday that maybe they ended up the wrong way when I uploaded the project.

Anyhow, lessons learned, thanks a lot!

1 Like

TBH, I have never looked at the wire protocol of those digital audio standards. It might be related, I simply don’t know. The interface circuit is meant to level shift Linear (or longitudinal) Timecode: Linear timecode - Wikipedia, which uses a bi-phase mark (or Manchester) encoding (an encoded 0 has one rising/falling edge, while an encoded 1 has two edges in the same time period).

And yes, I confused the meaning of “inverted”. In my initial post. Signal inversion doesn’t matter in a bi-phase mark encoded signal, as you only count the edges, not their direction. One reason why this simple circuit works quite well for the use case at hand.

1 Like

Ah, I see. These timecodes are something completely different. But it’s unrelated to KiCad and thus off topic.