Help for PWM problem in LTspice

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Thanks John_2016,

I know Matlab from hearsay in the signal processing group about 20 years ago, neverheard of simulink Sorry for that.

I can follow your pictures, my problem is that I want to generate pulses in a pulse file to generate a 1kHz sine wave.

This pulse file is used in a small uProcessor ( PIC12F629 ) ,

If you follow my simulation in LTspice than you see that I have use an ideal pulse width, but in reality the pulses

for the PIC will be truncated with a resolution op 200 Nano seconds.

This truncated file should be used in LTspice to see in the FFT if the required 70 dB suppression of harmonics

Is reached.

I will go to a better resolution 100nS or even In the future I want to try a non-equidistant filter, that means that marks en spaces
can vary a lot.

Regards
 

John_2016

Joined Nov 23, 2016
55
Hi Erik,

thanks for the point, I am aware of the intention of Watersnip to focus on LTSpice for this question but perhpaps Watersnip or any other reader
find useful the MATLAB solution, at a later time.

Regards

John BG
 

ericgibbs

Joined Jan 29, 2010
21,439
hi John,
It is expected practice within AAC to keep replies based on the Topic raised by the TS in his opening post.
Please keep future replies on Topic.
E
 

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Hi Eric,

Yes maybe you can help me with your expertise .

I have succeeded in using the PWL file and know now how to use it.

An idea from dutch professors ( 1970 ) is implemented in the PWL file.

This results in suppression of the 3e harmonic. see the uploaded files.

I am strugling now with the PWL file generation of the original idea,

If you look at the generation of a single sine than you will see that

about 100 points are required in the 0 to 1000 us interval.

Could you look into this problem ?

Best regards
 

Attachments

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Hi Mr Bordodynov, Yesterday evening at 11:00 I succeeded in running a PWL file

Many thanks for your solution, this evening I will post mine.

I have to do a study of your solution.

I had to take a lot of steps to find mine.

How did you calculate the distortion ?

Regards Guus ( Watersnip )
 

Bordodynov

Joined May 20, 2015
3,431
Draft793.png I made a simple search of options.I do a Fourier analysis and then scan the LOG file.I choose the best option.At first, I chose a narrow range of numbers.Now I managed to find a better option: Large amplitude and lower harmonic coefficient.I translate the number into binary code.
See
cir.png Plot.png
 

Attachments

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Hi Mr Bordodynov,

Attached are my files, I changed the filtering to Elleptic.

The steps to generate the file were as follows:

1) Measure in LTspice all the Pulses in time by hand ( 100 values for 50 pulses )
2) Put these in Excel
3) Since PWL makes a linear line between Point A and Point B, I made a second column
by adding 0.001 uSecond to the first 100 points.
4) Made a row with ( 1 point A 1 Point B )
row with ( 0 point A+1 0 Point B +1 )
5) Added the u sign behind these values
6) Copied this 50 times.
7) Saved this file in Word and then as a Text file.
8) Had a hell of a job to find the exact syntax for a PWL file


Comment on the FFT result , still too high 2e harmonic.

Regards Guus ( Watersnip )
 

Attachments

Thread Starter

Watersnip

Joined Oct 18, 2018
17
I just found that I can improve at least the amplitude by changing in the PWL file the 1 to 5
So the amplitude in the simulation is higher.

Regards
 

Bordodynov

Joined May 20, 2015
3,431
I will tell you how I understood the task.
I thought that the task was to use a microcontroller and using a microcontroller, feeding a "0" or "1" every 20µs to get after filtering 1kHz.I did it.But at the very end you just made a PWL file! This could be done (file) using a modulator and LTspice.You only need to configure the output of the RAW file in ASCII format.It is only necessary to remove the header at the beginning of the file.
All this is done quickly and easily!If you know what to do, of course.:)
 

Thread Starter

Watersnip

Joined Oct 18, 2018
17
I did correct a visible mistake in the PWL file,
but am afraid that I made more small errors.
I tried your method, but could not find a readable output file.
Maybe you could help how to do this.
I am also interessed in your harmonic calculation.

Regards Guus
 

ericgibbs

Joined Jan 29, 2010
21,439
hi W,
I also tried the spreadsheet method for the PWL, a real chore.
You asked earlier about Audacity creating a 1kHz pulse wave, attached sample.[ change extension from txt to wav]

Checking your filter post #30, the notch for 2 harmonic suppression is off the 2kHz point.
E

Added 3rd image, modified filter.
 

Attachments

Last edited:

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Sorry Eric I could not translate your file to wav.

Yes I see that the notch for 2e harmonic is off.

I did correct a visible mistake in the PWL file,

but am afraid that I made more small errors.

But the FFT was far better.

FFT  PWL 50 samples to pwm elleptic.JPG
 

ericgibbs

Joined Jan 29, 2010
21,439
hi Guus,
All you need to do with that 1kHz file is to change the name from Sqr1000Hz.txt to Sqr1000Hz.wav
BTW: Audacity can produce Tones, Chirps as Square or Sine.
E
 

Thread Starter

Watersnip

Joined Oct 18, 2018
17
Hi All,

When I do download the txt file I get a lot of gebberish,
Please make a zip file for me with the correct wav extention.

Guus
 

ericgibbs

Joined Jan 29, 2010
21,439
hi Guus,
If you try to read wav file data as text, it does look like gibberish, its an audio file.
E


EDIT:
Added working folder with a asc demo, keep them in same folder.
 

Attachments

Last edited:

Alec_t

Joined Sep 17, 2013
15,117
in reality the pulses for the PIC will be truncated with a resolution op 200 Nano seconds. This truncated file should be used in LTspice
If it helps, here's how to create a PWL file (as attached) with data points at 100ns rounded intervals :-
1) Run your post #3 sim, but for 1ms only and with maximum timestep = 10ns,
2) Click on the plot window and use 'File/export data as text',
3) Import the file into a spreadsheet,
4) Delete the column header text,
5) Convert the number format from scientific to normal, with 7 decimal places for the time data,
6) Replace all tab characters with commas,
7) Save the amended file and specify it as the PWL source.
 

Attachments

Top