DIY PROM Do It Yourself PROM chip burning help. No PROM begging. No PROMs for sale. No commercial exchange. Not a referral service.

$8D/$58/$42 RPM calculation

Thread Tools
 
Search this Thread
 
Old 04-06-2007, 10:27 AM
  #1  
Junior Member
Thread Starter
 
turbodig's Avatar
 
Join Date: May 2006
Posts: 30
Likes: 0
Received 0 Likes on 0 Posts
$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)

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
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
Old 04-06-2007, 11:12 AM
  #2  
Supreme Member

iTrader: (1)
 
JP86SS's Avatar
 
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
Old 04-06-2007, 11:14 AM
  #3  
Moderator

iTrader: (1)
 
RBob's Avatar
 
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.
Old 04-06-2007, 01:30 PM
  #4  
Junior Member
Thread Starter
 
turbodig's Avatar
 
Join Date: May 2006
Posts: 30
Likes: 0
Received 0 Likes on 0 Posts
Re: $8D/$58/$42 RPM calculation

Originally Posted by RBob
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.

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
This should add the /32 variable and retain the /25, so we don't have to go through and change all the CMP statements for RPM ranges and all the table indexes in the tunerpro defs. Or am I still out of whack?

Later,

Dig

Last edited by turbodig; 04-06-2007 at 02:22 PM. Reason: whoops. Had my last pula and pulb swapped.
Old 04-06-2007, 04:51 PM
  #5  
Moderator

iTrader: (1)
 
RBob's Avatar
 
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.
Old 04-06-2007, 08:35 PM
  #6  
Junior Member
Thread Starter
 
turbodig's Avatar
 
Join Date: May 2006
Posts: 30
Likes: 0
Received 0 Likes on 0 Posts
Re: $8D/$58/$42 RPM calculation

Originally Posted by RBob
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.
Thanks. I'll give that a try too.
I was kinda concerned about adding too much code to this... didn't wanna run out of time between loops.


Dig
Old 04-07-2007, 07:46 AM
  #7  
Z69
Supreme Member

 
Z69's Avatar
 
Join Date: Sep 2003
Location: Texas
Posts: 1,409
Likes: 0
Received 1 Like on 1 Post
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.
Old 04-10-2007, 03:01 PM
  #8  
Junior Member
Thread Starter
 
turbodig's Avatar
 
Join Date: May 2006
Posts: 30
Likes: 0
Received 0 Likes on 0 Posts
Re: $8D/$58/$42 RPM calculation

Originally Posted by Z69
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.
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
Old 04-10-2007, 03:44 PM
  #9  
Member

 
skwayb's Avatar
 
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.
Old 04-12-2007, 10:30 AM
  #10  
Z69
Supreme Member

 
Z69's Avatar
 
Join Date: Sep 2003
Location: Texas
Posts: 1,409
Likes: 0
Received 1 Like on 1 Post
Re: $8D/$58/$42 RPM calculation

Originally Posted by turbodig
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
I just added another calc a strategically placed pshx.-See the lotus code.

$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.
Old 07-27-2011, 03:23 AM
  #11  
Junior Member
 
cliffharris's Avatar
 
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:

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
      ;----------------------------------------------------------------------------
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.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Elephantismo
Electronics
14
02-13-2019 12:51 AM
Rousseau92maro
Exhaust
9
02-01-2016 05:12 PM
Giocio
TBI
7
10-01-2015 12:20 PM
Damon
Tech / General Engine
8
09-26-2015 04:29 PM
wisemanz28
Tech / General Engine
3
09-20-2015 01:26 PM



Quick Reply: $8D/$58/$42 RPM calculation



All times are GMT -5. The time now is 12:40 PM.