Forums

Quantization and sample/hold in spice

Started by Klaus Kragelund August 18, 2017
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
On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund
<klauskvik@hotmail.com> wrote:

>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
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
On Friday, August 18, 2017 at 4:14:29 PM UTC+2, John Larkin wrote:
> On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund > <klauskvik@hotmail.com> wrote: > > >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 > > 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 >
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
On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund
<klauskvik@hotmail.com> wrote:

>On Friday, August 18, 2017 at 4:14:29 PM UTC+2, John Larkin wrote: >> On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund >> <klauskvik@hotmail.com> wrote: >> >> >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 >> >> 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 >> >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
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.
On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund
<klauskvik@hotmail.com> wrote:

[snip]
>> >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
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.
On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund
<klauskvik@hotmail.com> wrote:

>On Friday, August 18, 2017 at 4:14:29 PM UTC+2, John Larkin wrote: >> On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund >> <klauskvik@hotmail.com> wrote: >> >> >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 >> >> 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 >> >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
Well, use LT Spice! -- John Larkin Highland Technology, Inc picosecond timing precision measurement jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On Fri, 18 Aug 2017 11:10:22 -0700, John Larkin
<jjlarkin@highland_snip_technology.com> wrote:

>On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund ><klauskvik@hotmail.com> wrote: > >>On Friday, August 18, 2017 at 4:14:29 PM UTC+2, John Larkin wrote: >>> On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund >>> <klauskvik@hotmail.com> wrote: >>> >>> >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 >>> >>> 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 >>> >>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 > >Well, use LT Spice!
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.
On Fri, 18 Aug 2017 11:24:34 -0700, Jim Thompson
<To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote:

>On Fri, 18 Aug 2017 11:10:22 -0700, John Larkin ><jjlarkin@highland_snip_technology.com> wrote: > >>On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund >><klauskvik@hotmail.com> wrote: >> >>>On Friday, August 18, 2017 at 4:14:29 PM UTC+2, John Larkin wrote: >>>> On Fri, 18 Aug 2017 06:13:59 -0700 (PDT), Klaus Kragelund >>>> <klauskvik@hotmail.com> wrote: >>>> >>>> >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 >>>> >>>> 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 >>>> >>>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 >> >>Well, use LT Spice! > >Just proves my point that most simulator users don't actually know how >to use their simulator. > > ...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
On Fri, 18 Aug 2017 11:52:17 -0700, John Larkin
<jjlarkin@highland_snip_technology.com> wrote:

>On Fri, 18 Aug 2017 11:24:34 -0700, Jim Thompson ><To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >
[snip]
>> >>Just proves my point that most simulator users don't actually know how >>to use their simulator. >> >> ...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.
PSpice has all kinds of behavioral blocks, plus I've created many more.
> >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,
Nor math.
>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?
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.
Den fredag den 18. august 2017 kl. 19.53.14 UTC+2 skrev Jim Thompson:
> On Fri, 18 Aug 2017 09:42:57 -0700 (PDT), Klaus Kragelund > <klauskvik@hotmail.com> wrote: > > [snip] > >> > >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 > > 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 >
Many thanks :-) (like doing an integer division in C) Cheers Klaus