QC3Control
A simple Arduino library to set the voltage of a Quick Charge 3.0 source
|
Main class of the QC3Control-library. More...
#include <QC3Control.h>
Public Member Functions | |
QC3Control (byte DpPin, byte DmPin) | |
Makes an object to control a Quick Charge source with a recommended "2-wire" circuit. More... | |
QC3Control (byte DpPin, byte DmPin, byte DmGndPin) | |
Makes an object to control a Quick Charge 3.0 source with a legacy "3-wire" circuit. More... | |
void | begin () |
Starts the handshake with the QC source in "class A" (up to 12V). More... | |
void | begin (bool classB) |
Starts the handshake with the QC source, specifying whether the source is "class B" compliant (up to 20V) or not. More... | |
void | setVoltage (double volt) |
(deprecated - use setMilliVoltage()) Sets the desired voltage of the QC source. More... | |
void | setMilliVoltage (unsigned int milliVolt) |
Sets the desired voltage of the QC3.0 source. More... | |
double | getVoltage () |
(deprecated - use getMilliVoltage()) Return the voltage that the charger is supposed to currently provide. More... | |
unsigned int | getMilliVoltage () |
Return the voltage that the charger is supposed to currently provide. More... | |
void | set5V () |
Set voltage to 5V. More... | |
void | set9V () |
Set voltage to 9V. More... | |
void | set12V () |
Set voltage to 12V. More... | |
void | set20V () |
Set voltage to 20V. More... | |
void | incrementVoltage () |
Increment the desired voltage of the QC3.0 source by 200mV. More... | |
void | decrementVoltage () |
Decrement the desired voltage of the QC3.0 source by 200mV. More... | |
Protected Member Functions | |
void | switchToContinuousMode () |
void | dmHiZ () |
void | dm0V () |
void | dm600mV () |
void | dm3300mV () |
void | dp600mV () |
void | dp3300mV () |
Protected Attributes | |
const byte | _DpPin |
Data+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor. | |
const byte | _DmPin |
Data- pin connected either to the middle of the D- 1K5-10K bridge via a 470R resistor (in recommended "2-wire" circuit), or to the top of the D- 1K5-10K bridge (in legacy "3-wire" circuit) | |
const byte | _DmGndPin |
Pin pin connected to the bottom of the D- 1K5-10K bridge in legacy "3-wire" circuit. Must be 0 if using a recommended "2-wire" circuit. | |
bool | _handshakeDone |
Is the handshake done? | |
bool | _continuousMode |
Are we in continuous adjustment (QC3) mode? | |
bool | _classB |
Do we have a class B QC source (up to 20V) ? | |
unsigned int | _milliVoltNow |
Voltage currently set (in mV). Using the word "now" instead of "current" to prevent confusion between "current" and "voltage" :-) | |
Main class of the QC3Control-library.
The QC3Control-class includes all the functions to easily set the voltage of a Quick Charge 3.0 source..
QC3Control::QC3Control | ( | byte | DpPin, |
byte | DmPin | ||
) |
Makes an object to control a Quick Charge source with a recommended "2-wire" circuit.
Makes it possible to set the voltage of the QC source to 5V, 9V or 12V (with a QC2.0 or later charger) or to any supported voltage between 3.6V and 12V (with a QC3.0 or later charger). Call this constructor if you are using a recommended "2-wire" circuit. See general description on how to wire it.
[in] | DpPin | Data+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor |
[in] | DmPin | Data- pin connected to the middle of the D- 1K5-10K bridge via a 470R resistor |
QC3Control::QC3Control | ( | byte | DpPin, |
byte | DmPin, | ||
byte | DmGndPin | ||
) |
Makes an object to control a Quick Charge 3.0 source with a legacy "3-wire" circuit.
Makes it possible to set the voltage of the QC source to 5V, 9V or 12V (with a QC2.0 or later charger) or to any supported voltage between 3.6V and 12V (with a QC3.0 or later charger). Call this constructor if you are using a legacy "3-wire" circuit (try this if the "2-wire" circuit fails). See general description on how to wire it.
[in] | DpPin | Data+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor |
[in] | DmPin | Data- pin connected to the top of the D- 1K5-10K bridge |
[in] | DmGndPin | pin connected to the bottom of the D- 1K5-10K bridge |
void QC3Control::begin | ( | ) |
Starts the handshake with the QC source in "class A" (up to 12V).
A handshake is needed to be able to set the voltage. begin() may be left out, in which case the first method modifying the voltage will silently call begin().
begin() is blocking code. It waits for a fixed period counting from the start up of the Arduino to act because the handshake needs a minimum time. But this is most likely not a problem because if you need 9V or 12V in your application, there is no gain in proceeding when the voltage isn't there yet (because of the handshake). And by putting begin() (or a call to one of the setXXX() functions) at the end of setup() (or other initialization) you can even do stuff while waiting because it counts from Arduino startup.
void QC3Control::begin | ( | bool | classB | ) |
Starts the handshake with the QC source, specifying whether the source is "class B" compliant (up to 20V) or not.
A handshake is needed to be able to set the voltage. begin() may be left out, in which case the first method modifying the voltage will silently call begin(false).
begin() is blocking code. It waits for a fixed period counting from the start up of the Arduino to act because the handshake needs a minimum time. But this is most likely not a problem because if you need 9V or 12V in your application, there is no gain in proceeding when the voltage isn't there yet (because of the handshake). And by putting begin() (or a call to one of the setXXX() functions) at the end of setup() (or other initialization) you can even do stuff while waiting because it counts from Arduino startup.
void QC3Control::decrementVoltage | ( | ) |
Decrement the desired voltage of the QC3.0 source by 200mV.
Will request a decrement of the voltage by 200mV. Performing the decrement request when the minimum value is already reached has no effect.
|
inline |
Return the voltage that the charger is supposed to currently provide.
Same as getVoltage, but returns an integer value in milliVolts
|
inline |
(deprecated - use getMilliVoltage()) Return the voltage that the charger is supposed to currently provide.
This will be a value between 3.6 and 12V.
void QC3Control::incrementVoltage | ( | ) |
Increment the desired voltage of the QC3.0 source by 200mV.
Will request an increment of the voltage by 200mV. Performing the increment request when the maximum value is already reached has no effect.
void QC3Control::set12V | ( | ) |
void QC3Control::set20V | ( | ) |
void QC3Control::set5V | ( | ) |
void QC3Control::set9V | ( | ) |
void QC3Control::setMilliVoltage | ( | unsigned int | milliVolt | ) |
Sets the desired voltage of the QC3.0 source.
Will always set the passed voltage using continuous (QC3) mode (even for 5V, 9V, 12V and 20V). To force usage of discrete (QC2) mode, please use set5V(), set9V(), set12V() or set20V();
[in] | milliVolt | The desired voltage in mV (between 3600mV and 12000mV). |
void QC3Control::setVoltage | ( | double | volt | ) |
(deprecated - use setMilliVoltage()) Sets the desired voltage of the QC source.
Will set the passed voltage either using discrete (QC2) mode for 5V, 9V and 12V (for backwards compatibility with QC2Control API), or using continuous (QC3) mode for all other values. Please use setMilliVoltage() to avoid this behaviour.
[in] | volt | The desired voltage (between 3.6V and 12V). |