BLDC Version of Marcos Alonso's LTSpice

Sorry but I am new to anything simulation related and I was trying to come up with a Qspice version of the Marcos Alonso’s BLDC.

I could not make it run.
I know there is an existent model done Krismon Budiono & Arief Noor Rahman but I wanted to do a version of my own so that I can edit the subcircuits.


I keep running into this kind of issue:

Fatal Error: Unknown Subcircuit X3

Thanks for any insight or help you will willingly offer.

Hi it’s Arief here

Can you post the model here?

Arief


  • Subcircuit to generate BLDCM back emfs and hall sensor outputs

.subckt bemf a b c n thetat amp hc hb ha
Ea a N value= {if(V(theta)<pi/6, V(amp)V(theta)/(pi/6),if(V(theta)<5pi/6, V(amp),

  • if(V(theta)<7pi/6, V(amp)-V(amp)(V(theta)-5pi/6)/(pi/6), if( V(theta)<11pi/6, -V(amp),
  • if(V(theta)<2pi, -V(amp) + V(amp)(V(theta)-11pi/6)/(pi/6),0) ) ) ) )}
    Eb b N value={if(V(theta)<pi/2, -V(amp), if( V(theta)< 5
    pi/6, -V(amp)+V(amp)(V(theta)-3pi/6)/(pi/6),
  • if( V(theta)<9pi/6, V(amp), if(V(theta)<11pi/6, V(amp)-V(amp)(V(theta)-9pi/6)/(pi/6),
  • if( V(theta)<2pi, -V(amp), 0 ) ) ) ) )}
    Ec c N value={if(V(theta)<pi/6, V(amp), if( V(theta)<3
    pi/6, V(amp)-V(amp)*(V(theta)-pi/6)/(pi/6),
  • if(V(theta)<7pi/6, -V(amp), if(V(theta)<9pi/6, -V(amp)+V(amp)(V(theta)-7pi/6)/(pi/6),
  • if( V(theta)<2pi, V(amp), 0 ) ) ) ) ) }
    XUhc 0 ca hc comp Vhigh=5 Vlow=0
    Eca ca 0 value={V(c)-V(a)}
    XUhb 0 ab hb comp Vhigh=5 Vlow=0
    Eab ab 0 value={V(a)-V(b)}
    XUha bc 0 ha comp Vhigh=5 Vlow=0
    Ebc bc 0 value={V(b)-V(c)}
    Rin1 thetat 0 10Meg
    Rin2 amp 0 10Meg
    E1 theta 0 value={ ( V(thetat)/(2
    pi) - floor( V(thetat)/(2*pi) ) )2pi}
    Rin4 theta 0 10Meg
    .ends bemf

  • BLDC motor

.subckt bldcm pha phb phc tload ea eb ec ha hb hc te w wrpm thetarot nr
XU1 a b c n thetat N007 hc hb ha bemf
La N001 N002 {L-M}
Lb N003 N004 {L-M}
Lc N005 N006 {L-M}
Ra N001 pha {R}
Rb N003 phb {R}
Rc N005 phc {R}
XU2 thetarott thetat Gain A={npp}
XUa N002 a ia isense k=1
XUb N004 b ib isense k=1
XUc N006 c ic isense k=1
XU3 ea ia N008 mul
XU4 eb ib N009 mul
XU5 ec ic N017 mul
XU6 N008 N009 N017 Pe Adder3
XU7 Pe w Te div eps=1e-6
XU8 Te N016 N010 Sub2
XU9 N010 Tload N011 Sub2
XU10 N016 Constant K={To}
XU13 N011 N015 N012 div eps=0
XU14 N015 Constant K={J}
XU11 N012 N013 Integ ic=0
XU12 N018 thetarott N019 mul
XU15 N018 Constant K={Bv/J}
XU16 N013 N019 N014 Sub2
XU18 w N007 Gain A={Kv}
XU21 w wrpm Gain A=60/(2pi)
XU22 a n ea Sub2
XU23 b n eb Sub2
XU24 c n ec Sub2
XU17 w thetarott Integ ic=0
XU29 N014 w abs k=1
E1 nr 0 value={ floor( V(thetarott)/(2
pi) )}
Rin1 nr 0 10Meg
E2 thetarot 0 value={ ( V(thetarott)/(2*pi) - V(nr) )2pi}
Rin2 thetarot 0 10Meg
.ends bldcm


  • Comparator

.subckt comp in+ in- out
E1 out 0 value = {if(V(in+, in-)>0, {Vhigh}, {Vlow})}
Rin+ in+ 0 10Meg
Rin- in- 0 10Meg
Rin in+ in- 1Meg
.ends comp


  • Gain

.subckt Gain in out
E1 out 0 value={A*v(in)}
Rin in 0 10Meg
.ends Gain


  • Current sensor

.subckt isense in+ in- out
V1 in+ in- 0
E1 out 0 value = {k*i(V1)}
.ends isense


  • Multiplier

