Spice netlist that square wave (pulse) as input and give sawtooth as output where pulse has positive voltage.

Thread Starter

santlal

Joined Jan 14, 2020
22
I want to write a subckt which take pulse voltage as input and give sawtooth voltage as output. The sawtooth only appears where pulse voltage values are positive, and the rest of the time it will be zero.
An image file is attached that descrive input/output.
Any help or hints will be greate.
 

Attachments

Thread Starter

santlal

Joined Jan 14, 2020
22
Hi Papabravo,
I did integration and the netlist is as below:

********* sawtooth depending on input pulse******************************************************
.subckt conditional_sawtooth inputsignal outputsignal
.func sawtooth(inputsignal)=if(inputsignal>0, idt(inputsignal),0)
b1 outputsignal 0 V=sawtooth(V(inputsignal))
.ends output_interface


vin in 0 pulse(-1 1 0 1n 1n 25m 50m)
Xsaw in output conditional_sawtooth
.tran 200m
.end


The output is attached here but I want little modification in output. I need the output starts from 0 .
 

Attachments

Papabravo

Joined Feb 24, 2006
21,264
Hi Papabravo,
I did integration and the netlist is as below:

********* sawtooth depending on input pulse******************************************************
.subckt conditional_sawtooth inputsignal outputsignal
.func sawtooth(inputsignal)=if(inputsignal>0, idt(inputsignal),0)
b1 outputsignal 0 V=sawtooth(V(inputsignal))
.ends output_interface


vin in 0 pulse(-1 1 0 1n 1n 25m 50m)
Xsaw in output conditional_sawtooth
.tran 200m
.end


The output is attached here but I want little modification in output. I need the output starts from 0 .
The thing you should integrate is the unit step function. Looking at the description of the idt function:
B. Arbitrary Behavioral Voltage or Current Sources
idt(x[,ic[,a]]) Integrate x, optional initial condition ic, reset if a is true.
IMHO you should write something like this:
idt(1, 0, [a]) ; integrate the unit step with initial condition 0 as long as [a] is false. Stop the integration when [a] is true.​
Take a look at the buf(x) and inv(x) functions for easy ways to create a Boolean condition from an input signal.
 

Papabravo

Joined Feb 24, 2006
21,264
Here is a quick demo I whipped up.
1673535189629.png
You can connect B1 & B2 in series to get a continuous sawtooth and you can change the duty cycle of V1 to unequal peaks on the sawtooth.
You can also do it with behavioral current sources, but they require additional components to convert the current into a voltage. If the amplitude is not to your liking, you can add a gain factor to the behavioral sources.
 

Attachments

Top