To start debugging the code we just added, we could take a number of approaches. The most certain way to be sure to see if we are getting what we want is with an oscilloscope, and we will do that eventually. Before that, however, we'll use the outpc.dbug variable to see if the code is performing as we expect (and this may be the only pre-vehicle testing we could do if we didn't have a oscilloscope).
If we wanted, we could have used an LED to indicate the dither status (turn it off for all normal functions, turn it on while the dither_pulse is active). However, this is more involved, and doesn't tell us the timing (we could use a stop watch, etc.). The biggest problem, though, is it wouldn't work very well for faster pulses of the sort we'll see in the refresh pulse for the other outputs. So we'll demonstrate the outpc.dbug method.
The first thing we do is change the conditions to those we can easily simulate on the bench. In this case, that means setting the LOAD_long threshold to 110 from 75. That way the dither pulse is active unless we blow into the MAP sensor hose. (Note that when you change something like this, a good idea is to comment out the original line of code with double forward slashes, then copy and paste the original line below to edit. This makes it easier to revert, and is a pretty good reminder that you have changed something you may want to change back!)
Code: Select all
// if (outpc.auto_mode && (outpc.current_gear == outpc.target_gear) && (outpc.LOAD_long < 75))
if (outpc.auto_mode && (outpc.current_gear == outpc.target_gear) && (outpc.LOAD_long < 110))
Next, we'll add the outpc.dbug variable. This first thing is to disable it's current use as the VSS error counter at line 2472:
Code: Select all
outpc.dbug = VSS_error; // set dbug to VSS error count unless used for debugging
becomes
Code: Select all
// outpc.dbug = VSS_error; // set dbug to VSS error count unless used for debugging
We need to distinguish between normal operation and the dither pulse. outpc.dbug is an unsigned int (i.e. it runs from 0 to 65535 or 0 to 65.535 seconds). Since our typical dither pulse interval runs around 10 seconds with a duration of one second, what we will do its let the counter stay static during the interval, then run from 0 to 1000 for the first dither pulse inteself. So what we expect to see is outpc.dbug sit at zero for about 10 seconds, then count up from 0 to 1000, then stay there for ten seconds, then from 1000 to 2000, etc. (because we have not reset the outpc.dbug value anywhere).
To do this, we insert a outpc.dbug assignment statement:
Code: Select all
// Pressure Control Output Dither Pulse
dither_counter++; // increment the counter
if (dither_counter > inpram.dither_intPC)
{
// if (outpc.auto_mode && (outpc.current_gear == outpc.target_gear) && (outpc.LOAD_long < 750))
if (outpc.auto_mode && (outpc.current_gear == outpc.target_gear) && (outpc.LOAD_long < 1100))
{
dither_flag |= 0x01; // set the dither_flag first bit to one
PWMDTY2 = PWMPER2; // set duty cycle to 100%
outpc.dbug++; // DEBUG
}
} // end if dither_counter ...
if (dither_counter > (inpram.dither_intPC + inpram.dither_durPC))
{
dither_counter = 0; // reset the dither counter to zero
dither_flag &= ~0x01; // reset the dither_flag first bit to zero
} // end if dither_counter ...
Note that we have added the comment // DEBUG after the addition to make it easier to find and remove all of these later (it's trivial in this case, but isn't always so easy!)
We compile (hopefully without warnings or errors, load the code, and open MegaTune). Open the x_debug gauge (by right clicking on any gauge, etc.). All of the debugging gauges are prefaced with 'x_' in the MShift code/INI gauge listing.
You'll see the gauge doesn't do much. This is because we have forgotten that the MAP units are x10, so if we want a limit of 75 kPa we need a value of 750 (and 1100 for 110 kPa, etc.). So we change that and re-compile. This works mostly as expected, but counts to 1001, 2002, 3003, etc. instead of multiple of 1000. To fix that, we change:
Code: Select all
if (dither_counter > (inpram.dither_intPC + inpram.dither_durPC))
to
Code: Select all
if (dither_counter > (inpram.dither_intPC + inpram.dither_durPC - 1))
Recompile and check and all is well. The next step would be to move the outpc.dbug statement above into the interval condition to verify that it is working exactly as predicted with the default values (or alternately - look at the datalog values and compare the dither timing to the clock). Then we can go on to check different settings for the interval and duration (including zeros!), verify that it doesn't dither during manual mode or at higher loads, check the main loop frequency (using the gauge x_loop_Hz), etc. Finally we look at the output on the oscilloscope (with the output pulling a load so the oscilloscope has a changing voltage to work with).
When making mods like this, it's always a good idea to keep an eye out for things that may not be quite right from earlier mods. In this case, the CLK_DONE: statement (for the GOTO) was in the wrong place, and slowing the code down a bit more than it needed too - so it was fixed.
Once we are satisfied the code works properly under all conditions, we remove the 'outpc.dbug++; // DEBUG' statement, change the condition back to 750 (== 75 kPa) and remove the forward slashes we added earlier to the 'outpc.dbug = VSS_error;' statement. Compile, load and run the code once more to make sure we haven't messed anything up. If that's good, it's over to the oscilloscope (or out to the vehicle) to check some more!
Three things help make developing code easier:
- a bench set-up with full hardware. In my case, this is a MS-II/V3/V2.1 stim plus a GPIO and its own stim.
- a push-button switch on the bootloader of the bench GPIO, so serial monitor ("bootloader") mode can be entered just by pushing the button while powering up,
- Codewarrior configured to open the downloader and MegaTune. I have these on F11 and F12. So I can compile, load and test code with just F7/F11/F12. You define the programs you want to open with what F
x keys under 'Edit/Commands and Key Bindings' in CW.
Lance.
"Never wrestle with pigs. You both get dirty and the pig likes it." - George Bernard Shaw