Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

89c51 32-bit Math calculation

Status
Not open for further replies.

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
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.
 

conkhicon

Advanced Member level 4
Joined
Aug 31, 2004
Messages
107
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Activity points
1,015
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.
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
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..
 

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
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.
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
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.
 

nicleo

Advanced Member level 2
Joined
Sep 6, 2004
Messages
661
Helped
66
Reputation
132
Reaction score
12
Trophy points
1,298
Activity points
7,161
calculation of timer for 89c51

An option (more expensive):

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

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
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 !!!
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
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..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top