QC3Control
A simple Arduino library to set the voltage of a Quick Charge 3.0 source
QC3Control Class Reference

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.
 

Detailed Description

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..

See also
setVoltage()

Constructor & Destructor Documentation

◆ QC3Control() [1/2]

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.

Parameters
[in]DpPinData+ pin
[in]DmHiPinData- "High" pin
[in]DmLoPinData- "Low" pin. If 0, the library starts in QC2 mode

◆ QC3Control() [2/2]

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.

Parameters
[in]DpPinData+ pin
[in]DmPinData- "High" pin. The lower side of the divider must be connected to GND.

Member Function Documentation

◆ begin()

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.

Returns
QC_ERROR_OK if everything is OK
See also
setVoltage(), set5V(), set9V(), set12V()

◆ decrementVoltage()

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.

Note
If no handshake has been done (via begin()) with the QC source, the first call to decrementVoltage() will result in a call to begin() to do the handshake, then the voltage will be decremented starting from 5V
Returns
QC_ERROR_OK if everything is OK, or QC_ERROR_QC2_ONLY if library is in QC2 mode

◆ getMilliVoltage()

unsigned int QC3Control::getMilliVoltage ( )
inline

Return the last voltage that was requested.

Same as getVoltage, but returns an integer value in milliVolts

Note
The library has no notion if the voltage is really set. It just tries to set it but if you just start it all of a QC3.0 source it should set the correct voltage.
Returns
The last requested voltage

◆ getVoltage()

double QC3Control::getVoltage ( )
inline

Return the last voltage that was requested.

This will be a value between 3.6 and 12V.

Note
The library has no notion if the voltage is really set. It just tries to set it but if you just start it all of a QC3.0 source it should set the correct voltage.
Returns
The last requested voltage

◆ incrementVoltage()

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.

Note
If no handshake has been done (via begin()) with the QC source, the first call to incrementVoltage() will result in a call to begin() to do the handshake, then the voltage will be incremented starting from 5V
Returns
QC_ERROR_OK if everything is OK, or QC_ERROR_QC2_ONLY if library is in QC2 mode

◆ set12V()

int QC3Control::set12V ( )

Set voltage to 12V.

Returns
Sets the output of the QC source to 12V using discrete (QC2) mode.
Note
If no handshake has been done (via begin()) with the QC source, the first call to setVoltage() will result in a call to begin() to do the handshake.
Returns
QC_ERROR_OK if everything is OK

◆ set5V()

int QC3Control::set5V ( )

Set voltage to 5V.

Returns
Sets the output of the QC source to 5V using discrete (QC2) mode.
Note
If no handshake has been done (via begin()) with the QC source, the first call to setVoltage() will result in a call to begin() to do the handshake.
Returns
QC_ERROR_OK if everything is OK

◆ set9V()

int QC3Control::set9V ( )

Set voltage to 9V.

Returns
Sets the output of the QC source to 9V using discrete (QC2) mode.
Note
If no handshake has been done (via begin()) with the QC source, the first call to setVoltage() will result in a call to begin() to do the handshake.
Returns
QC_ERROR_OK if everything is OK

◆ setMilliVoltage()

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

See also
setVoltage()
Parameters
[in]milliVoltThe desired voltage in mV (between 3600mV and 12000mV).
Returns
QC_ERROR_OK if everything is OK, or QC_ERROR_QC2_ONLY if library is in QC2 mode and requested voltage cannot be set

◆ setVoltage()

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.

Note
If no handshake has been done (via begin()) with the QC source, the first call to setVoltage() will result in a call to begin() to do the handshake.
Parameters
[in]voltThe desired voltage (between 3.6V and 12V).
Returns
QC_ERROR_OK if everything is OK, or QC_ERROR_QC2_ONLY if library is in QC2 mode and requested voltage cannot be set

The documentation for this class was generated from the following files: