PDA

View Full Version : Mixed Arithmetic Operation in IsoMax


stuey
02-05-04, 10:50 AM
Hi,

I am trying to perform a mixed arithmetic operation using IsoMax.

I need to know, whether it is indeed possible in IsoMax to
multiply a VARIABLE and FVARIABLE
store the resulting output in a VARIABLE.

If its not possible, then how can i achieve it using IsoMax?


If anybody can help. please let me know how to do it.

Thanks
Steve

g_jilek
02-05-04, 12:54 PM
Hi Steve,

The following code shows an example of using the floating point stack to calculate the running average of the AD Converter, then the result is stored as an integer.

Hope this helps,

Gerard

SCRUB

HEX

\ Analog Test Front-End Code

2VARIABLE RUN-AVG EEWORD
VARIABLE RUN# EEWORD \ Sets the Size of the Accumulator

DECIMAL
1.0E0 FCONSTANT SCALE EEWORD
HEX

: ADC_INIT ( -- ) \ Sets Up the Initial ADC Configuration
2000 0E80 ! \ Sets Start Bit & Once Sequential Scan Mode
0003 0E81 ! \ ADC Clock Period = IPbus/2N N=DIV[3:0]+1
3210 0E83 ! \ Default Scan Order
7654 0E84 ! \ Default Scan Order
0002 0E85 ! \ Sample Disable Register, (Only Channel 0 is Scanned)

0.0 RUN-AVG 2!
20 RUN# !
; EEWORD

: STARTCNV ( -- ) \ Provides Start Pulse to Initiate an ADC Conversion
2000 0E80 ! ; EEWORD

: 8/ 2/ 2/ 2/ ; EEWORD ( n -- n ) \ Fast 8 /, Right Shift

: ANA0 ( -- n )
E89 @ 8/ ( OUTPUT REGISTER FOR ADC CHANNEL ZERO
; EEWORD

: A/D ( -- ) \ Calculates the Running Average of the Analog Input
RUN-AVG 2@ D>F FDUP RUN# @ S>F F/ F- F>D ANA0 S->D D+ RUN-AVG 2!
STARTCNV ; EEWORD

: SMOOTHED. ( -- ) \ Scales the Floating Point Value & Converts it to an Integer
RUN-AVG 2@ D>F RUN# @ S>F F/ SCALE F* FDUP F. \ Displays both Values
FROUND F>D DROP .
; EEWORD


( TEST WORD
( DISPLAYS THE VALUE OF ADC REGISTER VS. SMOOTHED - Floating Point & Integer
: TESTZ DECIMAL BEGIN CR ANA0 . SMOOTHED. ?TERMINAL UNTIL ; EEWORD

ADC_INIT

EVERY 2000 CYCLES SCHEDULE-RUNS A/D \ Keeps the Algorithm Running

nmitech
02-05-04, 02:06 PM
First, Thanks g_jilek for your info and supports,

Here is additional info for stuey,

There are two ways to do this. Assuming these two variable names,

VARIABLE INT
FVARIABLE FLOAT


(1) Calculate the product in floating point and then convert to integer:

INT @ S>F FLOAT F@ F* F>D

which gives a double-precision integer result.

(2) Convert to double-integer and then calculate the product:

INT @ S>D FLOAT F@ F>D D*

which also gives a double-precision integer result.

Which is the best approach depends on the range of the data. E.g., if the floating point value is less than 1, you'll need to calculate the product in floating point. Approach #1 is probably safest.

stuey
02-06-04, 01:46 AM
Thanks to both of you for the support you provided. its a great help