Pulse Generator block
- Rise Time :
Type 'vec' of size 1. The Rise Time.
- Fall Time :
Type 'vec' of size 1. The Fall Time.
- Time in High State :
Type 'vec' of size 1. The High State.
- Delay time :
Type 'vec' of size 1. The Delay time.
- Period :
Type 'vec' of size 1. The Period.
- Value at high state :
Type 'vec' of size 1. The Value at high state.
- Value in low state :
Type 'vec' of size 1. The Value in low state.
- always active: no
- direct-feedthrough: no
- zero-crossing: no
- mode: no
- number/sizes of inputs: 0 /
- number/sizes of outputs: 1 / 1
- number/sizes of activation inputs: 1 / 1
- number/sizes of activation outputs: 0 /
- continuous-time state: no
- discrete-time state: yes
- name of computational function: genpulse
GENPULSE_f.sci
/* Variable duty cycle pulse generator
* Type 2 simulation function ver 1.0 - scilab-2.6&2.7
* february 12th 2004 IRCOM Group R. Quere
*/
/* REVISION HISTORY :
* $Log$
*/
#include "machine.h"
#include <math.h>
/* This function returns a variable duty cycle pulse waveform
* The parameters of the pulse are in the rpar vector in the following order
* rpar[0]=Trise Rise time of the pulse (default=0)
* rpar[1]=Tfall Fall time of the pulse (default=0)
* rpar[2]=Thigh Time duration in the high state (default=1)
* rpar[3]=Td Time delay of the pulse (default=0)
* rpar[4]=Tp Period of the pulse, if Tp=0 there is only one pulse (default=0)
* rpar[5]=Ahigh Value of the pulse in the high state (default=0)
* rpar[6]=Alow Value of the pulse in the low state (default=0)
*/
void genpulse(flag,nevprt,t,xd,x,nx,z,nz,tvec,ntvec,rpar,nrpar,
ipar,nipar,inptr,insz,nin,outptr,outsz,nout)
integer *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar,insz[],*nin,outsz[],*nout;
double x[],xd[],z[],tvec[],rpar[];
double *inptr[],*outptr[],*t;
{
/*déclaration des variables*/
double *y;
double t1, t2, t3, t4, tc, tp, Ahigh, Alow;
int nu,i;
y=(double *)outptr[0];
t1=rpar[3];
t2=t1+rpar[0];
t3=t2+rpar[2];
t4=t3+rpar[3];
tp=rpar[4];
Ahigh=rpar[5];
Alow=rpar[6];
if(*flag==4)
*y=z[0];
else if (*flag==1 || *flag==6)
*y=z[0];
else if (*flag==2)
{ if (tp == 0)
{if (*t < t1)
z[0]=Alow;
else if (*t<t2)
z[0]=(*t-t1)*(Ahigh-Alow)/(t2-t1)+Alow;
else if (*t<t3)
z[0]=Ahigh;
else if (*t<t4)
z[0]=(*t-t3)*(Alow-Ahigh)/(t4-t3)+Ahigh;
else
z[0]=0;
}
else
{ tc=*t-floor(*t/tp)*tp;
if (tc < t1)
z[0]=Alow;
else if (tc<t2)
z[0]=(tc-t1)*(Ahigh-Alow)/(t2-t1)+Alow;
else if (tc<t3)
z[0]=Ahigh;
else if (tc<t4)
z[0]=(tc-t3)*(Alow-Ahigh)/(t4-t3)+Ahigh;
else
z[0]=Alow;
}
}
}
IRCOM Group
Alan Layec