This is a multi-part message in MIME format. ------=_NextPart_000_018D_01C5D170.120DE510 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit > with the input 0 (NEW = 0) and FF = 1 - K. It's not clear to > me whether James just wants to show decay of a capacitor > discharging thru a resistor, or model a full R/C filter where > the input could change. The latter, but that code is done and working. If I hand it a correct value of K, it does it's thing just fine. Actually, the code is based on the diagram I've attached to this email. It uses two constants, one is the original attenuation represented by at (a=RC) and the second attenuation is e^(-at). There is a routine that does fractional multiplication: ;For PIC Microcontrollers fracmul CLRW ;W=0 fracmul1 BCF status,c RRF arg1 ;ARG1:=ARG1/2 BCF status,c ; don't copy the carry RLF arg2 ;CY:=MSB(ARG2), ; ARG2:=ASL(ARG2,1) BTFSC status,c ;IF CY=0 SKIP THE ADD ADDWF arg1,w ;ELSE W:=W+ARG1 MOVF arg2 BTFSS status,z ;IF ARG2 NE 0 REITERATE GOTO fracmul1 RETLW 0h ;ELSE RETURN RESULT IN W So to attenuate the sample by at, we compute at as a fraction of 256 and put the sample in arg1, the fraction in arg2 and call this routine. That result is then set aside. Next we calculate the feedback from the last value which is attenuated by e^(-at) This is just the previous output value in arg1 and the fraction e^(-at) in arg2 and a call to the same routine, the results of the two calls are summed and that is the new output value. If I calculate the two values for arg2 and put them in, the code does exactly as expected and simulates a low pass RC filter having the values of R and C specified. I can get the assembler to calculate the first value with the code: at EQU 256* 360000/1000000 movlw at ;for a digital equivalent to an RC filter with a ;360kOhm resistor and a 1uF capacitor That puts 92 in w which is 92/256 = 0.360 = RC So that students may alter the R and C values somewhat and see the results. But I can't get it to calculate the second value e^(-at) Olin was exactly right in a previous post. You can't scale it by 256 (or any other constant) and then de-scale it by the same amount at the end. There may very well be more efficient ways to do this, but this way is directly derived from the diagram above and that diagram is very easily derived from the operation of the standard low pass RC filter circuit. Again, the point is education, not optimal operation. --- James. ------=_NextPart_000_018D_01C5D170.120DE510 Content-Type: image/gif; name="news0405f2[1].gif" Content-Transfer-Encoding: base64 Content-Dispos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zWj1atzP2u1a6iOjkKobXeBMF7LBPWqghiYm cjmwitztbmtbZ9rP3pVQ31pUpk7HWvX6NryTqe9zrXap654Xvfi1L2lPS90As/d2pRpq9fQr4Dsa WH+Hgi7mrsutAK6EwQ0Wzndhw7xWlvbDKVPujD4UwAXrNsOV7ewntbvdBzsGwyiWroTjp77sRgvE 4MVxjGkWt//WzsLDoaTXJrljw5ESyOU58XGLDET6Fs9kHlbxjF/J5CbnSpEwznGVUTg5nK7RxY3x 7JateWPCTDl+JRyzOK9MRzBHJbzKEVYzl6ME5/2l98JplvM51arjD2pPzyAUs2ul3MIeAnqCgs6q e+1s6EMbMNEH7jOdi+hoRPOZ0O2tNOwgTU9MD1jT9rw0gQsM6uhx+jlnDnOp4ynqRWt51QVNsadJ DetYZ1q8tK71uk6dRVf/Vde2/rSvgQvsXbe6jrcudqR4nc9Zv1rZPDs2rp8N7WVLe9DUrjbnrq1o Yms7gdyOdK6/vW1Zjzrb5NZSUNe9U7aw+91yS7e8503veqskIAA7 ------=_NextPart_000_018D_01C5D170.120DE510 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_018D_01C5D170.120DE510--