Help for PWM problem in LTspice

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Hi all,
I am new to this forum, so may be this question is raised before.
I want to simulate a 1 Khz signal with PWM.
I have a PWM file of 50 pulses spaced at 20 u-seconds, but how should I apply that.
A filter is added that suppresses unwanted harmonics.
In the future I want to try a non-equidistant filter, that means that marks en spaces
can vary a lot.
 

Thread Starter

Watersnip

Joined Oct 18, 2018
17
I am not new to Ltspice, but cannot figure out to put these pulses in a file that can be used.
My previous idea is to generate the file as follows.
but in reality the samples are truncated to the nearby value
so instead of nearby ideal, it is far from ideal
 

Attachments

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Yes I have seen this solution, but here again the PWM is derived from an ideal world.
The real question is how to put in a file into this,
something like On for 10 usec, off for 10 usec, on for 14 usec, off for 6 usec etc
 

Hymie

Joined Mar 30, 2018
1,284
In is relatively simple to create a PWM circuit using an astable 555 timer circuit, varying the control voltage (pin 5).

If you ask nicely, I’ll post the circuit from my 555 timer cookbook.
 

HW-nut

Joined May 12, 2016
97
Linear Tech’s ltc6992 will generate a PWM signal over a wide frequency range and LT spice would have the simulation model.
 

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Many thanks for your time,

I am trying to simulate in LTspice a sine wave derived from pulses.
This is a step-up for the future, I want to try a non-equidistant pulse scenario, that means that marks en spaces
can vary a lot.
So I will have a " pulse " file that should be put into LTspice and generate the wanted waveform.
With LTspice I do an FFT to see what the theoretical limits are.
This is for hobby, I don't have an Audio analyser , so on a scope I
will see a max of 20dB Harmonic suppression, while I want to go to > 60 dB
 

Bordodynov

Joined May 20, 2015
3,180
Hi all,
I am new to this forum, so may be this question is raised before.
I want to simulate a 1 Khz signal with PWM.
I have a PWM file of 50 pulses spaced at 20 u-seconds, but how should I apply that.
A filter is added that suppresses unwanted harmonics.
In the future I want to try a non-equidistant filter, that means that marks en spaces
can vary a lot.
You can send your PWM file.Then I will help.If it is of course in a test format.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,849
hi,
A possible method. Rough guide.
1. Download Audacity a free audio program.
2. On the top menu bar Generate /Chirp
3. Set the params of the Chirp and duration.
4. File/Export as WAV. [name it]
5. Move the wave file to the LTSpice folder that has the asc file.
6. Refer the attached image for a basic asc test circuit.

The test chirp file should give you an idea if this method is suitable for your app.

With Audacity it is possible to Record audio thru thru the PC's Line input.
Export the saved file as a wav file and use the new wav file as an input to to your PWM and Gyrator.

E
 

Attachments

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Thanks from you all,

I have added my ideally generated file for Mr Bordodynov,
It takes 20 minutes on my PC to run, The FFT shows a great result,
I want to use this in an less ideal world where the pulse widths ate truncated to 200 nS.
So an ideal pulse width of 12.371 uS pulse is reduced to 12.4 uS
This is valid for all pulses.

I have looked into the PWL file, But do not know how to generate this.

Regards
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,849
hi W,
Did the wav file option not meet your requirement for file generation.
BTW: for the sim posted, as the sine source is only 1kHz, why do you run the sim for 100mSec.?

E
AA1 21-Oct-18 10.33.gif
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,849
hi,
Done a simple test, Audacity chirp.wav 500Hz > 1500Hz over 1 sec.
This is what I see on the modified sim.
I would say its a possible way of doing some initial testing of your project.

E

chirp1a.wav is the saved file from the sim run.

AA1 21-Oct-18 11.22.gif
 
Last edited:

John_2016

Joined Nov 23, 2016
55
Hi Watersnip

you can use the following MATLAB functions:
modulate
https://uk.mathworks.com/help/signal/ref/modulate.html?searchHighlight=modulate&s_tid=doc_srchtitle
demod
https://uk.mathworks.com/help/signal/ref/demod.html?searchHighlight=demod&s_tid=doc_srchtitle

This allows to directly code the functions you need to generate the sought file

Another option is SIMULINK.
Following, MATLAB example, if interested in the SIMULINK version please let me know:


fc=1e3;
Nc=30; % amount of samples per cycle

fs=Nc*fc;
Np=3; % amount cycles of input signal to generate

t=[0:1/fs:Np/fc];
x=sin(2*pi*fc*t)+randn(size(t))/10;
figure(1);plot(t,x);grid on
title('input signal +noise')




X=fft(x,2056)
figure(2);plot(abs(X));grid on
title('FFT X(f)')
axis tight




% conditioning signal

x=x-mean(x);
% DC block

% x(x>1)=1 % avoid clipping with hard limiter
x=1/(max(x)-min(x))*x; % or normalise input signal peak2peak amplitude to value 1 a bit of attenuation

x=x+abs(min(x));
% rise for PWM to work, PWM doesn't take negative input

y=modulate(x,fc,fs,'pwm');
% PWM modulation, can't be any easier than this line

t2=linspace(0,t(end),numel(y));
figure(3);plot(t2,y);grid on
axis tight




y2=y-mean(y);
Y=fft(y2,2056);
figure(4);plot(abs(Y));grid on;axis tight;title('FFT |Y(f)|')




x3=demod(y,fc,fs,'pwm');

figure(5);plot(t,x3);grid on
title('demodulated signal')


John BG
 

John_2016

Joined Nov 23, 2016
55
Hi Watersnip

with MATLAB

file_name='pwm_example1.wav'
audiowrite(file_name,y,fs)


to import audio files use command audioread

John BG
 
Top