Back to MiscEl main page | Write a message to author |

MiscEl contains lots of different calculations and some of them are very usefull when working with microprocessors. This page will high light these functions and possibilities.

To multiply with PI, select the page Integer math function "Real to Mult/Div", then write PI in the value field:

355/113 is within 8.49e-8 of the correct value. When using 16 bit operations the input range is 0..366 (with signed value: -183 to 183). I.e. to multiply with rougly PI your can multiply with 355 and divide with 113 and then your do not need to include a floating point package in your code (At least for this operation).

To multiply with PI and keep high performance, select the page Integer math function "Real to Mult/Div with x/2^n", then write PI in the value field:

201/64 is within 308ppm of the correct value. When using 16 bit operations the input range is 0..326 (with signed value: -163 to 163). I.e. to multiply with rougly PI your can multiply with 201 and shift the result 6 bit right

To divide a value with (rougly) 23.5, select the page Integer math function "Real to Mult/Div with x/2^wordsize", then write 1/23.5 in the value field:

Result on 8 bit MPU: Multiply by 11 and use the upper word of the result.

Result on 16 bit MPU: Multiply by 2789 and use the upper word of the result.

If your just need to known how many bits are required for a number, this page also has the function for that, this is called "Bit size".

Getting from number of bits to possible contents in these bits, check "Word size".

- Get some sample data pair (Desired value and ADC readout).*
- Fill these values into the curve fit input table.*
- Select the fit algorithm that gives the best curve.
- Save a table or formula from the page
- Paste the table or formula into your program
- Adapt the formula/table to your programming language

- In Calculator select "Curve/Table setup" and enter in X: "t*100/2/pi" and in Y1: "sin(t)*127"
- Fill in the "Table" parameters Start: "0", End: "2*pi", Steps: "101" and press "Fill"
- In the table, right click and select "Table to clibboard X,Y"
- Goto Curve fit and paste the table into the data input
- Delete first line (The one with "X Y1")
- Select Fit format: "Spline", Data format: "x <tab> f(x)" and Fit steps: "100"
- Select Save format: "Y (uint8, ofs)" (This will offset all negative values) and press "Save"

It is possible to enter any data and get listing of the exact timing for each bit.

MiscEl can help with this, the CRC and checksum page can be used to analyze data for what crc parameters are used or it can calculate a crc for some data, making it possible to verify your crc calculations.

When using table driven crc routines, MiscEl can also generate the tables.

The help page CRC calculations show code for all the different kind of crc algorithms that are used.

Terminate number with h or H, i.e. 7fh or 0e67H are hexadecimal values (Note: They must start with a digit)

Prefixing a number with $ of 0x, i.e. $ef or 0xf567 are hexadecimal values

Use Hex(Value) to display value as hexadecimal, i.e. hex(13) will return a string with 0000000D

a BitAnd b

a BitOr b

a BitXor b

SHL(Value,shift) // Shift left

SHR(Value,shift) // Shift right

BitExtract(Value,FirstBit,Bits) // Extract a number of bits

BitReplace(Value,NewBits,FirstBit,Bits) // Replace a number of bits

BitSet(Value,Bit) // Set specified bit, i.e. BitSet(0,4) is 10000B

BitReset(Value,Bit) // Reset specified bit, i.e. BitReset(11111111B,4) is 11101111B

BitInvert(Value,Bit) // Invert specified bit, i.e. BitInvert(0,4) is 10000B

BitMask(Bits) // Return a mask with Bits number of 1 bit, i.e. BitMask(3) is 111B

BitNot(Value) // Invert value

BitReverse8(Value) // Reverse bit direction (i.e. lsb move to msb) in a byte

BitReverse16(Value) // Reverse bit direction (i.e. lsb move to msb) in a word

BitReverse32(Value) // Reverse bit direction (i.e. lsb move to msb) in a dword

Most of these functions are for usage in scripts/functions, here is an example:

Nipple="Low nipple: "+BitExtract(Param[0],0,4)+" High nipple: "+BitExtract(Param[0],4,4)Copy this line to the calculator input line, right click with the mouse and select "Create function". Now your can use Nipple(125) to displays nipples in a byte. If your want a multi line output from a function use chr(13)+chr(10) as line delimeter. When the result is to large for the result line a result page will open, and this page will respect line delimeters.