/*********************************************************\
*  VEMS - 2005                                            *
*  (C) 2005 VEMS-GROUP.ORG				                  *
\*********************************************************/


Changelog:

since 1.0.23: airdenfactor,matfactor and thermfactor on fix locations.

since 1.0.19:

	* added full power shift cut, with configurable spark and/or fuel cut
	* baro correction updated to work in the new non-lookup scheme; baro value to megatune is in real kpa now
	* baro/kpafactor table lookup is no longer supported 
	* if MAP multiplying is configured, only used for RPM >= config.hybrid_rpm_m
	* added tach output supporting funcionality
	* new per page read and write serial commands were added to fix the megatune trashing config bug
	* old non-compat megatune commands were removed

since 1.0.18

    * fixed tps acceleration enrichment. It left infinitely small time for user to press TPS in the last couple releases: 
	  effectively disabled tps accel enrichment. The sampling is now synchronized to the tps acceleration enrichment calculation,
      so result should be more deterministic than earlier.
    * note that interpolation of the n[] table (ignition advance) was not fixed because no problem was found: it tested perfect!

since 1.0.17

    * boostcontrol configured with MAP-target considers the scaled MAP (not the MAP sensor input voltage)
    * boost_conf bit3:2 00,01,10,11 means 20,40,60,80% reference position for the solenoid. 40% or 60% recommended 
	  if otherwise no idea. (TODO: someone check the generated assembly code for overflow at the 8*8 bit multiplication - result should be 16bit).

since 1.0.16

    * small firmware bugfix: from megatune config.primep was altered instead of element 0 of the b[] table (boostcontrol-target)

since 1.0.15:

    * the new (1.0.14) fuelcut_kpa is renamed to fuelcut_min_kpa. Meaning is unchanged, read below
    * new variable to prevent overboost (useful until the boostcontrol PID is tuned) fuelcut_max_kpa=FF to disable; 
	  fuelcut_max_kpa=F0 to cut fuel above MAP > 240 kPa (assuming the default MY_CONF += -D KPA_CONFIG_RESOLUTION=1; 
	  naturally same meanse 480 kPa for MY_CONF += -D KPA_CONFIG_RESOLUTION=2)
    * tach_channel=FF to disable
    * tach_divider=.. is not used. Use FF for now, I think 00 will be used finally to disable completely

since 1.0.14:

    * 8,10,12 or 16 cyl support with multitooth wheel
    * Compiled with 12x12 maps. Known (optical) bug: h-table is apparently 12 element wide on LCD
    * fixed the boostcontroller bug, that effected boost-target (calculated from the TPS and t[] and b[] table). If you 
	  are planning to use boost control, get this bugfix.
    * the firmware intro has been re-introduced to the LCD code and tested. This is an optical feature but tells the user what firmware revision 
	  they are running.
    * some boostcontroller items have been added to the display
    * changed airdenfactor to not lean any more above MAT > 60C (actually, it enriches above MAT > 60C with appr. +0.1%/C ). Below MAT < 50C 
	  the universal gas-law is followed (which is appr -0.33%/C). A small plateu is applied from appr. MAT=50..60C
    * added lowmap_fuelcut function: config.fuelcut_kpa=0E recommended (fuelcut under 14 kPa) or up to 12 (fuelcut under 18kPa). The hysteresis
      is compile-time (3kPa, and applied as config.fuelcut_kpa + LOWMAP_FUELCUT_HYSTERESIS). Those who use KPA_CONFIG_RESOLUTION=2 (for extreme 
	  boost; rare) know that every MAP-kpa related config values must be multiplied by 2 (so max range is 510kPa and 09 means 18 kPa): fuelcut_kpa 
	  is no exception. fuelcut_kpa=00 gives old behavior (disables lowmap_fuelcut), but why would anyone do that ? It is extremely difficult to tune
      injopen, injocfuel, kpaoffs and other config variables that become significant at low-MAP so that engine work well at 0..10 kPa . 
	  The result was engine-stumbling when you suddenly get your foot off the throttle - the iac reference positions, config.iac_integral_limit_dec
      and overrun_fuelresume can be tuned to eliminate the stumbling by ensuring MAP > 10kPa always holds at RPM < overrun_fuelresume, but appropriate 
	  fuelcut_kpa value ensures fuel is cut even if those crazy-low MAP values - and therefore short pulsewidths - are reached. This works so well that 
	  config.tpsdq related decel-fuelcut seems quite useless, scheduled for demolition in the near future.

