# Pic Binary Division Problem

Discussion in 'Embedded Systems and Microcontrollers' started by toritorin, Jul 26, 2011.

1. ### toritorin Thread Starter New Member

Dec 30, 2009
2
0
Dear People:

Thanks to all for sharing your knowledge. I was wondering if some of you have had a problem like the one I describe below. Any help will be welcomed!
Im dealing with integer unsigned binary division using a PIC. I implemented 24/24 bit division and everything went ok. But when performing 24/16 bit division, something goes wrong.
The dividend (numerator) is a 24 bit constant, but the divisor (denominator) is a variable number. When this denominator takes a low value (but still 16 bit value), say 10700 i.e., the error in the result is quite a lot, and it becomes bigger as the difference between both operands does too. Is there a solution to this?
Thanks again for your help. Greetings!

Sep 7, 2009
2,803
594
3. ### toritorin Thread Starter New Member

Dec 30, 2009
2
0

ErnieM: No, it is not a negative number. I’m working with unsigned integer numbers. The error is the same even working with other routines (32/24, 16/8).

Markd77: I have tried all of those routines. I did some of my own too, but the problem persists.

To add some information, once I do the division, I convert both High and Low bytes of the result into BCD, and show them in 4 seven segment displays.

When the result is exact or very near to the exact result, the digits show “stable”. But when the problem appears, it also causes the numbers to change a lot. For example, when the result should be 3000, I got 3400, where the last two digits values change many times in a second (3420/3415/3440 an so on).

This example I mentioned is the worst case, being the result of:

d’15000000’/d’5000’=d’3000’

When the divisor is near the “high end” of the 16 byte (65536), the error is acceptable.

Is it possible to do something about it using the remainder? What am I doing wrong?

Last edited: Jul 27, 2011

Sep 7, 2009
2,803
594