$8D/$58/$42 RPM calculation
#1
$8D/$58/$42 RPM calculation
I've been trying to understand the numerical magic behind the
fdiv by 307 in the RPM calculation. I'm looking at $58, but the
same code appears to be used in $8d, $42, others.
Thinking out loud
Assuming a V8 engine...
Start with 1000 RPM. (Picking a Number out of a hat)
Dissy turns once for every 2 crank rotations, so we / 2.
1000/2 = 500 RPM
* 8 pulses on the reluctor
500 * 8 = 4000 Reluctor (Reference pulses/DiRPs)/Min.
/60 to convert minutes to seconds.
4000/60 = 66.667 DiRPs/second.
1/66.667 = .015 second period for each DiRP.
To the best of my understanding (and maybe this is my
problem), the DiRP timer runs at 65,535 Hz.
Period of a 65,535 hz count is 1.5259e-5
Divide the two to get # of counts per DiRP.
.015/1.5259e-5 = 983 =$3D7
3D7 = number of DiRP counts at 1000 RPM
The code itself likes the math above just fine, I've stepped through the code below in Wookie
with several different counter values and it always comes out right.
(it's actually 25 RPM lower, but that amounts to a zero-base/rounding issue)
What I can't seem to get to make sense in my head, is why the divide by
307 works. I can't work out any set of numbers to come up with the 153.6.
Can someone point me in the right direction? I'm thinking about creating an RPM /32
variable such that the ALDL stream could report up to 8160 RPM.
(and, eventually, integrate this variable into the VE and timing table lookups)
Thanks,
Dig
fdiv by 307 in the RPM calculation. I'm looking at $58, but the
same code appears to be used in $8d, $42, others.
Thinking out loud
Assuming a V8 engine...
Start with 1000 RPM. (Picking a Number out of a hat)
Dissy turns once for every 2 crank rotations, so we / 2.
1000/2 = 500 RPM
* 8 pulses on the reluctor
500 * 8 = 4000 Reluctor (Reference pulses/DiRPs)/Min.
/60 to convert minutes to seconds.
4000/60 = 66.667 DiRPs/second.
1/66.667 = .015 second period for each DiRP.
To the best of my understanding (and maybe this is my
problem), the DiRP timer runs at 65,535 Hz.
Period of a 65,535 hz count is 1.5259e-5
Divide the two to get # of counts per DiRP.
.015/1.5259e-5 = 983 =$3D7
3D7 = number of DiRP counts at 1000 RPM
The code itself likes the math above just fine, I've stepped through the code below in Wookie
with several different counter values and it always comes out right.
(it's actually 25 RPM lower, but that amounts to a zero-base/rounding issue)
Code:
start ldS #$01FF jmp LCFAC LCFAC: ldD L3FC0 ; Timer chip register (DRP) stD L0037 ; Store this in location 0037 (Ref Period) ldX #$0037 ; ldaA KNUMCYL ; Cylinder Select Address beq LCFBF ; If it's zero, it's an 8 cylinder jsr LF650 ; Multiply X by A (i.e. timer * cylinder select) stD L0037 ; Store result in 0037 LCFBF ldD L0037 ; Load the timer (i.e. DRP time) lslD ; timer = timer * 2 pshB ; Put A and B in X pshA ; Basically equivalent to X=D pulx ldD #$0133 ; 15 * (512/25) or 153.6 * 2 fdiv ; D/X where X = quotient, D=Rem pshX ; Move X into A and B pula ; Basically, D = X pulb
307 works. I can't work out any set of numbers to come up with the 153.6.
Can someone point me in the right direction? I'm thinking about creating an RPM /32
variable such that the ALDL stream could report up to 8160 RPM.
(and, eventually, integrate this variable into the VE and timing table lookups)
Thanks,
Dig
#2
Supreme Member
iTrader: (1)
Join Date: Apr 2004
Location: Browns Town
Posts: 3,178
Likes: 0
Received 3 Likes
on
3 Posts
Car: 86 Monte SS (730,$8D,G3,AP,4K,S_V4)
Engine: 406 Hyd Roller 236/242
Transmission: 700R4 HomeBrew, 2.4K stall
Axle/Gears: 3:73 Posi, 7.5 Soon to break
Re: $8D/$58/$42 RPM calculation
This is the thread describing the operation in $8D.
Z69' has done exactly what you are describing for the S_AUJP V4 (in testing now)
https://www.thirdgen.org/forums/diy-...?highlight=rpm
Z69' has done exactly what you are describing for the S_AUJP V4 (in testing now)
https://www.thirdgen.org/forums/diy-...?highlight=rpm
#3
Moderator
iTrader: (1)
Join Date: Mar 2002
Location: Chasing Electrons
Posts: 18,432
Likes: 0
Received 225 Likes
on
211 Posts
Car: check
Engine: check
Transmission: check
Re: $8D/$58/$42 RPM calculation
It sets the maximum RPM value for a V8. Previous to the RPM calc the DRP counts are normalized to 90 deg of crank rotation. Then multiplied by 2 (which halves the RPM).
Hard to explain, another way to look at the value of 307 is this:
RPM = ( 65536 * (120 / NCyl) ) / DRP
For an 8 cylinder, or 90deg of crank rotation for each DRP:
RPM = 983040 / DRP
-or-
3202 = 983040 / 307
Which is 6400 RPM (double the 3202 value from above).
RBob.
Hard to explain, another way to look at the value of 307 is this:
RPM = ( 65536 * (120 / NCyl) ) / DRP
For an 8 cylinder, or 90deg of crank rotation for each DRP:
RPM = 983040 / DRP
-or-
3202 = 983040 / 307
Which is 6400 RPM (double the 3202 value from above).
RBob.
#4
Re: $8D/$58/$42 RPM calculation
It sets the maximum RPM value for a V8. Previous to the RPM calc the DRP counts are normalized to 90 deg of crank rotation. Then multiplied by 2 (which halves the RPM).
Hard to explain, another way to look at the value of 307 is this:
RPM = ( 65536 * (120 / NCyl) ) / DRP
For an 8 cylinder, or 90deg of crank rotation for each DRP:
RPM = 983040 / DRP
-or-
3202 = 983040 / 307
Which is 6400 RPM (double the 3202 value from above).
RBob.
Hard to explain, another way to look at the value of 307 is this:
RPM = ( 65536 * (120 / NCyl) ) / DRP
For an 8 cylinder, or 90deg of crank rotation for each DRP:
RPM = 983040 / DRP
-or-
3202 = 983040 / 307
Which is 6400 RPM (double the 3202 value from above).
RBob.
That helped... makes better sense now. Not sure what the existing comments were getting at. Thanks RBob.
Anyway, if I do this....
Code:
ldD #$00F0 ; /240 fdiv ; D/X where X = quotient, D=Rem pshX ; Move X into A and B pula ; Basically, D = X pulb staa RPM_32 ; new ram variable for RPM LSRD ;multiply a by 128, now in D pshx ;save what was in x, in case something else wants LDX #$64 ;gonna divide by 100 IDIV ; divide by 100... this multiplies the /32 var ; by 1.28, overall. Rescales to /25. pshx ; x is the quotient of our result pulb ; get the RPM/25 back... just like the /32 never happened pula pulx ;x is back to what it started to be. cmpA #$40 ; 1600 RPM
Later,
Dig
Last edited by turbodig; 04-06-2007 at 02:22 PM. Reason: whoops. Had my last pula and pulb swapped.
#5
Moderator
iTrader: (1)
Join Date: Mar 2002
Location: Chasing Electrons
Posts: 18,432
Likes: 0
Received 225 Likes
on
211 Posts
Car: check
Engine: check
Transmission: check
Re: $8D/$58/$42 RPM calculation
By the comments in the code it works out. The only issue I can see would be the loss of precision when converting from the RPM/32 to RPM/25 value. I would be tempted to just do both conversions the same way. With 307 and 240, using the same basic routine twice. After so many years of writing and testing code, I've found the more straight forward the less chance of an error or strange condition causing a problem.
RBob.
RBob.
#6
Re: $8D/$58/$42 RPM calculation
By the comments in the code it works out. The only issue I can see would be the loss of precision when converting from the RPM/32 to RPM/25 value. I would be tempted to just do both conversions the same way. With 307 and 240, using the same basic routine twice. After so many years of writing and testing code, I've found the more straight forward the less chance of an error or strange condition causing a problem.
RBob.
RBob.
I was kinda concerned about adding too much code to this... didn't wanna run out of time between loops.
Dig
#7
Re: $8D/$58/$42 RPM calculation
GM added a high rpm calc to the lotus code in the same loop.
Works just fine.
8D has a table lookup for # of DRP's for start to run.
I just made it into a constant to save time.
Works just fine.
8D has a table lookup for # of DRP's for start to run.
I just made it into a constant to save time.
Trending Topics
#8
Re: $8D/$58/$42 RPM calculation
My code above doesn't seem to operate too well, gonna give Rbob's recommendation a shot. I might be getting to the point where I don't have
any RAM to rob, been stealing bytes off the deep end of the stack. Risky, I know, but so far it's worked ok. Got one of MonteCarslow's modules, but I'd like to have the code run on the stock hardware as much as possible.
Speaking of table lookups, did you guys have the same issue with table lookups being limited to 16x16? I did get it fixed, just curious to see if the same limitation existed in $8D
Later,
Dig
#9
Member
Join Date: Jun 2004
Posts: 157
Likes: 0
Received 0 Likes
on
0 Posts
Car: 93 GMC Typhoon
Engine: 4.3L V6 Turbo Charged
Transmission: 4L80e
Re: $8D/$58/$42 RPM calculation
Dig I have the lotus code some where on the 59 site. So if you want to look at that it is there.
#10
Re: $8D/$58/$42 RPM calculation
ok. Thanks.
My code above doesn't seem to operate too well, gonna give Rbob's recommendation a shot. I might be getting to the point where I don't have
any RAM to rob, been stealing bytes off the deep end of the stack. Risky, I know, but so far it's worked ok. Got one of MonteCarslow's modules, but I'd like to have the code run on the stock hardware as much as possible.
Speaking of table lookups, did you guys have the same issue with table lookups being limited to 16x16? I did get it fixed, just curious to see if the same limitation existed in $8D
Later,
Dig
My code above doesn't seem to operate too well, gonna give Rbob's recommendation a shot. I might be getting to the point where I don't have
any RAM to rob, been stealing bytes off the deep end of the stack. Risky, I know, but so far it's worked ok. Got one of MonteCarslow's modules, but I'd like to have the code run on the stock hardware as much as possible.
Speaking of table lookups, did you guys have the same issue with table lookups being limited to 16x16? I did get it fixed, just curious to see if the same limitation existed in $8D
Later,
Dig
$8D has the table limit also since they both use the same 3d l/u routine.
Unless you need a high rpm solution, you may be working on a very narrow use feature. I just added a 3rd table rather than make everyone suffer with tuning a huge table. Then I decided that was still too much hassle for most and went with a bit selectable high rpm capable PE table instead.
With some research, you can also combine different scales on the same table. GM did it in the "scaled" rpm calc instead so that several tables could have different scales w/o having to do redundant code for each table.
I understand that you are dealing with boost. So you have dbl or trpl the map scale to cover. Which would make for 3-4 tables using the stock l/u routine and good resolution in the table.
The smog code eats up a lot of ram space. Careful study may reveal a few stock locations that almost no one running 3 bar code has the stock smog equipment that would need that code anymore. There are also a few startup timers that may not be used once the engine is running. So a branch cmd based on run status would allow dual useage of the ram location.
#11
Junior Member
Join Date: Aug 2010
Location: Anaheim, CA
Posts: 22
Likes: 0
Received 0 Likes
on
0 Posts
Car: 1986 Corvette
Engine: 5.7 liter
Transmission: Auto
Axle/Gears: 3.07
Re: $8D/$58/$42 RPM calculation
The 307 number baffled me for quite a while. While trying to figure it out I really looked at the code and came up with several conclusions.
What is commonly called DRP is actually not Distributor Reference Pulses, but should be called the "DRP period count". It's the number of 65.536 KHz counts between DRPs. The period is the time between the rising edge of one DRP and the rising edge of the next DRP, measured in counts.
Here are the comments in my code so I can remember all this:
In the bottom two equations the reason the "256" is in there is because the code only uses the MSB of the count, so the count is divided by 256 to eliminate the LSB. The "x2" factor doubles the 153.6 to make it 307.
What is commonly called DRP is actually not Distributor Reference Pulses, but should be called the "DRP period count". It's the number of 65.536 KHz counts between DRPs. The period is the time between the rising edge of one DRP and the rising edge of the next DRP, measured in counts.
Here are the comments in my code so I can remember all this:
Code:
;---------------------------------------------------------------------------- ; RPM/25 (scaled), RPM/25 & RPM/12.5 ; ; Count period = 1/65.536 KHz per bit = 15.258789 us per count ; ; 1 count 60 sec 1 rev 983040 ; ------------ x ------ x ----- = (983040 RPM)(counts) ===> ------ = RPM ; 15.258789 us min 4 DRP counts ; ; 983040 307 ; -------- = 153.6 ===> ------------------ = RPM/25 ; 256 * 25 (counts * 2) / 256 ;----------------------------------------------------------------------------
Thread
Thread Starter
Forum
Replies
Last Post
Damon
Tech / General Engine
8
09-26-2015 04:29 PM