function [time,feed,speed]= calc_signal(port,Vref,kp,ki,kd,max_time)
    t=tic;
    index=1;
    errprev=0;
    errprev2=0;
    integral1=0;
    write_volt(port,0);
    while(toc(t)<max_time)
            t1=tic;
            [tacho,rpm]=read_sig(port);
            error=Vref-tacho;
            if(error>4)
                error=4;
            else if(error<-4)
                    error=-4;
                end
            end
            time(index)=toc(t);
            feed(index)=tacho;
            speed(index)=rpm;
            dt=toc(t1);
            fun_p=error*kp;
            integral1=integral1+(error);
            fun_i=integral1*ki;
            fun_d=kd*(error-errprev);
            total=fun_p+fun_i+fun_d;
            write_volt(port,total);
            index=index+1;
            errprev2=errprev;
            errprev=error;
            
            
            
            
         
    end
    write_volt(port,0);
    
    
    
end