James Newtons Massmind wrote: > Could I get a hand with simplifying some calculations in integer math? Sounds like floating point math would be more suitable. My PIC preprocessor lets you do a bunch of assembly time calculations using floating point, then convert to integer right before using it in the actual assembly instructions. > I would like to calculate some values to plug into simple digital filter > code inside the actual assembler. The assembler supports integer > variables of 32 bits precision. The idea is that the student can put in > the actual values of the R and the C in a basic RC type low pass filter > and the code will load the literal values appropriate for the digital > simulation of that filter. The digital realm is a bit different from the analog realm. First, specifying an R and C value is really only specifying a single value since there is no issue of impedence in the digital filter. For your purposes, only the product of R and C matter. But you do need an additional parameter that isn't relevant in the analog domain: the filter iteration rate. Inside the processor it doesn't make sense to talk about a half life, for example, of 100mS. You can only specify a half life in filter iterations, which may take a lot less or a lot more time than the analog filter which always operates in real time. The simple digital filter FILT <-- FILT + FF * (NEW - FILT) is a low pass filter with an exponential decay just like an RC analog filter. Note there is only one parameter to adjust. I call it FF for "filter fraction". FF of 0 is an infinitely heavy filter as the output never changes. FF = 1 disables all filtering since the input is just passed to the output. Values in between simulate real RC low pass filters, within the constraint of discrete samples of course. > The voltage change with time across a capacitor is an exponential > function. If the voltage at time zero is V, then the voltage at time t > is given by Ve^(-at) (a is the Same constant as above). They failed to mention that the input voltage is assumed to be 0 in this case. I don't think any text this sloppy is worth spending time on. > I need to find e^(-at) given the value of at. No, you don't. You are thinking of modeling analog again instead of embracing digital. There is no need (and it would take a lot more cycles) to compute the full equation of the filter each iteration. Simple incremental operations performed each iteration as shown above will model the filter without ever requiring exponentiation. > E^(-at) is the same as (1/e) ^ (at) right? Yes. > Now, 1/e is approximately 368/1000 and so I can calculate a power by > making a macro in the assembler that multiplies that value times itself > (at) times and then take that time 256 divided by 1000. The value (at) > can not be more than 255/256 and probably will not be more than about > 192/256. > > 368^192 exceeds 32 bits by a little tiny bit. > > I guess the question is: How does one calculate a fractional power to > any degree of accuracy in 32 bit integer math? This sounds like more beating of head against wall. You can make this easy on yourself by using the FFTC2 or FFREQ inline functions in my preprocessor. These both calculate FF given appropriate parameters. You can then do additional floating point manipulations until finally ending up with the integer value you will use in the fixed point multiply by FF. Another strategy is to make sure FF ends up being 2 ^ -N so that the multiply by FF becomes just a right shift. To get an arbitrary "frequency" response you adjust the filter iteration frequency. The PREPIC documentation file is at http://www.embedinc.com/pic/prepic.txt.htm. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist