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  * Params and return value constants
11  */
12 
13 #define QC_ERROR_OK 0
14 #define QC_ERROR_QC2_ONLY -1
15 
16 /*
17  * QC specification constants
18  */
19 
20 #define QC3_MIN_VOLTAGE_MV 3600
21 #define QC3_MAX_VOLTAGE_MV 12000
22 
23 // timing values for Portable Device are not available, indicative values for a HVDCP taken from uP7104 datasheet https://www.upi-semi.com/files/1889/1b8dae21-e91a-11e6-97d5-f1910565ec6d
24 #define QC_T_GLICH_V_CHANGE_MS 60
25 #define QC_T_ACTIVE_MS 1
26 #define QC_T_INACTIVE_MS 1
27 
35 class QC3Control{
36  public:
47  QC3Control(byte DpPin, byte DmHiPin, byte DmLoPin);
48 
58  QC3Control(byte DpPin, byte DmPin);
59 
72  int begin();
73 
85  int setVoltage(double volt);
86 
99  int setMilliVoltage(unsigned int milliVolt);
100 
101 
111  double getVoltage();
112 
122  unsigned int getMilliVoltage();
123 
124 
134  int set5V();
135 
145  int set9V();
146 
156  int set12V();
157 
167  int incrementVoltage();
168 
178  int decrementVoltage();
179 
180 
181  protected:
182  const byte _DpPin;
183  const byte _DmHiPin;
184  const byte _DmLoPin;
185 
188 
189  unsigned int _milliVoltNow;
190 
191  static const unsigned int _WaitTime;
192 
193  int QC3Control::switchToContinuousMode();
194 
195  // Low level functions to obtain desired voltages
196  void dm0V();
197  void dm600mV();
198  void dm3300mV();
199  void dp600mV();
200  void dp3300mV();
201 };
202 
double getVoltage()
Return the last voltage that was requested.
Definition: QC3Control.cpp:189
QC3Control(byte DpPin, byte DmHiPin, byte DmLoPin)
Makes an object to control a Quick Charge 3.0 source.
Definition: QC3Control.cpp:6
const byte _DmHiPin
Data- "high" pin.
Definition: QC3Control.h:183
const byte _DpPin
Data+ pin.
Definition: QC3Control.h:182
int set9V()
Set voltage to 9V.
Definition: QC3Control.cpp:61
Main class of the QC3Control-library.
Definition: QC3Control.h:35
int decrementVoltage()
Decrement the desired voltage of the QC3.0 source by 200mV.
Definition: QC3Control.cpp:126
unsigned int getMilliVoltage()
Return the last voltage that was requested.
Definition: QC3Control.cpp:193
bool _continuousMode
Are we in QC3 continuous adjustment mode?
Definition: QC3Control.h:187
int begin()
Starts the handshake with the QC3.0 source.
Definition: QC3Control.cpp:26
int set12V()
Set voltage to 12V.
Definition: QC3Control.cpp:82
unsigned int _milliVoltNow
Voltage currently set (in mV). Avoiding the term "current milliVolt" to prevent confusion between "cu...
Definition: QC3Control.h:189
int setVoltage(double volt)
Sets the desired voltage of the QC3.0 source.
Definition: QC3Control.cpp:184
int incrementVoltage()
Increment the desired voltage of the QC3.0 source by 200mV.
Definition: QC3Control.cpp:103
const byte _DmLoPin
Data- "low" pin. If set to 0, library is in QC2 mode.
Definition: QC3Control.h:184
int setMilliVoltage(unsigned int milliVolt)
Sets the desired voltage of the QC3.0 source.
Definition: QC3Control.cpp:157
bool _handshakeDone
Is the handshake done?
Definition: QC3Control.h:186
static const unsigned int _WaitTime
Wait time in the handshake. Should be at least 1,25s.
Definition: QC3Control.h:191
int set5V()
Set voltage to 5V.
Definition: QC3Control.cpp:45