Analog to Digital Converter block
- q :
Type 'vec' of size -1. The level step.
- vmin :
Type 'vec' of size -1. The first input value where the convertion begins.
- type :
Type 'vec' of size -1. Set the type of the quantification.
- number of bit :
Type 'vec' of size -1. The number of bit of the CAN. Set also the maximum input level.
- code complément ŕ 2 (0/1) :
Type 'vec' of size -1. Set if the output integer is unsigned or signed.
- always active: no
- direct-feedthrough: no
- zero-crossing: no
- mode: no
- number/sizes of inputs: 1 / 1
- 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: no
- name of computational function: can
CAN_f.sci
c can.f Analog to Digital Convertor
c IRCOM Group - A. Layec
c REVISION HISTORY :
c $Log$
c
subroutine can(flag,nevprt,t,xd,x,nx,z,nz,tvec,ntvec,
& rpar,nrpar,ipar,nipar,u,nu,y,ny)
double precision t,xd(*),x(*),z(*),tvec(*),rpar(*),u(*),y(*)
integer flag,nevprt,nx,nz,ntvec,nrpar,ipar(*)
integer nipar,nu,ny
integer i,j
double precision fsr
do 15 i=1,nu
if(ipar(i).eq.1)then
if (u(i).lt.0.0d0)then
y(i)=rpar(i)*(ANINT(u(i)/rpar(i)+0.5d0))
else
y(i)=rpar(i)*(ANINT(u(i)/rpar(i)-0.5d0))
endif
elseif(ipar(i).eq.2)then
c qzrnd.f
if (u(i).lt.0.0d0)then
y(i)=rpar(i)*(ANINT(u(i)/rpar(i)+0.5d0)-0.5d0)
else
y(i)=rpar(i)*(ANINT(u(i)/rpar(i)-0.5d0)+0.5d0)
endif
elseif(ipar(i).eq.3) then
c qzflr.f
y(i)=rpar(i)*ANINT(u(i)/rpar(i)+0.5d0)
elseif(ipar(i).eq.4) then
c qzcel.f
y(i)=rpar(i)*ANINT(u(i)/rpar(i)-0.5d0)
endif
15 continue
do 20 i=1,nu
fsr=(2**ipar(i+nu))*rpar(i)
if(y(i).lt.rpar(nu+i)) then
y(i)=rpar(nu+i)
elseif(y(i).gt.(rpar(nu+i)+fsr))then
y(i)=rpar(nu+i)+fsr
endif
c write(6,'(''fsr='',e10.3,'' ipar(i+nu)='',i1)') fsr,ipar(i+nu)
c write(6,'(''rpar(nu+i)+fsr='',e10.3)') rpar(nu+i)+fsr
20 continue
do 30 i=1,nu
y(i)=aint( (y(i)-rpar(nu+i))/rpar(i))
c write(6,'(''y(i)='',e10.3,''s= '',i1)') y(i),2**(ipar(i+nu)-1)
if(ipar(2*nu+i).eq.1)then
y(i)=y(i)-(2**(ipar(i+nu)-1))
endif
30 continue
end
IRCOM Group
Alan Layec