Addicted,
Yeah, it amazes me that *I* understand it sometimes! Before MegaSquirt I had no electronics or code background at all (though I had plenty of automotive experience - mostly with formula cars).
Yes, the posted test code is safe to continue with. Except for a small change to the dbug variable (to assign it back to its original use) this will soon be released as 4.145 code. The dbug variable has been in the code right from the beginning. But it hasn't always been reported. Normally that channel is used for reporting the number of skipped VSS teeth. This is done in one line in the code like this:
Code: Select all
outpc.dbug = VSS_error; // set dbug to VSS error count unless used for
// logging elsewhere in code
But when I need a variable for debugging (often!), I comment out that line with // (which is the ONLY place outpc.dbug is used) and put an assignment somewhere else. For example, in the code you tested it was:
Code: Select all
// outpc.dbug = VSS_error; // set dbug to VSS error count unless used for
// logging elsewhere in code
if (FOUR_WD & FOUR_WDpin) outpc.dbug++; else outpc.dbug--; // DEBUG
where FOUR_WD and FOUR_WDpin are 'defined' as:
Code: Select all
// 4WD
#define FOUR_WD PORTE
#define FOUR_WDpin 0x02
This just tells the compiler that wherever it sees FOUR_WD substitute PORTE, and wherever it sees FOUR_WDpin substitue 0x02 (you can tell these are compiler directives and not C statements because they begin with # and don't end with a semicolon).
So:
if (FOUR_WD & FOUR_WDpin)
is the same as
if (PORTE & 0x02)
or equivalently
if (PE1 is high).
Using defines makes the code more readable and more portable between processors (for another processor I can just change the assignment in the file, and all the rest of the code can stay the same).
BTW, there also happens to be an input debug variable. This can be used to toggle or set values in the code from TS, and often comes in handy. You can see this variable under the 'Tools -> Debugging Input Variables' menu (this menu is sometimes commented out for release code), and the input value can be set to either a voltage (0-5V) or an ADC value (0 to 1023) and used in the code in any way one likes.
Having these permanently built into the code and INI makes debugging easier.
Lance.