MembersPage/NickLaTech/MarcellCode

Marcell's Solution with my Comments


Actual Code

http://cvs.sourceforge.net/viewcvs.py/megasquirtavr/firmware/boostcontrol.c?view=markup


There is the code sniplet:

[code]

// going to 12 bits:

boost += boost;

if( (boost >> 4) > (uint16_t)config.boost_minpressure ){

uint16_t pid_result;

// TODO: boostcut (above configurable boost) in fuelcalc.c

pid_set_target( &boostcontrol_pid, boost_target() );

// with pid15() high-boost will decrease command (more DLOW)

// which is consistent with DLOW above

pid_result = pid15( &boostcontrol_pid, boost );

// pid_result useful range is -2048 .. +2047 (consider this in PID config)

// offset going to 0..4095 ( 0.5 fixed offset should be OK )

pid_result += 2048;

// prevent underflow, overflow.

// 3 outputs possible: always low, always high

// and something between

if( pid_result >= 0x8000 || pid_result < BOOSTACT_MINTIME){

// always OFF

schedule_needed = 0;

output = DLOW;

} else if( pid_result >= 4096 ){ // compare against (4096 - BOOSTACT_MINTIME) ?

// fully ON! good luck Mr. Gorsky!

schedule_needed = 0;

output = DHIGH;

} else {

schedule_needed = 1; // true !!!

output = DHIGH;

// when pid_result is 4095, we want appr.

// (BOOSTCONTROL_PWM_PERIOD_8MS * 2048) * 4 usec ON-time

command16 = mult16_8( pid_result, BOOSTCONTROL_PWM_PERIOD_8MS);

command16 >>= 1;

}

} else {

/*

Don't activate boost valve below/equal a configurable boost:

there is no need to wear the valve at cruising

at low boost where the wastegate is known not to open anyway.

Without this, the pid15() would raise command, so DHIGH would be likely

*/

schedule_needed = 0;

output = DLOW;

}

[/code]