Hola, primero q nada mis disculpas, ya poi5on tiene razon en que la derivada de una constante es cero.. y olvide explicarles la idea de la rutina que tengo.
La idea es conectar mediante software el conversor a/d del pic a un registro con la idea de variar un registro cualquiera... en un loop cerrado, y a medida que vaya variando ese registro ir obteniendo el valor de la derivada que deseo en otro registro.
Ahora, la rutina de derivada q encontre esta en la aplication note
http://ww1.microchip.com/downloads/en/AppNotes/00544d.pdf de la microchip
Esta rutina es para la familia de los pic17... y por ignorancia no podria cambiarlo ya que hay instrucciones q desconozco, como el movfp y otros
;*******************************************************************
00968 ; Numerical Differenciation
00969 ;
00970 ; The so called “Three-Point Formula” is implemented to
00971 ; differenciate a sequence of points (uniformly sampled).
00972 ; The eqn implemented is :
00973 ; f’(Xn) = [ f(Xn - 2h) - 4*f(Xn - h) + 3*f(Xn)]*0.5/h
00974 ; where Xn is the present sample and ‘h’ is the step size.
00975 ;
00976 ; The above formula may be rewritten as :
00977 ;
00978 ; f’(Xn) = [ 0.5*f(Xn -2) - 2*f(Xn - 1) + 0.5*3*f(Xn)]*1/DiffK
00979 ; where DiffK = h = Step Size
00980 ;
00981 ; This differenciation routine can be used very effectively
00982 ; in the computation of the differential component part in
00983 ; a PID Loop calculation in Motor Control Applications
00984 ;
00985 ; Double precision arithmetic is used throught
00986 ; The present sample value is assumed to be in locations
00987 ; (XnHi, XnLo). The past two values are assumed to be in locations
00988 ; (Xn_1_Hi, Xn_1_Lo) & (Xn_2_Hi, Xn_2_Lo).
00989 ; The output value is located in DiffHi & DiffLo. No overflow
00990 ; checking mechanism is implemented. If the values are limited
00991 ; to 12 bits, then the user need not worry about overflows
Ó 1997 Microchip Technology Inc. DS00544D-page 4-33
AN544
00992 ;
00993 ; It is user’s responsibility to update the past values with the
00994 ; present values before calling this routine.
00995 ; After computation, the present value Xn is not moved to Xn_1
00996 ; because the user may want these values to be intact for other
00997 ; computations ( say numerical integration)
00998 ; Also it is user’s responsibility to set past 2 values
00999 ; (Xn_1 & Xn_2) values to be zero on initialization.
01000 ;
01001 ;*******************************************************************
01002 ;
02C6 01003 Diff
02C6 6A2B 01004 movfp Xn_2_Lo,WREG
02C7 0E27 01005 addwf XnLo,W
02C8 011A 01006 movwf ACCbLO
02C9 6A2C 01007 movfp Xn_2_Hi,WREG
02CA 1028 01008 addwfc XnHi,W
02CB 011B 01009 movwf ACCbHI ; Y = f(Xn-2) + f(Xn)
01010 ;
02CC 6A27 01011 movfp XnLo,WREG
02CD 0F1A 01012 addwf ACCbLO, F
02CE 6A28 01013 movfp XnHi,WREG
02CF 111B 01014 addwfc ACCbHI, F
02D0 6A27 01015 movfp XnLo,WREG
02D1 0F1A 01016 addwf ACCbLO, F
02D2 6A28 01017 movfp XnHi,WREG
02D3 111B 01018 addwfc ACCbHI, F ; Y = f(Xn-2) + 3*f(Xn)
01019 ;
02D4 8804 01020 bcf ALUSTA,C
02D5 191B 01021 rrcf ACCbHI, F
02D6 191A 01022 rrcf ACCbLO, F ; Y = 0.5*[ f(Xn-2) + 3*f(Xn) ]
01023
01024 ;
02D7 6A29 01025 movfp Xn_1_Lo,WREG
02D8 051A 01026 subwf ACCbLO, F
02D9 6A2A 01027 movfp Xn_1_Hi,WREG
02DA 031B 01028 subwfb ACCbHI, F
02DB 6A29 01029 movfp Xn_1_Lo,WREG
02DC 051A 01030 subwf ACCbLO, F
02DD 6A2A 01031 movfp Xn_1_Hi,WREG
02DE 031B 01032 subwfb ACCbHI, F ; Y = 0.5*[f(Xn-2) + 3*f(Xn)] - 2*f(Xn-1)
01033 ;
02DF 6A2D 01034 movfp DiffKLo,WREG
02E0 0118 01035 movwf ACCaLO
02E1 6A2E 01036 movfp DiffKHi,WREG
02E2 0119 01037 movwf ACCaHI
01038 ;
02E3 E119 01039 call D_divS
02E4 6A1A 01040 movfp ACCbLO,WREG
02E5 012F 01041 movwf DiffLo
02E6 6A1B 01042 movfp ACCbHI,WREG
02E7 0130 01043 movwf DiffHi ; result = Y/h
01044 ;
02E8 0002 01045 return
me despido, y gracias de antemano
