doppelhub / MuddersMIMA

Mudders Take on Manual IMA Control in the G1 Honda Insight
GNU General Public License v3.0
2 stars 4 forks source link

Brake light handling question #4

Closed Hurricos closed 9 months ago

Hurricos commented 9 months ago

@mudder,

I notice this JTS2doNow under MuddersMima.git@main:muddersMIMA_firmware/brakeLights.cpp:

uint8_t brakeLights_handler(void)
:
        //brake light control logic
        //JTS2doNow: When brake pressed, gpio_getBrakePosition_bool() alternates between "Lights ON" & "Lights OFF"
        if     (joystickPercent < JOYSTICK_MIN_ALLOWED_PERCENT)                { gpio_brakeLights_turnOff(); } //joystick input too low 
        else if(joystickPercent < TURN_BRAKE_LIGHTS_ON_BELOW_JOYSTICK_PERCENT) { gpio_brakeLights_turnOn();  } //strong regen
        else if(gpio_getBrakePosition_bool() == BRAKE_LIGHTS_ARE_ON)           { gpio_brakeLights_turnOff();  }
        else                                                                   { gpio_brakeLights_floatPin(); }
    }
    else if(brakeLightMode == BRAKE_LIGHT_FORCE_ON) { gpio_brakeLights_turnOn();  }
    else if(brakeLightMode == BRAKE_LIGHT_OEM)      { gpio_brakeLights_turnOff(); }
    else if(brakeLightMode == BRAKE_LIGHT_PULSE)    { pulseBrakeLights();         }
}

Two questions:

Edit: I get it now. We'd ideally alternate so that we can detect whether the brake pedal is actually being pushed independently of LiControl driving the line connected to the brake switch.

Hurricos commented 9 months ago

I believe my understanding is beyond that which prompted the initial question; I'm going to leave this issue open until I can find and link the post where you mention [the need to be] flickering the brake lights (I recall this but don't know where it was).

doppelhub commented 9 months ago

You've got it figured out: -Insight's only brake signal is the actual 12 volt line that energizes the bulb; there's no other signal we can measure. -LiControl has a "high side FET driver" ('HSFD') essentially in parallel with the OEM brake switch (on the pedal). -When the user pushes the brake pedal, 12 volts appears on LiControl's 'BRAKE' screw terminal pin. This signal is then translated to 5 volt TTL and fed into one of LiControl's I/O pins ('D5'). Part of this hardware translation process includes a circuit that causes the HSFD to turn on. This circuit causes the HSFD to latch on each time the brake light is pressed, but only when the key is on (or LiControl is connected to a powered USB port, e.g. while uploading firmware). -When the user lets go of the brake pedal, the HSFD does not turn off, due to the latching behavior described above. -When LiControl wants the brake light on, it just pulls pin D5 high (whether or not the brake light was previously on). -When LiControl doesn't want the brake light on, if the BRAKE pin is low, LiControl can immediately determine that the light is off (so no further action is needed). -When LiControl doesn't want the brake light on, if the BRAKE pin is high, LiControl can't initially tell whether or not the user is pressing the brake pedal. Therefore, LiControl forces the HSFD off by briefly pulling D5 low, which forces the HSFD off. If the user isn't pushing the brake pedal, then the BRAKE signal will also go low (and the brake lights will turn off). If the user is pushing the brake pedal, then the BRAKE signal will stay high (and the brake lights will turn on).

doppelhub commented 9 months ago

My previous comment should make the code in brakeLights_handler.cpp make more sense.

The hardware design described above adds the following limitation: -If LiControl turns the brake lights on (by pulling D5 high, which turns on the HSFD), AND; -you are using the ECM's OEM CMDPWR signal in any way to influence the CMDPWR signal LiControl then forwards to the MCM, THEN; -as soon as LiControl turns the brake lights on, the ECM will command full regen (because the ECM thinks you're pressing the brake pedal).

For the above reasons, you cannot program LiControl to turn on the brake lights in any mode that uses the ECM's CMDPWR signal (e.g. 'OEM Mode 0'). See function brakeLights_setControlMode(), which controls whether or not LiControl will illuminate the brake lights.

Hurricos commented 9 months ago

Makes sense. I'll close the issue, now that it contains documentation about what's going on.