PDA

View Full Version : Best way to get the square root of a 16/32 bit unsigned integer



sougata
- 17th March 2008, 19:01
Hi All,

In one of my implementation of a true RMS voltmeter I used the Mchip technical bulletin TB040 to find the square root of a 16bit number. I was using the ADC in 8bit on a PIC18. I would like the pros to shed some light on a better way dealing with longs sqrt.

P.S. = Perhaps a better way to measure AC RMS

skimask
- 17th March 2008, 19:06
find the square root of a 16bit number
Since it's only a 16 bit number, maybe you'd be best off using a lookup table. After all, there are only 255 integer numbers of squares inside of 16 bits...

EDIT: Whoops! Just saw that the title said 16/32 bit sqrt instead of 16 bit only.

But...I'd say, same thing still applies. Could easily get the sqrt of the upper 16 bits of the 32 bits using a lookup table. Then depending on the accuracy required, interpolate the lower 16 bits.

Acetronics2
- 17th March 2008, 19:29
Hi, Sougata

I do not understand your question ...

TB 040 ALSO deals with 32 bits ...




; ************************************************** *****************
Title"16/32 bit Integer Square Root"
; ************************************************** *****************
; ************************************************** *****************
; *** ***
; *** Author: Ross Fosler ***
; *** Applications Engineer ***
; *** Microchip Technology Inc. ***
; *** ***
; *** Program:sqrt.asm ***
; *** This module contains code to perform fast integer ***
; *** square root functions on either 16 or 32 bit ***
; *** values. ***
; *** ***
; *** Last Rev:August 10, 2000 ***
; *** Ver 1.00 ***
; *** ***
; ************************************************** *****************



????

Are you looking for faster than that ???

Alain

sougata
- 18th March 2008, 04:29
Hi Alain,

I am actually looking for a faster and better way to do it. Cause my system measures 16 channels and does a whole lot of logging housekeeping stuff.