.subckt Mul in1 in2 out
E1 out 0 value = {V(in1)*V(in2)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
.ends Mul


  • Adder, 2 inputs

.subckt Adder2 in1 in2 out
E1 out 0 value={v(in1)+v(in2)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
.ends Adder2


  • Adder, 3 inputs

.subckt Adder3 in1 in2 in3 out
E1 out 0 value={v(in1)+v(in2)+v(in3)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
Rin3 in3 0 10Meg
.ends Adder3


  • Divider

.subckt Div in1 in2 out
E1 out 0 value = {V(in1)/( V(in2) + eps)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
.ends Div


  • ABS

.subckt abs in out
E1 out 0 value = {k*abs(V(in))}
Rin in 0 10Meg
.ends abs


  • Subtractor, 2 inputs

.subckt Sub2 in1 in2 out
E1 out 0 value={v(in1)-v(in2)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
.ends Sub2


  • Subtractor, 3 inputs

.subckt Sub3 in1 in2 in3 out
E1 out 0 value={v(in1)-v(in2)-v(in3)}
Rin1 in1 0 10Meg
Rin2 in2 0 10Meg
Rin3 in3 0 10Meg
.ends Sub3


  • Constant

.subckt Constant out
E1 out 0 value={K}
.ends Constant


  • Integrator

.subckt Integ in out
E1 in1 0 value={v(in)}
E2 out 0 value={i(L1)}
L1 ind 0 1
R1 ind in1 1n
Rin in 0 10Meg
.ic i(L1) {ic}
.ends Integ

I cannot upload attachments for some reason, sir. Sorry

Refer to this post to elevate your trust level to a basic member and upload your schematic.

It will be better if you post the Qsch file here.

you can either follow the @KSKelvin suggestion to elevate your level, or upload it somewhere and paste the link to those file here.

BldcCy.qsym (2.2 KB)
This is the Qsym

BldcCy.lib (5.3 KB)
The library at which it is pointing at.

4c_BLDC_Cy.qsch (2.9 KB)
This is the schem

interesting but man this is very disorganized i will try to make a circuit and test it but i not sure with what file to start and what i working or not.
Please explain what file is from where and what is what also i didn’t see Alsonsos BLDC model on Git
Here is how i would do it:
1 make the BLDC model with in a schematic and make that work.
2 add features progressively over the established working model
3 repeat
If i were to simulate something i am not sure if i would want a model with current sense included and BEMF since i will make that on the PCB and sizing up components is part of the problem not to mention making the current sense circuitry.
Yes it would be nice to have an exact value to compare against but not critical.
When it comes to a simple BLDC model i am mostly looking for this:

  • electrical 3-6 phase input
  • mechanical load input
  • mechanical position* as in to see if it spins at all and if it did how fast this is mostly
    As of now when i see the models i ma not even sure what i am looking at and i sort of have no idea what i need to do with them since there may be problems if left open , like a thermal output in a mosfet model, it ether gets virtually super hot or fets some sudden shuts down for no obvious reason.
1 Like

It is a mathematical model

It was also assumed that the motor is constructed in such a way that the back emf is trapezoidal. This already runs in LTspice. The benefit of having this in Qspice is that we can plug in the FOC code and test the model.

The model was derived from subcircuits, and I think it still is valid. Just needed to convert it to Qspice. I am also building this through schem. I apologize as like I said, I am not into simulations until Qspice came out.

@aloysius Well, I believe you have done your best. Building the symbol is not the most challenging part; you have included all the necessary subcircuits in the subcircuit netlist. The most challenging aspect is replicating the example in Prof. Marcos Alonso’s BLDCM LTspice example. If the example is successfully replicated, we can verify that everything has been correctly implemented in Qspice. Possibly, this is too challenging for anyone new to Qspice.

In the LTspice example, a 74138 3-to-8 decoder is used, but the LTspice subcircuit utilizes an A-device, which is not available in Qspice. Therefore, I had to construct a 74138 subcircuit symbol with a Qspice logic device to support this replication work. Everything is embedded in the schematic; simply download the .qsch file, and you can run this example.

@marcos.uniovi This discussion thread requests your BLDC model in Qspice. I don’t see that in your Github and therefore worked out this one. Feel free to take this back.

BLDCM-QspiceByKSK.qsch (43.4 KB)
BLDCM-Qspice.lib (4.6 KB)
BLDCM.qsym (5.3 KB)


Wow! A big thanks Sir Kelvin! I actually did the model for the decoder and tested it and verified the outputs with the truth table posted by the datasheet but I think i was not able to figure out how to run it with the motor. I really thought there is something wrong with the motor model as I only made the subcircuits that I can’t find. Also, I had trouble debugging the parts separately, like the back emf as I do not know how to input the rotor angle from 0-2pi. A very big thanks sir!
How did you do the boundaries and the convergence, sir? Any chance you can teach how to do them?

The model is already built into the program in the ACT72350 examples.

1 Like

the model is already posted in Sir Kelvin’s posting. It runs really well.

Does BLDC model in Krismon’s work exactly the same as Marcos Alonso BLDC model? My impression is that Krismon made some changes. But I didn’t review that.

Here, I think @aloysius is looking for an exact replicate of Marcos LTspice BLDC model and its example. This is the reason I follow exactly what the LTspice model provided.

Oh, this one has no convergence issue. You might have noticed many .options in the graphical command block, but all of them are default settings except one. I designed this block so that I can easily modify option parameters. The only adjustment I made was setting feather=0.1. I placed this block in the schematic purely to enhance its appearance and to encourage others to consider switching to Qspice. Qspice is not only superior in simulating circuits but also in terms of its schematic drawing capabilities.

wow, that is nice. Although I can only copy and paste parts of the schem that you did. =) But I am playing with multiplying things and the like. Will make teaching bldc a lot easier as they can see the waveforms themselves =) thank you very much, Sir!

All symbols used in my schematic can be download from my Github, here is the link:
Qspice/Symbols-KSKelvin at main · KSKelvin-Github/Qspice
You can clone it with Github desktop, or download individual symbol directly from Github webpage.