Adding a voltage does not work in spice

Hi,
I am trying to create a model for ACS712 30V and it works well when I use a voltage source in the schematic. I have tried to replace the the VDC by adding the 2.5 V in the program which failed. What is the reason? The schematic is attached.
I have tried the following statement
Hsub out+ out- Vnam {gain*2.5/30+2.5} which results in an error
model ACS715

I’m not very good with ngSpice stuff. I can’t even find an HSOURCE in my KiCad V8 libraries. The closest is an ESOURCE. You can add “stuff” directly into the Simulation Model part of the Symbol Properties

The syntax of your text block does not make sense to me. How is KiCad to know that whatever text you added there is related to the H1 symbol?

When
Hsub out+ out- Vnam {gain*2.5/30}
is ok, the above should be o.k. as well. Of course it will not be the same as when you add the VDC source.

What is the error message?

with offset of 2.5V (Hsub out+ out- Vnam {(gain *2.5/30)+2.5}) the Voltage shown is 77.5V rather than the expected 5V.



Die pictures show the circuit, the lib file and the output

with gain = 1, and a current I = 30 A

output = (gain*2.5/30) * I = 2.5

with the offset

output = (gain * 2.5/30 +2.5) * I = (0.08333 + 2.5)*30 = 2.58333*30 = 77.5

The value in {} is the multiplier to the input current.

So the title of this thread is awfully wrong!

thanks for reply. I understand that my syntax obviously is wrong.
i want to generate a the symbol for the AC715 but shift the output voltage by -2.5V but I am struggeling with the syntax.
What would be the correct syntax instead of
Hsub out+ out- Vnam {(gain *2.5/30)}
so that I get the offset for the circuit below:

If you look at chapter 4.2.4 Hxxxx: Linear Current-Controlled Voltage Sources (CCVS) of the ngspice manual, you will see that there is no option for the H source to define an offset. So put a voltage source in series to the output.

thanks for your response. I further studied the suject and I believe I understand better the concept, but I still need to test it:

  1. create the entire circuit and simulate it
  2. once it works go to simulation → show spice net list
  3. copy the entire net list a put in a text file and make it a subciruit by adding
    .subckt name “list of inputs” *first line
    copy of netlist
    .ends *last line
  4. delete e.g. the line where V1 is defined and add V1 to the ‘list of inputs’
    save it as .lib and use it as simulation model.

Please let me know if this should work

Yes, it should.

I have done this with several eamples, e.g. at Simulation examples for KiCad/Eeschema/ngspice with A bipolar 741 operational amplifier, A CMOS version of the famous 555 timer circuit, and A 555 with bipolar transistors, and at Simulation examples for KiCad8/Eeschema/ngspice with The venerable ICL8038, using transistors, but of course you may use any spice-compatible element inside of your subcircuit.

thanks for your encouraging response. I studied your referenced examples and it helped me