# How do we use C Script box?

**URL:** <https://forum.plexim.com/t/how-do-we-use-c-script-box/263>\
**Category:** PLECS\
**Tags:** c-script, \#c\
**Created:** [February 3, 2018, 1:23am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263 "2018-02-03T01:23:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aviral](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Aviral](https://forum.plexim.com/u/Aviral)\
**Post date:** [February 3, 2018, 1:23am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/1 "2018-02-03T01:23:04Z")

</div>

How are inputs and outputs defined in the code?

Do we need a main function to run it?

Is a do-while loop required to run it forever? or it loops itself as in Arduino.

---

<div class="post-metadata">

**Author:** ![Falk\_Kyburz](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@Falk\_Kyburz](https://forum.plexim.com/u/Falk_Kyburz)\
**Post date:** [February 5, 2018, 3:53am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/2 "2018-02-05T03:53:39Z")

</div>

Hello Aviral,

Keep in mind that using the C-Script block is non-trivial and requires some deeper knowledge of PLECS. Try using PLECS blocks to create the required function first.

To start using the C-Script block, have a look at the C-Script chapter in the documentation and try some of the examples.

Best Regards

Falk

---

<div class="post-metadata">

**Author:** ![rcolbeck](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rcolbeck](https://forum.plexim.com/u/rcolbeck)\
**Post date:** [February 14, 2018, 6:26pm UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/3 "2018-02-14T18:26:41Z")

</div>

It’s not too bad to figure out. As Falk said start by reading the documentation and looking at the examples. It took me about a day to go through that and then try some simple scripts. I’m no expert now but I am now able to do state machines (although Plexim provides native support for state machines) and logic blocks in c-script. I’m actually converting some of these from Verilog into C.

I use a trigger so that the c-script is only executed on certain clock edges. It then might do a bunch of If/then/else statements, and updates its outputs, until asked to execute again.

…Roger

---

<div class="post-metadata">

**Author:** ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://forum.plexim.com/u/Sikander)\
**Post date:** [April 12, 2018, 11:49pm UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/4 "2018-04-12T23:49:15Z")

</div>

@Roger Need help about C-Script

---

<div class="post-metadata">

**Author:** ![rcolbeck](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rcolbeck](https://forum.plexim.com/u/rcolbeck)\
**Post date:** [April 13, 2018, 12:27am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/5 "2018-04-13T00:27:26Z")

</div>

How can I help?

Late here. Will try to answer tomorrow if you can give me some details.

Roger

---

<div class="post-metadata">

**Author:** ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://forum.plexim.com/u/Sikander)\
**Post date:** [April 13, 2018, 3:38am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/6 "2018-04-13T03:38:27Z")

</div>

I am trying to build MPPT block on C-script, there is no error in code. But still not getting desired duty cycle. Attached is the algorithm i implemented on C-script. Please guide me what changes i need to make.

[MPPT.docx](https://forum.plexim.com/uploads/short-url/jK8ySB4oIv8yM16C3j3rF5EidlW.docx) (294 KB)

---

<div class="post-metadata">

**Author:** ![rcolbeck](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rcolbeck](https://forum.plexim.com/u/rcolbeck)\
**Post date:** [April 13, 2018, 11:17am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/7 "2018-04-13T11:17:52Z")

</div>

ok probably best if someone from Plexim could help you but if I will try to find time to look at this, maybe this weekend.

…Roger

---

<div class="post-metadata">

**Author:** ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://forum.plexim.com/u/Sikander)\
**Post date:** [April 16, 2018, 12:14am UTC](https://forum.plexim.com/t/how-do-we-use-c-script-box/263/8 "2018-04-16T00:14:03Z")

</div>

Okay thanks. Will contact you soon.
