From 47e74b8ca8649d13cbe27db6ae0cee4c50215fee Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 18 Jun 2014 18:08:04 -0700 Subject: [PATCH] zinger: do not trigger OCP on transients Ensure that the slow OCP (thermal/power protection) is not triggering for power spikes below 20us, by sampling 4 times (with a 5us sampling period). Signed-off-by: Vincent Palatin BRANCH=none BUG=chrome-os-partner:28331 TEST=connect Zinger to Firefly+electronic load, test with various current pulse widths and amplitudes. Change-Id: Ic8150dbbf191c002bba9e8d3f70beb47af4577b9 Reviewed-on: https://chromium-review.googlesource.com/204588 Reviewed-by: Alec Berg Tested-by: Alec Berg Commit-Queue: Alec Berg --- board/zinger/usb_pd_policy.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c index 5123b7c5a0..fded37ab11 100644 --- a/board/zinger/usb_pd_policy.c +++ b/board/zinger/usb_pd_policy.c @@ -205,18 +205,35 @@ int pd_board_checks(void) /* re-enable fast OCP */ adc_enable_watchdog(ADC_CH_A_SENSE, MAX_CURRENT_FAST, 0); - if ((fault == FAULT_FAST_OCP) || (vbus_amp > MAX_CURRENT)) { - debug_printf("OverCurrent : %d mA\n", - vbus_amp * VDDA_MV / CURR_GAIN * 1000 / R_SENSE / ADC_SCALE); + if (fault == FAULT_FAST_OCP) { + debug_printf("Fast OverCurrent\n"); fault = FAULT_OCP; /* reset over-current after 1 second */ fault_deadline.val = get_time().val + OCP_TIMEOUT; return EC_ERROR_INVAL; } + if (vbus_amp > MAX_CURRENT) { + /* 3 more samples to check whether this is just a transient */ + int count; + for (count = 0; count < 3; count++) + if (adc_read_channel(ADC_CH_A_SENSE) < MAX_CURRENT) + break; + /* trigger the slow OCP iff all 4 samples are above the max */ + if (count == 3) { + debug_printf("OverCurrent : %d mA\n", + vbus_amp * VDDA_MV / CURR_GAIN * 1000 + / R_SENSE / ADC_SCALE); + fault = FAULT_OCP; + /* reset over-current after 1 second */ + fault_deadline.val = get_time().val + OCP_TIMEOUT; + return EC_ERROR_INVAL; + } + } if ((output_is_enabled() && (vbus_volt > voltages[volt_idx].ovp)) || (fault && (vbus_volt > voltages[volt_idx].ovp_rec))) { - debug_printf("OverVoltage : %d mV\n", - vbus_volt * VDDA_MV * VOLT_DIV / ADC_SCALE); + if (!fault) + debug_printf("OverVoltage : %d mV\n", + vbus_volt * VDDA_MV * VOLT_DIV / ADC_SCALE); /* TODO(crosbug.com/p/28331) discharge */ fault = FAULT_OVP; /* no timeout */