# C-Script for pwm input

**URL:** <https://forum.plexim.com/t/c-script-for-pwm-input/823>\
**Category:** PLECS\
**Tags:** c-script\
**Created:** [August 3, 2020, 4:12am UTC](https://forum.plexim.com/t/c-script-for-pwm-input/823 "2020-08-03T04:12:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![babackmn](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@babackmn](https://forum.plexim.com/u/babackmn)\
**Post date:** [August 3, 2020, 4:12am UTC](https://forum.plexim.com/t/c-script-for-pwm-input/823/1 "2020-08-03T04:12:14Z")

</div>

Hi

I want to know how to program the c-script for the attached matlab function

function a = fcn(x,ma,shift)

shift\_k= shift_pi/180; %converter degree to rad/s  
a= (ma_(sin((x)+shift\_k))); %refernce voltage

[C-Script.docx](https://forum.plexim.com/uploads/short-url/mbZzbAsTrDkeJ7xqwiAiarx7Mxa.docx) (24.7 KB)

---

<div class="post-metadata">

**Author:** ![Bryan\_Lieblick](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/bryan_lieblick/32/10_2.png) [@Bryan\_Lieblick](https://forum.plexim.com/u/Bryan_Lieblick)\
**Post date:** [August 10, 2020, 4:29pm UTC](https://forum.plexim.com/t/c-script-for-pwm-input/823/2 "2020-08-10T16:29:42Z")

</div>

Firstly, why use a C-script for something so trivial? You can easily build this out of basic PLECS components.

Secondly, please review the [PLECS Tutorials on C-Scripts.](https://plexim.com/support/tutorials?body_value=All&field_tutorial_product_value=1) The “PLECS: Using the C-Script Block” tutorial should give you all the background needed to complete this task. Refer specifically to Section 4 of the exercise which shows how to implement a basic mathematical function. There also is a reference case in \*.zip package you can download that is associated with the tutorial.
