Slight reqork of QC logic to bring back older style + mix in another compatability hack
This commit is contained in:
@@ -233,10 +233,25 @@ void startQC(uint16_t divisor) {
|
|||||||
|
|
||||||
// Delay 1.25 seconds
|
// Delay 1.25 seconds
|
||||||
uint8_t enteredQC = 0;
|
uint8_t enteredQC = 0;
|
||||||
vTaskDelay(125);
|
for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) {
|
||||||
// Check if D- is low to spot a QC charger
|
vTaskDelay(1); //10mS pause
|
||||||
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET)
|
if (i > 130) {
|
||||||
enteredQC = 1;
|
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET) {
|
||||||
|
enteredQC = 1;
|
||||||
|
}
|
||||||
|
if (i == 140) {
|
||||||
|
//For some marginal QC chargers, we try adding a pulldown
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
if (enteredQC) {
|
if (enteredQC) {
|
||||||
// We have a QC capable charger
|
// We have a QC capable charger
|
||||||
QC_Seek9V();
|
QC_Seek9V();
|
||||||
@@ -280,19 +295,19 @@ static unsigned int sqrt32(unsigned long n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int16_t calculateMaxVoltage(uint8_t useHP) {
|
int16_t calculateMaxVoltage(uint8_t useHP) {
|
||||||
// This measures the tip resistance, then it calculates the appropriate
|
// This measures the tip resistance, then it calculates the appropriate
|
||||||
// voltage To stay under ~18W. Mosfet is "9A", so no issues there
|
// voltage To stay under ~18W. Mosfet is "9A", so no issues there
|
||||||
// QC3.0 supports up to 18W, which is 2A @9V and 1.5A @12V
|
// QC3.0 supports up to 18W, which is 2A @9V and 1.5A @12V
|
||||||
uint32_t milliOhms = 4500;
|
uint32_t milliOhms = 4500;
|
||||||
// Check no tip
|
// Check no tip
|
||||||
if (milliOhms > 10000)
|
if (milliOhms > 10000)
|
||||||
return -1;
|
return -1;
|
||||||
//Because of tolerance, if a user has asked for the higher power mode, then just goto 12V and call it a day
|
//Because of tolerance, if a user has asked for the higher power mode, then just goto 12V and call it a day
|
||||||
if (useHP)
|
if (useHP)
|
||||||
return 120;
|
return 120;
|
||||||
//
|
//
|
||||||
// V = sqrt(18W*R)
|
// V = sqrt(18W*R)
|
||||||
// Convert this to sqrt(18W)*sqrt(milli ohms)*sqrt(1/1000)
|
// Convert this to sqrt(18W)*sqrt(milli ohms)*sqrt(1/1000)
|
||||||
|
|
||||||
uint32_t Vx = sqrt32(milliOhms);
|
uint32_t Vx = sqrt32(milliOhms);
|
||||||
if (useHP)
|
if (useHP)
|
||||||
@@ -300,17 +315,17 @@ int16_t calculateMaxVoltage(uint8_t useHP) {
|
|||||||
else
|
else
|
||||||
Vx *= 1342; // sqrt(18) * sqrt(1/1000)*10000
|
Vx *= 1342; // sqrt(18) * sqrt(1/1000)*10000
|
||||||
|
|
||||||
// Round to nearest 200mV,
|
// Round to nearest 200mV,
|
||||||
// So divide by 100 to start, to get in Vxx
|
// So divide by 100 to start, to get in Vxx
|
||||||
Vx /= 100;
|
Vx /= 100;
|
||||||
if (Vx % 10 >= 5)
|
if (Vx % 10 >= 5)
|
||||||
Vx += 10;
|
Vx += 10;
|
||||||
Vx /= 10;
|
Vx /= 10;
|
||||||
// Round to nearest increment of 2
|
// Round to nearest increment of 2
|
||||||
if (Vx % 2 == 1)
|
if (Vx % 2 == 1)
|
||||||
Vx++;
|
Vx++;
|
||||||
//Because of how bad the tolerance is on detecting the tip resistance is
|
//Because of how bad the tolerance is on detecting the tip resistance is
|
||||||
//Its more functional to bin this
|
//Its more functional to bin this
|
||||||
if (Vx < 90)
|
if (Vx < 90)
|
||||||
Vx = 90;
|
Vx = 90;
|
||||||
else if (Vx >= 105)
|
else if (Vx >= 105)
|
||||||
@@ -332,7 +347,7 @@ void setTipPWM(uint8_t pulse) {
|
|||||||
// timers.
|
// timers.
|
||||||
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||||
// Period has elapsed
|
// Period has elapsed
|
||||||
if (htim->Instance == TIM2) {
|
if (htim->Instance == TIM2) {
|
||||||
// we want to turn on the output again
|
// we want to turn on the output again
|
||||||
PWMSafetyTimer--;
|
PWMSafetyTimer--;
|
||||||
@@ -354,7 +369,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
|
||||||
// This was a when the PWM for the output has timed out
|
// This was a when the PWM for the output has timed out
|
||||||
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
|
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
|
||||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
|
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user