Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

C-script based counter(or relay ) works at wrong frequency

0 votes

I am utilizing C-Script to realize a counter, I set the frequency at 10kHz, however,my result shows that my  counter works at a double speed.

And my code is as follows:

static int count2=0;

if (IsMajorStep)





if(InputSignal(0, 0) >0.6&&InputSignal(0, 0)<=0.9)






OutputSignal(0, 0) =1;



OutputSignal(0, 0) =0;




I reckon that the counter will reaches the peak value every 0.6 seconds ,but in fact,the conter reaches the peak value every 0.3 seconds, so what's wrong?

asked Jul 30, 2020 by shichenseu (299 points)

1 Answer

0 votes
I reckon that maybe it's just a problem  of Rising edge and falling edge of the c-script?Maybe a signal has been counted for twice?
answered Aug 2, 2020 by shichenseu (299 points)