since 1.0.13 rc5:

    * Tested with MegaTune r021, the high resolution MAP and RPM shows correctly in megatune.
    * New config variables: use config.toothrel_normal=0x76 in every case. For config.toothrel_missing=0xB5 (for N-2, eg. 60-2) 
	  and config.toothrel_missing=0x00 (for N-1, eg. 36-1). Actually, these only matter if config.primary_trigger bit3=1 and multitooth 
	  is configured bit1=0 (thus primary_trigger=09 instead of 01) but don't do that. Keep on using the same values as recommended earlier:
      primary_trigger=01 for multitooth and primary_trigger=FF/FE for coil type trigger (rising/falling edge) unless you know what you are doing.
      That way the new variables do not effect operation.

since 1.0.13:

    * camsync improvements
    * resync if VR trigger has noise during cranking
    * unfortunately rc5 was compiled with decreased trigger resync-noise-suppression (mostly used at first-crank) values (since than reverted,
      to decrease chance of firstcrank misfire in case of noisier setups)

since 1.0.12:

    * better MegaTune compatibility (vemsv3.ini r16 or newer)

since 1.0.11:

    * kpa configuration resolution can be changed to 2kPa (but is 1kPa by default) for very high boost engines: add MY_CONF += -D 
	  KPA_CONFIG_RESOLUTION=2 to my_make
    * Note1: changes also needed in MegaTune vemsv3.ini
    * Note2: all the following config variables change to max 510kPa range (2kpa unit):
          o k[] table
          o ego_maxmap
          o config.inj_stage2_start_map
          o tpsdot rates
          o hybrid_rpm_a
          o hybrid_rpm_m
          o some kpa text on LCD will become 2 kPa (eg. the axis in mtt menu)
          o misc1out_minmap
          o misc1out_maxmap
          o misc2out_minmap
          o misc2out_maxmap
          o ve_learn_kpa_scale (this is not in 2kPa units, but it needs to be doubled ?)
    * restart not needed after adjusting wbo2_nernstdc_target (from menu) to take effect.
    * iac integral starts at max value, not 0 (higher iac position => faster startup without throttle)
    * better wbo2 leave_warmup condition (leaves warmup and starts normal heater control earlier if sensor was warm for some reason;
      eg. because of mde02)
    * after mdd02 command, fuel is cut if throttle is pressed (above tps_thresh). This can be used to calibrate WBO2 free-air calibration with WOT 
	  and fuelcut (or as a minimalistic "antitheft"). mdd00 changes back to normal behaviour.
    * comm.c changed for recent r008 MegaTune (more variables logged)
    * in the r1.0.11 minor lcd_display changes: "RPM:" string was addded (back), and fixed the scale of free-air o2 on LCD
    * in the r11 there is a new feature on LCD page00 (mlp00): La:... shows Lambda (like "0.95" or "1.02") or O2% (like "20.7" - note that 
	  the dot moves to different position in this case!) or undefined (??.?)
          o note: there was a small problem with 02 display, so in the r11_v2 in lcd_print_current_o2() a small fix was made to lcd_print_XX_X( t32 >> 8 );
          o note: 'mde02' command must be used to switch on WBO2 unless engine is running (trigger is applied). This is intended this way.

since 1.0.9: 
	* camsync with coil-type primarytrigger (not restricted to multitooth). VERY IMPORTANT: USE secondary_trigger=02 if you don't 
	  use camsync, otherwise (eg. with commonly used FF value, that works no more) you won't get spark nor fuel nor automaticly activated WBO2 !!!!!
	  
	  
since 20041124 release:

    * a small patch that allows tps_low > tps_high configuration for silly TPS sensor that reads higher voltage for lower throttle opening
    * AlphaN
    * engine.batt displayed on LCD mlp06
    * BoostControl low freq PWM configurable
    * injector PW reading changed to 10 usec on LCD
    * MegaTunix stores VE to both ve_ref and learnt VE table
    * send the real ("learnt" if learning is enabled) VE table to MegaTunix not the ve_ref table (that can be confusing to the unaware)
    * highest RPM and kPa bin can be written from MegaTunix too
    * internal rx21 variables dropped in favor of a faster interpolation implementation
	  
