Minor cleanup of pulsewidth calc.
This commit is contained in:
parent
e62231fb06
commit
ca67510e70
17
math.h
17
math.h
|
@ -11,8 +11,8 @@ Ref: http://www.hackersdelight.org/divcMore.pdf
|
|||
*/
|
||||
|
||||
//Unsigned divide by 10
|
||||
unsigned divu10(unsigned n) {
|
||||
unsigned q, r;
|
||||
unsigned int divu10(unsigned int n) {
|
||||
unsigned int q, r;
|
||||
q = (n >> 1) + (n >> 2);
|
||||
q = q + (q >> 4);
|
||||
q = q + (q >> 8);
|
||||
|
@ -36,3 +36,16 @@ int divs10(int n) {
|
|||
return q + ((r + 6) >> 4);
|
||||
// return q + (r > 9);
|
||||
}
|
||||
|
||||
//Signed divide by 100
|
||||
int divs100(int n) {
|
||||
int q, r;
|
||||
n = n + (n>>31 & 99);
|
||||
q = (n >> 1) + (n >> 3) + (n >> 6) - (n >> 10) +
|
||||
(n >> 12) + (n >> 13) - (n >> 16);
|
||||
q = q + (q >> 20);
|
||||
q = q >> 6;
|
||||
r = n - q*100;
|
||||
return q + ((r + 28) >> 7);
|
||||
// return q + (r > 99);
|
||||
}
|
||||
|
|
|
@ -359,7 +359,7 @@ void loop()
|
|||
//BEGIN INJECTION TIMING
|
||||
//Determine next firing angles
|
||||
//1
|
||||
int PWdivTimerPerDegree = div(currentStatus.PW, timePerDegree).quot; //This variable is used multiple times, so only do the division once.
|
||||
int PWdivTimerPerDegree = div(currentStatus.PW, timePerDegree).quot; //How many crank degrees the calculated PW will take at the current speed
|
||||
injector1StartAngle = 355 - ( PWdivTimerPerDegree ); //This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. I am using 355 as the point at which the injector MUST be closed by. See http://www.extraefi.co.uk/sequential_fuel.html for more detail
|
||||
//Repeat the above for each cylinder
|
||||
//2
|
||||
|
|
7
utils.h
7
utils.h
|
@ -50,9 +50,10 @@ unsigned int PW(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen, b
|
|||
intermediate = (intermediate * iMAP) >> 7;
|
||||
intermediate = (intermediate * iCorrections) >> 7;
|
||||
intermediate = (intermediate * iTPS) >> 7;
|
||||
unsigned int final = (unsigned int)(intermediate + injOpen);
|
||||
//if (final > 65535) { final = 65535; } //Make sure this won't overflow. This means the maximum pulsewidth possible is 65.535mS
|
||||
return final;
|
||||
intermediate += injOpen; //Add the injector opening time
|
||||
if ( intermediate > 65535) { intermediate = 65535; } //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
|
||||
//unsigned int final = (unsigned int)(intermediate);
|
||||
return (unsigned int)(intermediate);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue