??? 10/23/07 16:47 Read: times |
#146088 - Climax time Responding to: ???'s previous message |
Jason Arkwright said: ,How would I adjust sample time and integration time? Christoph Franck said:
The latter by modifying a. By sample time, do you mean the sampling period of the ADC ? 1)By sample time, means the time taken between each ADC sample, in my case this is 0.35 secs, which calibrates the filter to secs 2)By integration time, means adjusting your CR time whilst the processor is running, in otherwords the end user can adjust the filter time in mSecs,secs,minutes or hours to his desire. Heres your difference equation: y(n) = (1 - a) * y(n-1) + a * x(n-1) How would I adjust it as outlined in 1 and 2 using your difference equation? Christoph Franck said:
The homogenous part of the differential equation should be the same no matter whether you're charging or discharging the capacitor, since the charging/discharging is expressed in the particular part of the equation. Correct, I introduced the negative sign to indicate the gradient dVc/dt goes negative during discharging and positive during charging. Christoph Franck said:
The are other ways of getting from other domains to a difference equation (for example the bilinear transformation, which transforms a transfer function in the Laplace domain to a transfer function in the z domain). Christoph, I am well aware of what Z transforms do, they produce iterative/recursive difference equations whilst Laplace/Heaveside_switchers transforms transform from the frequency domain to time domain. There are other much easier ways of handling differential equations, like using commutating methods, which I use, but we don't even have do that and infact we can run a differential equation(ODE) directly in software with a little thought. we have.... dVc=[(E-Vc)/cr]*dt.....(1)charging dVc=[(Vc-E)/cr]*dt.....(2)discharging final output(Vc(t+1))=Vc(t)+dVc cr= adjustable integration time of the filter dt= sample time, in my case 0.35 secs Heres my CR filter routine.... In_filter: Dti = Adc_present - Adc_last ;test charging/discharging If Dti < 0 Then ; if neg. then exec. following code Dti = Adc_last - Adc_present Dti = Dti * 0.35 ; calibrate filter to secs Dti = Dti / Fil_time ; fil_time=cr time (adjustable) Adc_last = Adc_last - Dti ; form final output Gosub Disp ; display it Return End If Dti = Dti * 0.35 ; if discharging then go here Dti = Dti / Fil_time Adc_last = Adc_last + Dti Gosub Disp Return Cheers Jason |