Page 1 of 1

Duty Cycle

Posted: Mon Aug 09, 2010 11:12 am
by dbh86
This is a question about the duty cycle calculations that MS makes for the % gauge in MT/TS. I haven't found a firm statement that this is how it is calculated, but I will try my best to explain how I believe it works. Please correct me if I'm wrong. The entire reason for this is that there appears to be more fuel available even after you go over 100% on the gauge.

So here is my hypothesis:

Duty cycle is time active/ time available for the cycle: 50% DC = 5 ms injection / 10 ms cycle time
The cycle time is dependent on rpm. 6000 rpm = 10 ms, 3000 rpm = 20 ms.
The injection time is a combination of the opening, full open injection, and closing. So the 5ms would actually consist of ~1ms opening time, ~3.9ms full open, 0.1ms closing time.

So, at 100% DC for a 10ms cycle time: 0-1ms is opening, 1-9.9ms is full open, and 9.9-10ms is closing.

^^^ Is this correct?

If so, then you could actually go above 100% DC and still find more fuel.
So, at ~112% DC for a 10ms cycle: -1 to 0ms is opening, 0-10ms is full open, 10-10.1ms is closing ... Because these will overlap with the cycles before and after the current cycle, the injector will never actually see anything more than being full open... i.e. 0-10ms is full open for each cycle

Can anyone else offer some insight into this?

Re: Duty Cycle

Posted: Mon Aug 09, 2010 11:56 am
by DonTZ125
Duty cycle is based the OPEN time, and does not include the opening / 'dead' time. Also, when you exceed ~ 80-85% duty cycle, you enter a non-linear region. The flow difference between 80% and 88% duty is not necessarily 10%; it could be 5%, it could be 15%. It's very difficult to tune in this region, so most recommend avoiding it.

100% duty cycle = fully open all the time. Can't open more than 100%...

Re: Duty Cycle

Posted: Mon Aug 09, 2010 6:35 pm
by Bernard Fife
Guys,

The duty cycle includes the opening time.

Lance.

Re: Duty Cycle

Posted: Mon Aug 09, 2010 7:49 pm
by dbh86
LOL...
Is the code viewable for it somewhere?

Re: Duty Cycle

Posted: Tue Aug 10, 2010 5:34 am
by Bernard Fife
dbh86,

Yes, you can find links to the embedded code in the manual table of contents: http://www.megamanual.com/mtabcon.htm

The duty cycle isn't computed directly by MegaSquirt though, it is done by the tuning software. In MegaTune it is in the INI is the [OutputChannels] section:

Code: Select all

dutyCycle1       = { 100.0*nSquirts1/altDiv1*pulseWidth1/cycleTime1 }, "%"

cycleTime1       = { 60000.0 / rpm * (2.0-twoStroke)                }, "ms"

altDiv1          = { alternate ? 2 : 1                              }
Lance.

Re: Duty Cycle

Posted: Tue Aug 10, 2010 6:48 pm
by dbh86
Awesome, but alas I can't really figure out the assembly code part of it.

Code: Select all

PWCALC = TMP6 + TMP11 + TPSACCEL - INJOCFUEL
The best guess I can make is that this is the variable that gets passed to MT for the "pulsewidth1" variable. Or is there a different variable that is passed to MT?

Re: Duty Cycle

Posted: Wed Aug 11, 2010 5:25 am
by Bernard Fife
dbh86,

In the INI [OutputChannels] section there is a line like this:

Code: Select all

pulseWidth1      = scalar, U16,    2, "s",     0.001, 0.0
The 2 in this is telling use that pulse width 1 is located at an offset 2 of two words (16 bits) in the OUTPC structure in the code (all of the variable going from MegaSquirt to the tuning software are in outpc, the variables going from the tuning software to MegaSquirt are described in the
[Constants] section of the INI and are found in INPRAM or INPRAM2).

Looking at the code itself (2.89), around line 1360 you will find:

Code: Select all

// rs232 Outputs to pc
typedef struct {
unsigned int seconds,pw1,pw2,rpm;           // pw in usec
int adv_deg;                                // adv in deg x 10
unsigned char squirt,engine,afrtgt1,afrtgt2;    // afrtgt in afr x 10 (or Vx100)
...
The first variable (seconds) takes up two words because it is an int, so the offset of two gives us pw1 for the variable that corresponds to pulseWidth1 in the INI. So if you want to see how pw1 (aka outpc.pw1 in the code, pulseWidth1 in the INI) is calculated by the code, you need to look up pw1 and see where it is used in the code (which will lead to a number of other variables).

Lance.

Re: Duty Cycle

Posted: Wed Aug 11, 2010 6:27 am
by dbh86
Thanks Lance,
I see the code you quoted is MS2 and in C... much easier to understand. I should be able to figure it out from here. :D