SQUARE ROOT ON A PIC
This shows that every time the
base number, 10, is multiplied by 100,
an extra digit of precision is available
before the decimal point. If one
decimal digit of precision is needed,
the initial number must be multiplied
by 100. If two are needed, 10000
must be the multiplier. So, for every
digit of precision needed, just multiply
by 100 before the square root is
computed. It is essentially a two-digit,
decimal left shift.
Using the square root function
presented here and the small MCU
being used, it is not practical to
multiply an input number by 100
for each decimal digit. But if we
switch our thinking from decimal to
binary, we can still gain the desired
If the number is shifted up by two
bits, we gain one bit of fraction. In
decimal this bit represents 0.0 and
0.5. If we shift up by four bits, two
fractional bits are gained. These represent 0.00, 0.25, 0.50 and 0.75. And so
on. So a shift up by 14 bits will give
seven fractional bits giving a fractional
resolution of 1/128. This is even better
than the 1/100 given by shifting up by
two decimal digits. Again all needs for
a multiply have been avoided. This
does limit the maximum input number
to 18 bits. If less precision is needed,
say four bits, the maximum would
be 24 bits.
Often small MCUs are underestimated in the amount of real math
they can perform. Given a good
understanding of the constraints of
the intended use and a good grip of
math, they can perform astonishing
feats; including integer and fractional
square roots with out using a single
multiply or divide. NV
Noel Henson has been designing and
programming embedded systems for over 20
years. He has developed everything from simple
remote controls to custom supercomputers.
He currently owns Lane Mountain Logic, an
embedded design and programming firm.
NEW! HIDmaker FS for Full Speed FLASH PIC18F4550
Creates complete PC and Peripheral
programs that talk to each other over
USB. Ready to compile and run!
• Large data Reports
• 64,000 bytes/sec per Interface
• Easily creates devices with multiple
Interfaces, even multiple Identities!
• Automatically does MULTITASKING
• Makes standard or special USB HID
NEW! “Developers Guide for USB HID
Peripherals” shows you how to make
devices for special requirements.
Both PC and Peripheral programs
understand your data items (even odd
sized ones), and give you convenient
variables to handle them.
PIC18F Compilers: PICBASIC Pro,
MPASM, C18, Hi-Tech C.
PIC16C Compilers: PICBASIC Pro,
MPASM, Hi-Tech C, CCS C.
PC Compilers: Delphi, C++ Builder,
Visual Basic 6.
HIDmaker FS Combo: Only $599.95
DOWNLOAD the HIDmaker FS Test Drive today!