# How to simulate a square wave current control on a BLDC motor

**URL:** <https://forum.plexim.com/t/how-to-simulate-a-square-wave-current-control-on-a-bldc-motor/1185>\
**Category:** TI C2000\
**Tags:** hall-sensor\
**Created:** [November 30, 2022, 8:21am UTC](https://forum.plexim.com/t/how-to-simulate-a-square-wave-current-control-on-a-bldc-motor/1185 "2022-11-30T08:21:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberto](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Alberto](https://forum.plexim.com/u/Alberto)\
**Post date:** [November 30, 2022, 8:21am UTC](https://forum.plexim.com/t/how-to-simulate-a-square-wave-current-control-on-a-bldc-motor/1185/1 "2022-11-30T08:21:48Z")

</div>

Goodmorning,

as the title of this question states I would like to know how to simulate a BLDC motor with a square wave current using PLECS,  
TI Launchpad F28069M, the TI DRV8305EVM inverter and the BLDC QBL42018-100 motor from Trimac.

I see on [https://www.plexim.com/sites/default/files/demo\_models\_categorized/rtbox/launchpad\_interface\_demo.pdf](https://www.plexim.com/sites/default/files/demo_models_categorized/rtbox/launchpad_interface_demo.pdf) that what I’m trying to do is possible  
but this example is for RT-Box which I don’t have and can’t use.

My aim is to use the Hall signals as a position sensor so that a square wave current control would be possible. Same signals, as the example above states, are inputs for the duty cycle calculation.  
Are there specific examples for this?

I get the theoretical basis about square wave commutation and the PWM chopping related to it, but I’m struggling translating this into PLECS:  
the PWM modules from the library don’t have a “Chopper” window like Symulink has, so I find quite difficult creating the PWM Chopping by using a C-Script.

Is it possible to create such control using PLECS blocks from library with proper manipulation of the signals or is it required to use ad-hoc blocks which library doesn’t have?

Attached you can find the file I’m working on where the Hall signals are imported via digital inputs and are later manipulated via a C-script to calculate which sector is  
at the moment.  
Duty cycles are still calculated form a current loop in the bottom side of the file where current are read by an ADC and then transformed into DQ quantities.

Hoping I’ve been clear enough, I wish someone will answer me.  
Thanks in advance,

Alberto

[sqrWAVE\_hall.zip](https://forum.plexim.com/uploads/short-url/juKgQgjeoakMxf9a50SyyWxTkEX.zip) (11.6 KB)

---

<div class="post-metadata">

**Author:** ![Manu\_Parimi](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/manu_parimi/32/6_2.png) [@Manu\_Parimi](https://forum.plexim.com/u/Manu_Parimi)\
**Post date:** [December 6, 2022, 11:27am UTC](https://forum.plexim.com/t/how-to-simulate-a-square-wave-current-control-on-a-bldc-motor/1185/2 "2022-12-06T11:27:05Z")

</div>

Contacted the requestor directly to discuss this question.

- Manu
