- 31st January 2005, 16:42 #1

- Join Date
- Nov 2004
- Posts
- 444
- Helped
- 24 / 24
- Points
- 6,628
- Level
- 19

## 32bit div 32bit for 8051

Hi friends,

please, help me for a math problem, i need to calculate:-

(55299539) / ((a*100 + b)*61375 +c)

where a = 0 to 8

b= 0 to 100

c = 0 to 61375

using 89c51 assembly progrmming. what algorithm should i use?

can anyone please provide me a code?

thank you.

- 31st January 2005, 21:00 #2
## bit math

http://www.8052.com/codelib.phtml

Has some very nice code snippits. In your case I'd examine this library a bit closer:

http://www.8052.com/codelib/math8051.asm

It has 8, 16 and 32 bit subtraction, multiplication, and division (signed and unsigned). Has good comments, should be worthwile...

Happy coding!

- 31st January 2005, 21:00

- 1st February 2005, 06:23 #3

- Join Date
- Aug 2004
- Posts
- 107
- Helped
- 3 / 3
- Points
- 2,151
- Level
- 10

## rpm 60 pulses per revolution 8052

Hi

It's very simple.

Copy your function into new project in C compiler as Keil, IAR...

Unassembly for code.

- 1st February 2005, 09:54 #4

- Join Date
- Oct 2004
- Location
- West Coast
- Posts
- 7,943
- Helped
- 2302 / 2302
- Points
- 160,151
- Level
- 95

## 89c51 basic registers

As all numbers in your eqasion are decimal and the microcontroller will perform calculations on HEX numbers you will have to convert these numbers from decimal to HEX.

With numbers up to 255d there is no problem ( a and b).

With big costance such as 55299539 you can use windows calculator and convert them to HEX:

55299539 d = 03h 4Bh 0CDh 0D3h

61375 d = 0EFh 0BFh

But for c you will need DEC to HEX converter subroutine. Try to find it somewhere, if not I did it some time before and you can have it..

Having these numbers converted try to find 40-bit/24bit division, but first you will have to calculate the value in brackets using 32-bit MUL and SUM subroutines..

Little bit long but not impossible..

- 1st February 2005, 09:54

- 1st February 2005, 14:44 #5

- Join Date
- Nov 2004
- Posts
- 444
- Helped
- 24 / 24
- Points
- 6,628
- Level
- 19

## 32 bit math routine for 8051

Thanks a lot for replying.

"Ianp" i think i need routines for 32-bit division also. actually i want to design a rpm meter (tachometer) ranging from 1 rpm to 10000 rpm. i'm planning to use 11.0592mhz xtal, and a disc mounted on motor shaft having one hole with IR encoder-decoder . for this if i run counter between two succesive pulses i obtain maximum readibilty of 843.4 rpm, any speed slower than this will make the counter overflow. so for 1 rpm i plan to make cascading with two more registers (R1, R0 one upto 100 and other upto 8 ) , which increments after each overflow then second register increments. so,

60 * 1000000 * 1000

------------------------------------------------------------- = rpm

[(R0*100 + R1) * 61444 + Counter0] * 1085

AM I GOING THE RIGHT WAY, Please Help ME.

Thanking You in Anticipation.

- 2nd February 2005, 02:01 #6

- Join Date
- Oct 2004
- Location
- West Coast
- Posts
- 7,943
- Helped
- 2302 / 2302
- Points
- 160,151
- Level
- 95

## math functions for 89c51

For motor RPM you don't need very complicated calculatons..

First you need 60sec time base and I don't want to repeat this issue once more; you will find it in this forum under "1 second Interrupt from 8051?" (search "1s AND 8051")

Once you have the 1s time base multiply it by 60 for 1min. For 1rpm you will need at least 1m time base..

And now just count pulses from the motor shaft..

The count of pulses over 1m is the RPM.

You will need 2 registers to obtain the 10000 mark..

So the mathematical operations involved are:

SUM to calculate Time Base

SUM to count pulses.

- 2nd February 2005, 03:01 #7

- Join Date
- Sep 2004
- Posts
- 662
- Helped
- 72 / 72
- Points
- 21,612
- Level
- 35

## calculation of timer for 89c51

An option (more expensive):

Pulse from encoder -> frequency to voltage (IC, e.g.VFC320 from TI/BurrBrown) -> ADC -> 8051

- 2nd February 2005, 17:18 #8

- Join Date
- Nov 2004
- Posts
- 444
- Helped
- 24 / 24
- Points
- 6,628
- Level
- 19

## bit revolution calculation

Thanks a lot for replying. "Ianp" i think the method you told is no doubt very correct, but i think the refreshing rate would be 1 minute which would be to slow. right? and the error could increase upto 1 rpm !!!

- 3rd February 2005, 00:48 #9

- Join Date
- Oct 2004
- Location
- West Coast
- Posts
- 7,943
- Helped
- 2302 / 2302
- Points
- 160,151
- Level
- 95

## code 89c51 calculator

You can do it every 0.1s, 1s etc. and mulitply result by 600, 60 ....

Insread o having only 1 hole in your encoder you can have 2,3,4,.. holes and this will give you several pulses per revolution.

Of-the-shelf rotary encoders have 100, 200, .. , 1000+ ppr so the error is reduced to acceptable minimum..