Diferencia entre revisiones de «Taller de distorsión»

Sin resumen de edición
Sin resumen de edición
 
(No se muestran 26 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
Podemos usar [https://en.wikipedia.org/wiki/Ngspice Ngspice] para simular la distorsión en circuitos.
Tené en cuenta si estás introduciendo un comando de shell o un comando de ngspice, y también si estás dando órdenes al shell o a ngspice. Para salir de ngspice, escribe "quit". Se recomienda colocar todos los archivos en un único directorio y utilizarlo para ejecutar la simulación.
Archivos que necesitas para esos ejemplos se colocan en este directorio: https://cloud.undernet.uy/s/ByzeA7arTfGdxGD
=clip=
=clip=
v1 es una fuente voltaje independiente. Consulta el capítulo en el manual de Ngspice:
* 4.1 Independent Sources for Voltage or Current
v1 tiene una onda de voltaje sinusoidal. Los parámetros se explican aqui:
* 4.1.2 Sinusoidal 
d1 es un diodo de modelo 1N4148, algo común. El diodo (y varios otros componentes) necesita un comando ".model" para especificar sus parámetros. Podés ponerlo en un archivo se llama 1n4148.lib y incluir ese archivo. El contenido del archivo debe ser esto:
<pre>
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1)
</pre>
Los parámetros del modelo del diodo se definan en el capitulo "7.2.1 Diode Model (D)" del manual usuario de Ngspice.
==Archivo SPICE (clip.cir)==
==Archivo SPICE (clip.cir)==
<pre>
<pre>
Línea 11: Línea 30:


==comandos==
==comandos==
* tran 10us 3s
* ngspice clip.cir (en el shell)
* plot v(sig) v(out)  xlimit 0 10m
* tran 10us 3s (en ngspice)
* plot v(sig) v(out)+1 xlimit 0 10m
* plot v(sig) v(out)  xlimit 0 10m (en ngspice)
* plot v(sig) v(out)+1 xlimit 0 10m (en ngspice)
* plot v(sig) v(out) 1000*-1*v1#branch xlimit 0 10m (en ngspice)


=amp 1=
=amp 1=
Línea 40: Línea 61:


==comandos==
==comandos==
* ngspice amp1.cir
* ngspice amp1.cir (en shell)
* plot v(sig) v(out) xlimit 0 3
* plot v(sig) v(out) xlimit 0 3 (en ngspice)
* fft v(out)
* fft v(out) (en ngspice)
* plot mag(v(out)) xlimit 0 10
* plot mag(v(out)) xlimit 0 10 (en ngspice)


=dist 1=
=dist 1=
Línea 73: Línea 94:


==comandos==
==comandos==
* ngspice amp1.cir
* ngspice dist1.cir
* plot v(sig) v(out) xlimit 0 3
* plot v(sig) v(out) xlimit 0 3
* fft v(out)
* fft v(out)
Línea 79: Línea 100:


=amp 2=
=amp 2=
Vamos a correr una simulación y escuchar a la salida del circuito.
Para hacerlo, generamos un archivo que contiene una grabación de los voltages durante la simulación.
Convertiramos ese archivo a un archivo de audio, en formato WAV.
Para eso, usamos los programas de [https://github.com/Ttl/spice-audio-tools Spice Audio Tools].
==Archivo SPICE (amp2.cir)==
==Archivo SPICE (amp2.cir)==
<pre>
<pre>
Línea 137: Línea 163:
* ngspice dist2.cir
* ngspice dist2.cir
* python spicetowav.py out.dat distout.wav
* python spicetowav.py out.dat distout.wav
=1n4148.cir=
<pre>
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1)
</pre>
=TL072.mod=
<pre>
* TL072 OPERATIONAL AMPLIFIER "MACROMODEL" SUBCIRCUIT
* CREATED USING PARTS RELEASE 4.01 ON 06/16/89 AT 13:08
* (REV N/A)      SUPPLY VOLTAGE: +/-15V
* CONNECTIONS:  NON-INVERTING INPUT
*                | INVERTING INPUT
*                | | POSITIVE POWER SUPPLY
*                | | | NEGATIVE POWER SUPPLY
*                | | | | OUTPUT
*                | | | | |
.SUBCKT TL072    1 2 3 4 5
*
  C1  11 12 3.498E-12
  C2    6  7 15.00E-12
  DC    5 53 DX
  DE  54  5 DX
  DLP  90 91 DX
  DLN  92 90 DX
  DP    4  3 DX
  EGND 99  0 POLY(2) (3,0) (4,0) 0 .5 .5
  FB    7 99 POLY(5) VB VC VE VLP VLN 0 4.715E6 -5E6 5E6 5E6 -5E6
  GA    6  0 11 12 282.8E-6
  GCM  0  6 10 99 8.942E-9
  ISS  3 10 DC 195.0E-6
  HLIM 90  0 VLIM 1K
  J1  11  2 10 JX
  J2  12  1 10 JX
  R2    6  9 100.0E3
  RD1  4 11 3.536E3
  RD2  4 12 3.536E3
  RO1  8  5 150
  RO2  7 99 150
  RP    3  4 2.143E3
  RSS  10 99 1.026E6
  VB    9  0 DC 0
  VC    3 53 DC 2.200
  VE  54  4 DC 2.200
  VLIM  7  8 DC 0
  VLP  91  0 DC 25
  VLN  0 92 DC 25
.MODEL DX D(IS=800.0E-18)
.MODEL JX PJF(IS=15.00E-12 BETA=270.1E-6 VTO=-1)
.ENDS
</pre>
=Archivo de WAV de entrada, WAV de salida=
Esta simulación consume el contenido de un archivo se llama [https://cloud.undernet.uy/s/FqfqEwxw7tsaHRy clean.wav].
Genera un archivo se llama out.wav.
Consulte en el [https://cloud.undernet.uy/s/mnjZEiEcPYB99NL manual de Ngspice]
* 8.2.9 Filesource (PWL sourced from file)
* 8.1 Code Model Element
* 8.1.1 %v represents a single-ended voltage port
* 8.1.1 Square brackets ([ ]) are used to enclose vector input nodes.
* 13.5.78 General Form: Shell: Call the command interpreter
* 13.5.56 General Form: Pre_<command>: execute commands prior to parsing the circuit
Necesitas esos archivos en el mismo directorio con el archivo SPICE (wav_in.cir):
# [https://cloud.undernet.uy/s/ST4wXi67BBNZac5 wavtospice.py]
# [https://cloud.undernet.uy/s/opnbgPRq6QmAepY spicetowav.py]
# [https://cloud.undernet.uy/s/FqfqEwxw7tsaHRy clean.wav]
==Archivo SPICE (wav_in.cir)==
<pre>
.title wave input
a1 %v([in]) filesrc
.model filesrc filesource (file="in.dat" amploffset=[0] amplscale=[100] timeoffset=0 timescale=1 timerelative=false amplstep=false)
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1)
r1 in out 1k
d1 out 0 1n4148
d2 0 out 1n4148
.control
  pre_shell python3 wavtospice.py clean.wav in.dat
  tran 0.02m 10
  wrdata out.dat v(out)
  shell python3 spicetowav.py out.dat out.wav
.endc
</pre>
==comandos==
Nota: Pasar la opción -b hace que se ejecute y luego finalice. Consulte "12.3 Command line options for starting ngspice" en el manual
* ngspice -b wav_in.cir
Ahora podés escuchar out.wav. Un ejemplo del archivo de salida es aquí: https://cloud.undernet.uy/s/e2fsjes6fy6P6Ei