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 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" :-)
 

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
setMilliVoltage(unsigned int)

Constructor & Destructor Documentation

◆ QC3Control() [1/2]

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.

Parameters
[in]DpPinData+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor
[in]DmPinData- pin connected to the middle of the D- 1K5-10K bridge via a 470R resistor

◆ QC3Control() [2/2]

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.

Parameters
[in]DpPinData+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor
[in]DmPinData- pin connected to the top of the D- 1K5-10K bridge
[in]DmGndPinpin connected to the bottom of the D- 1K5-10K bridge

Member Function Documentation

◆ begin() [1/2]

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.

See also
begin(bool), setMilliVoltage(unsigned int), set5V(), set9V(), set12V()

◆ begin() [2/2]

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.

See also
begin(), setMilliVoltage(unsigned int), set5V(), set9V(), set12V(), set20V()

◆ decrementVoltage()

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.

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

◆ getMilliVoltage()

unsigned int QC3Control::getMilliVoltage ( )
inline

Return the voltage that the charger is supposed to currently provide.

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.
See also
getVoltage()
Returns
The voltage that the charger is supposed to currently provide, in milliVolt

◆ getVoltage()

double QC3Control::getVoltage ( )
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.

Note
The library has no feedback if that voltage is actually provided. It just takes note of the operations requested to the charger and computes the voltage that the charger is supposed to output now.
See also
getMilliVoltage()
Returns
The voltage that the charger is supposed to currently provide, in Volt

◆ incrementVoltage()

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.

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

◆ set12V()

void QC3Control::set12V ( )

Set voltage to 12V.

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 set12V() will result in a call to begin() to do the handshake.

◆ set20V()

void QC3Control::set20V ( )

Set voltage to 20V.

Sets the output of the QC Class B source to 20V using discrete mode.

Note
If no handshake has been done (via begin()) with the QC source, the first call to set20V() will result in a call to begin() to do the handshake.

◆ set5V()

void QC3Control::set5V ( )

Set voltage to 5V.

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 set5V() will result in a call to begin() to do the handshake.

◆ set9V()

void QC3Control::set9V ( )

Set voltage to 9V.

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 set9V() will result in a call to begin() to do the handshake.

◆ setMilliVoltage()

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();

Note
If no handshake has been done (via begin()) with the QC source, the first call to setMilliVoltage() will result in a call to begin() to do the handshake.
Setting an unreachable voltage will result in the closest supported voltage being set.
Calling this method on a QC2 charger will not work.
See also
set5V(), set9V(), set12V()
Parameters
[in]milliVoltThe desired voltage in mV (between 3600mV and 12000mV).

◆ setVoltage()

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.

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.
Setting an unreachable voltage will result in the closest supported voltage being set.
Calling this method on a QC2 charger will only work for 5V, 9V or 12V.
Parameters
[in]voltThe desired voltage (between 3.6V and 12V).
See also
setMilliVoltage(unsigned int), set5V(), set9V(), set12V()

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