Quantization and sample/hold in spice

Hi

I need to introduce and error in a signal, both quantization and sample/hold

Sofar I have done it by placing an opamp based sample/hold followed by a 8bit ADC (ADC8break) and a 8 bit DAC (DAC8break)

But it doesn't feel right to use that much circuitry just to simulate an error in the system

Anyone know if it can be done with ABM blocks? (sample and hold can be done with a zero order hold I think, but the quantisation is more difficult)

Some sort of rounding function?

Or I could use the C interface API, and write it in code, but that seems stupid also

Cheers

Klaus

Reply to
Klaus Kragelund
Loading thread data ...

Spice has an ideal sample/hold.

Here's a quantizer:

Version 4 SHEET 1 880 680 WIRE 48 48 0 48 WIRE 112 48 48 48 WIRE 384 48 320 48 WIRE 432 48 384 48 WIRE 0 96 0 48 WIRE 112 112 112 48 WIRE 320 112 320 48 WIRE 432 128 432 48 WIRE 0 224 0 176 WIRE 112 224 112 192 WIRE 320 240 320 192 WIRE 432 240 432 208 FLAG 0 224 0 FLAG 320 240 0 FLAG 112 224 0 FLAG 432 240 0 FLAG 48 48 X FLAG 384 48 OUT SYMBOL bv 320 96 R0 WINDOW 3 36 198 Left 2 SYMATTR Value V=int(5.1*V(X))*0.2 SYMATTR InstName B1 SYMBOL voltage 0 80 R0 WINDOW 3 16 199 Left 2 WINDOW 123 0 0 Left 2 WINDOW 39 0 0 Left 2 SYMATTR Value SINE(0 1 1k 0 0 0 3) SYMATTR InstName V1 SYMBOL res 96 96 R0 SYMATTR InstName R1 SYMATTR Value 1k SYMBOL res 416 112 R0 SYMATTR InstName R2 SYMATTR Value 1k TEXT 144 40 Left 2 !.tran 0 .005 0 1u

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

Great, I will try it out (although I have problems finding the INT() function in pspice and the ability to feed into the equation the voltage from a node name net directly)

Cheers

Klaus

Reply to
Klaus Kragelund

EVALUE ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson
[snip]

PSpice Reference Guide Before you begin July 2006 17 Product Version 15.7 Expressions can contain the standard operators as shown in the following table:

ceil(arg) Returns an integer value. The argument for this function should be a numeric value or an expression that evaluates to a numeric value. If arg is an integer, the return value is equal to the argument value. If arg is a non-integer value, the return value is the nearest integer greater than the argument value. Example: ceil(PI)=4 ceil(5)=5 ceil(5.4)=6

floor(arg) Returns an integer value. The argument for this function should be a numeric value or an expression that evaluates to a numeric value. If arg is an integer, the return value is equal to the argument value. If arg is a non-integer value, the return value is the nearest integer smaller than the argument value. Example: floor(PI)=3 floor(5)=5 floor(5.4)=5

...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

Well, use LT Spice!

--

John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

Just proves my point that most simulator users don't actually know how to use their simulator. ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

I haven't used Pspice, but I found the "BV" block quantizer easy to create. I had to play with the equation a bit to get precise 0.1 volt steps, but that's not a Spice issue, it's just math.

Dumping a BV block on the schematic prompts you for an equation, so it's pretty easy. I had a little confusion about syntax, but that's OK now.

I think a lot of simulator users don't really understand electronics, especially hobbyists without a formal EE education. They fiddle with circuits. Nothing wrong with that as a hobby, I guess.

We wouldn't want everybody to be good at electronic design, would we?

--

John Larkin         Highland Technology, Inc 
picosecond timing   precision measurement  

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

[snip]

PSpice has all kinds of behavioral blocks, plus I've created many more.

Nor math.

No ;-)

...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

Den fredag den 18. august 2017 kl. 19.53.14 UTC+2 skrev Jim Thompson:

Many thanks :-) (like doing an integer division in C)

Cheers

Klaus

Reply to
viableletter

Den fredag den 18. august 2017 kl. 20.10.40 UTC+2 skrev John Larkin:

I have 20 years of simulation blocks and earlier project in PSpice, so that is not an option. And Capture PSpice gives me some features not available in LTSpice

Cheers

Klaus

Reply to
viableletter

Den fredag den 18. august 2017 kl. 20.24.48 UTC+2 skrev Jim Thompson:

I have never had the need for a "rounding" function before

These days I only do in average 1 hours per week simuation

Reply to
viableletter

In PSpice....

You can put slicing point "down the middle" by using both ceil() and floor(). ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

As in...

...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

Very nice, thanks :-)

I am looking into THD magnitude versus microcontroller PWM resolution in a PMSM drive. Higher PWM resolution equates into more accurate motor field vectors and more smooth control

Very limited papers about that out there

Cheers

Klaus

Reply to
Klaus Kragelund

Happy to have been of help! ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| STV, Queen Creek, AZ 85142    Skype: skypeanalog |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 

             I'm looking for work... see my website. 

Thinking outside the box...producing elegant & economic solutions.
Reply to
Jim Thompson

You can delta-sigma or noise dither low-resolution DACs or PWMs to get more effective resolution.

--

John Larkin         Highland Technology, Inc 

lunatic fringe electronics
Reply to
John Larkin

Yes, but in this case the problem is that the microcontroller is running at max speed, and the max clock frequency and the inverter stage frequency sets the number of effective dutycycles.

So, say a 30MHz timer clock, and a switching frequency of 20kHz, the number of different dutycycles possible is 1500

Cheers

Klaus

Reply to
Klaus Kragelund

ample/hold

d by a 8bit ADC (ADC8break) and a 8 bit DAC (DAC8break)

ate an error in the system

n be done with a zero order hold I think, but the quantisation is more diff icult)

seems stupid also

d

in a PMSM drive. Higher PWM resolution equates into more accurate motor fie ld vectors and more smooth control

at max speed, and the max clock frequency and the inverter stage frequency sets the number of effective dutycycles.

er of different dutycycles possible is 1500

per cycle, but you might be able to average over multiple cycles

Reply to
Lasse Langwadt Christensen

und:

:

sample/hold

wed by a 8bit ADC (ADC8break) and a 8 bit DAC (DAC8break)

ulate an error in the system

can be done with a zero order hold I think, but the quantisation is more di fficult)

at seems stupid also

and

n in a PMSM drive. Higher PWM resolution equates into more accurate motor f ield vectors and more smooth control

t

g at max speed, and the max clock frequency and the inverter stage frequenc y sets the number of effective dutycycles.

mber of different dutycycles possible is 1500

Yes, that might have an effect. I do not know if the FOC algoritm does that already, will check :-)

In any case, it is probably way lower than the effect of the non-ideal dist ribution of the windings

Cheers

Klaus

Reply to
Klaus Kragelund

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.