QC3Control
A simple Arduino library to set the voltage of a Quick Charge 3.0 source
QC3Control.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "Arduino.h"
8 
9 /*
10  * QC specification constants
11  */
12 
13 #define QC3_MIN_VOLTAGE_MV 3600
14 #define QC3_CLASS_A_MAX_VOLTAGE_MV 12000
15 #define QC3_CLASS_B_MAX_VOLTAGE_MV 20000
16 
17 // timing values for Portable Device are not available, indicative values for a HVDCP charger were taken from the uP7104 datasheet https://www.upi-semi.com/files/1889/1b8dae21-e91a-11e6-97d5-f1910565ec6d
18 #define QC_T_GLITCH_BC_DONE_MS 1500
19 #define QC_T_GLICH_V_CHANGE_MS 60
20 #define QC_T_ACTIVE_MS 1
21 #define QC_T_INACTIVE_MS 1
22 
30 class QC3Control{
31  public:
43  QC3Control(byte DpPin, byte DmPin);
44 
57  QC3Control(byte DpPin, byte DmPin, byte DmGndPin);
58 
69  void begin();
70 
81  void begin(bool classB);
82 
83 
97  void setVoltage(double volt);
98 
114  void setMilliVoltage(unsigned int milliVolt);
115 
116 
128  double getVoltage();
129 
141  unsigned int getMilliVoltage();
142 
143 
151  void set5V();
152 
153 
161  void set9V();
162 
163 
171  void set12V();
172 
173 
181  void set20V();
182 
183 
191  void incrementVoltage();
192 
193 
201  void decrementVoltage();
202 
203 
204  protected:
205  const byte _DpPin;
206  const byte _DmPin;
207  const byte _DmGndPin;
208 
211  bool _classB;
212 
213  unsigned int _milliVoltNow;
214 
215  void QC3Control::switchToContinuousMode();
216 
217  // Low level functions to obtain desired voltages
218  void dmHiZ();
219  void dm0V();
220  void dm600mV();
221  void dm3300mV();
222  void dp600mV();
223  void dp3300mV();
224 };
225 
double getVoltage()
(deprecated - use getMilliVoltage()) Return the voltage that the charger is supposed to currently pro...
Definition: QC3Control.cpp:234
void incrementVoltage()
Increment the desired voltage of the QC3.0 source by 200mV.
Definition: QC3Control.cpp:137
const byte _DpPin
Data+ pin connected to the middle of the D+ 1K5-10K bridge via a 470R resistor.
Definition: QC3Control.h:205
void setVoltage(double volt)
(deprecated - use setMilliVoltage()) Sets the desired voltage of the QC source.
Definition: QC3Control.cpp:215
void decrementVoltage()
Decrement the desired voltage of the QC3.0 source by 200mV.
Definition: QC3Control.cpp:156
Main class of the QC3Control-library.
Definition: QC3Control.h:30
void set5V()
Set voltage to 5V.
Definition: QC3Control.cpp:64
unsigned int getMilliVoltage()
Return the voltage that the charger is supposed to currently provide.
Definition: QC3Control.cpp:238
bool _classB
Do we have a class B QC source (up to 20V) ?
Definition: QC3Control.h:211
bool _continuousMode
Are we in continuous adjustment (QC3) mode?
Definition: QC3Control.h:210
void set9V()
Set voltage to 9V.
Definition: QC3Control.cpp:78
unsigned int _milliVoltNow
Voltage currently set (in mV). Using the word "now" instead of "current" to prevent confusion between...
Definition: QC3Control.h:213
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.
Definition: QC3Control.h:207
void begin()
Starts the handshake with the QC source in "class A" (up to 12V).
Definition: QC3Control.cpp:24
void set20V()
Set voltage to 20V.
Definition: QC3Control.cpp:116
void set12V()
Set voltage to 12V.
Definition: QC3Control.cpp:97
const byte _DmPin
Data- pin connected either to the middle of the D- 1K5-10K bridge via a 470R resistor (in recommended...
Definition: QC3Control.h:206
QC3Control(byte DpPin, byte DmPin)
Makes an object to control a Quick Charge source with a recommended "2-wire" circuit.
Definition: QC3Control.cpp:14
bool _handshakeDone
Is the handshake done?
Definition: QC3Control.h:209
void setMilliVoltage(unsigned int milliVolt)
Sets the desired voltage of the QC3.0 source.
Definition: QC3Control.cpp:183