once again, thanks for the wonderful pid filter. im still troubleshooting, and my main problem is this;
Code:
 MAIN:                                             
     IF POSITION < SETPOINT THEN                  ;decreasing the setpoint                
     pid_Error = setpoint - position            ;calculate error
     ENDIF
     IF POSITION > SETPOINT THEN                  ;increasing the setpoint
     PID_ERROR = 65535-(POSITION - SETPOINT)    ;calculate error                                                              
     endif         
     gosub pid                                  ;take error to pid filter  
     DIRECTION = pid_out.15                     ;determine direction
     PID_TEMP = ABS PID_OUT
     DUTY = PID_TEMP                            ;load duty cycle from pid_out
     select case DIRECTION                      ;direction bit to control    
     case 0                                     ;  hpwm 1 for forward or hpwm2     
     GOSUB FORWARD                              ;  for reverse to corresponding
     case 1                                     ;  h-bridge circuit 
     GOSUB BACKWARD                             ;
     END SELECT
     LCDOUT $FE, $80, "POS=" ,DEC5 POSITION, " SP=" ,DEC5 SETPOINT; temporary
     LCDOUT $FE, $C0, "DT=" ,DEC5 DUTY, " ERR=" ,DEC5 PID_ERROR   ; temporary                 
     goto Main
my calculated pid_error jumps from 65534 to 00001 , skipping two numbers; 65535, and 00000. i have the recommended position calculation,
Code:
 position = 256*poscnth + poscntl
this runs from a dt_interrupt (thanks Darrel Taylor). i tried to change setpoint and position variables to byte, instead of word, but pid filter works on word variables, and all calculations get messed up. any solutions? this has been my biggest headache on this project, for the last three weeks. and any help from anyone will be highly appreciated. thanks in advance.