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 DmHiPin, byte DmLoPin) | |
Makes an object to control a Quick Charge 3.0 source. More... | |
QC3Control (byte DpPin, byte DmPin) | |
Makes an object to control a Quick Charge 2.0 source (QC2 mode). More... | |
int | begin () |
Starts the handshake with the QC3.0 source. More... | |
int | setVoltage (double volt) |
Sets the desired voltage of the QC3.0 source. More... | |
int | setMilliVoltage (unsigned int milliVolt) |
Sets the desired voltage of the QC3.0 source. More... | |
double | getVoltage () |
Return the last voltage that was requested. More... | |
unsigned int | getMilliVoltage () |
Return the last voltage that was requested. More... | |
int | set5V () |
Set voltage to 5V. More... | |
int | set9V () |
Set voltage to 9V. More... | |
int | set12V () |
Set voltage to 12V. More... | |
int | incrementVoltage () |
Increment the desired voltage of the QC3.0 source by 200mV. More... | |
int | decrementVoltage () |
Decrement the desired voltage of the QC3.0 source by 200mV. More... | |
Protected Member Functions | |
int | switchToContinuousMode () |
void | dm0V () |
void | dm600mV () |
void | dm3300mV () |
void | dp600mV () |
void | dp3300mV () |
Protected Attributes | |
const byte | _DpPin |
Data+ pin. | |
const byte | _DmHiPin |
Data- "high" pin. | |
const byte | _DmLoPin |
Data- "low" pin. If set to 0, library is in QC2 mode. | |
bool | _handshakeDone |
Is the handshake done? | |
bool | _continuousMode |
Are we in QC3 continuous adjustment mode? | |
unsigned int | _milliVoltNow |
Voltage currently set (in mV). Avoiding the term "current milliVolt" to prevent confusion between "current" and "voltage" :-) | |
Static Protected Attributes | |
static const unsigned int | _WaitTime = 1500 |
Wait time in the handshake. Should be at least 1,25s. | |
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 | DmHiPin, | ||
byte | DmLoPin | ||
) |
Makes an object to control a Quick Charge 3.0 source.
Makes it possible to set the voltage of the QC3.0 source to any supported voltage (between 3.6V and 12V). See general description on how to wire it.
[in] | DpPin | Data+ pin |
[in] | DmHiPin | Data- "High" pin |
[in] | DmLoPin | Data- "Low" pin. If 0, the library starts in QC2 mode |
QC3Control::QC3Control | ( | byte | DpPin, |
byte | DmPin | ||
) |
Makes an object to control a Quick Charge 2.0 source (QC2 mode).
Makes it possible to set the voltage of the QC2.0 source to either 5V, 9V or 12V. This is backwards compatible with QCControl2.
[in] | DpPin | Data+ pin |
[in] | DmPin | Data- "High" pin. The lower side of the divider must be connected to GND. |
int QC3Control::begin | ( | ) |
Starts the handshake with the QC3.0 source.
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 (1,25s minimum). 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 setVoltage()) at the end of setup() (or other initialization) you can even do stuff while waiting because it counts from Arduino startup.
int 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 last voltage that was requested.
Same as getVoltage, but returns an integer value in milliVolts
|
inline |
Return the last voltage that was requested.
This will be a value between 3.6 and 12V.
int 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.
int QC3Control::set12V | ( | ) |
Set voltage to 12V.
int QC3Control::set5V | ( | ) |
Set voltage to 5V.
int QC3Control::set9V | ( | ) |
Set voltage to 9V.
int QC3Control::setMilliVoltage | ( | unsigned int | milliVolt | ) |
Sets the desired voltage of the QC3.0 source.
Same as setVoltage, but takes an integer value in milliVolts
[in] | milliVolt | The desired voltage in mV (between 3600mV and 12000mV). |
int QC3Control::setVoltage | ( | double | volt | ) |
Sets the desired voltage of the QC3.0 source.
Will set the voltage using continuous (QC3) mode. Setting an unreachable voltage will result in the closest supported voltage.
[in] | volt | The desired voltage (between 3.6V and 12V). |