8 May 17:57
[PIC] - Need fast divide by 14 constant routine? ( Random access 8-bit data in PIC16F flash )
From: Ed Sutton <esutton <at> engius.com>
Subject: [PIC] - Need fast divide by 14 constant routine? ( Random access 8-bit data in PIC16F flash )
Newsgroups: gmane.comp.hardware.microcontrollers.pic
Date: 2008-05-08 15:59:19 GMT
Subject: [PIC] - Need fast divide by 14 constant routine? ( Random access 8-bit data in PIC16F flash )
Newsgroups: gmane.comp.hardware.microcontrollers.pic
Date: 2008-05-08 15:59:19 GMT
Are there other ways to implement a divide by a 14 constant other than
cycle-chewing subtraction loops?
I want to use the PIC16F flash consisting of 14-bit words to store 8-bit
data. I can implement the multiply-by-8 as a shift. The crux of the
problem is basically the divide by a constant of 14.
Pseudo Code ( actual code will likely be assembly )
wordOffset = 8*byteOffset / 14; // The integer result
wordBitOffset = 8*byteOffset % 14; // The remainder result
Patterns:
The 14-bit words and 8-bit data have a common multiple of 56.
The wordBitOffset pattern { 0,8,2,10,4,12,6 } repeats every 7-bytes.
I can't see a solution but it is an interesting puzzle.
Thanks in advance for any tips or suggestions,
-Ed
--
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
-- Mark
> -----Original Message-----
> From: piclist-bounces <at> mit.edu [mailto:piclist-bounces <at> mit.edu]On Behalf
> Of David VanHorn
> Sent: Thursday, May 08, 2008 12:06 PM
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] - Need fast divide by 14 constant routine? ( Random
> access8-bit data in PIC16F flash )
>
>
> Multiply by 9, then divide by 128? (close..)
>
> It's not really apparent what you're trying to optimize.
> I had a problem once where I was trying to do bearing calculations,
> and I did NOT want to do 16 bit math, and I was able to do it in 8
> bit, forsaking degrees for "dilberts" where there are 256 dilberts of
> angle in a circle
> --
>
It says:
; ALGORITHM:
; Clear accumulator
; Add input / 16 to accumulator
; Add input / 128 to accumulator
; Add input / 1024 to accumulator
; Add input / 8192 to accumulator
; Add input / 65536 to accumulator
The first error is at 14. (ALL the factors are obviously zero.)
Even if I do:
(i/2 + i/16 + i/128 + i/1024 + i/8192) / 8
The first error is still at 14.
Going at it backwards isn't going to work either:
x/14 = x/8 - x/32 - x/64 - x/256...
RSS Feed