| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "vr_pwm.h" | |||
| 4 | ||||
| 5 | static OutputPin pins[VR_THRESHOLD_COUNT]; | |||
| 6 | static SimplePwm pwms[VR_THRESHOLD_COUNT]; | |||
| 7 | ||||
| 8 | // Default to 3.3v if not defined, most boards wire the VR threshold input directly to an MCU pin. | |||
| 9 | #ifndef VR_SUPPLY_VOLTAGE | |||
| 10 | #define VR_SUPPLY_VOLTAGE 3.3f | |||
| 11 | #endif | |||
| 12 | ||||
| 13 | 2184 | static void updateVrThresholdPwm(float rpm, size_t index) { | ||
| 14 | 2184 | auto& cfg = engineConfiguration->vrThreshold[index]; | ||
| 15 | ||||
| 16 |
1/2✓ Branch 1 taken 2184 times.
✗ Branch 2 not taken.
|
1/2✓ Decision 'true' taken 2184 times.
✗ Decision 'false' not taken.
|
2184 | if (!isBrainPinValid(cfg.pin)) { |
| 17 | 2184 | return; | ||
| 18 | } | |||
| 19 | ||||
| 20 | ✗ | float thresholdVoltage = interpolate2d(rpm, cfg.rpmBins, cfg.values); | ||
| 21 | ||||
| 22 | // 0v threshold voltage = 3.3v output from mcu = 100% duty | |||
| 23 | // 2.5v threshold voltage = 0v output from mcu = 0% duty | |||
| 24 | ✗ | float thresholdInputVoltage = interpolateClamped(0, 3.3f, 2.5f, 0, thresholdVoltage); | ||
| 25 | ||||
| 26 | ✗ | float duty = thresholdInputVoltage / VR_SUPPLY_VOLTAGE; | ||
| 27 | ||||
| 28 | ✗ | pwms[index].setSimplePwmDutyCycle(duty); | ||
| 29 | } | |||
| 30 | ||||
| 31 | 1092 | void updateVrThresholdPwm() { | ||
| 32 | 1092 | auto rpm = Sensor::getOrZero(SensorType::Rpm); | ||
| 33 | ||||
| 34 |
2/2✓ Branch 1 taken 2184 times.
✓ Branch 2 taken 1092 times.
|
2/2✓ Decision 'true' taken 2184 times.
✓ Decision 'false' taken 1092 times.
|
3276 | for (size_t i = 0; i < efi::size(engineConfiguration->vrThreshold); i++) { |
| 35 | 2184 | updateVrThresholdPwm(rpm, i); | ||
| 36 | } | |||
| 37 | 1092 | } | ||
| 38 | ||||
| 39 | ✗ | void initVrThresholdPwm() { | ||
| 40 | ✗ | for (size_t i = 0; i < efi::size(engineConfiguration->vrThreshold); i++) { | ||
| 41 | ✗ | auto& cfg = engineConfiguration->vrThreshold[i]; | ||
| 42 | ||||
| 43 | ✗ | if (!isBrainPinValid(cfg.pin)) { | ||
| 44 | ✗ | continue; | ||
| 45 | } | |||
| 46 | ||||
| 47 | ✗ | startSimplePwmHard(&pwms[i], "VR Threshold", | ||
| 48 | &engine->scheduler, | |||
| 49 | cfg.pin, | |||
| 50 | ✗ | &pins[i], | ||
| 51 | 10000, // it's guaranteed to be hardware PWM, the faster the PWM, the less noise makes it through | |||
| 52 | 0 | |||
| 53 | ); | |||
| 54 | } | |||
| 55 | ✗ | } | ||
| 56 | ||||
| 57 | 593 | void setDefaultVrThresholds() { | ||
| 58 |
2/2✓ Branch 0 taken 1186 times.
✓ Branch 1 taken 593 times.
|
2/2✓ Decision 'true' taken 1186 times.
✓ Decision 'false' taken 593 times.
|
1779 | for (int i = 0;i<VR_THRESHOLD_COUNT;i++) { |
| 59 | 1186 | setRpmTableBin(engineConfiguration->vrThreshold[i].rpmBins); | ||
| 60 | 1186 | setLinearCurve(engineConfiguration->vrThreshold[i].values, 0.6, 1.2, 0.1); | ||
| 61 | } | |||
| 62 | 593 | } | ||
| 63 |