Skip to content

Commit ba788bd

Browse files
committed
0.5.2 MCP_DAC
1 parent 36289cc commit ba788bd

File tree

7 files changed

+57
-44
lines changed

7 files changed

+57
-44
lines changed

libraries/MCP_DAC/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.5.2] - 2025-01-31
10+
- fix #33, update readme.md about **gain**
11+
- added comments about gain in code.
12+
913
## [0.5.1] - 2024-06-05
1014
- add support for ARDUINO_ARCH_MBED
1115

libraries/MCP_DAC/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2024 Rob Tillaart
3+
Copyright (c) 2021-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/MCP_DAC/MCP_DAC.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: MCP_DAC.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.5.1
4+
// VERSION: 0.5.2
55
// DATE: 2021-02-03
66
// PURPOSE: Arduino library for MCP_DAC
77
// URL: https://github.com/RobTillaart/MCP_DAC
@@ -40,6 +40,8 @@ MCP_DAC::MCP_DAC(uint8_t dataOut, uint8_t clock)
4040

4141
void MCP_DAC::reset()
4242
{
43+
// _gain is default set to 1x as that gives the lowest output voltages
44+
// this is the safest option, although datasheet 4.1.1.1 states default = 2x
4345
_gain = 1;
4446
_value[0] = 0;
4547
_value[1] = 0;

libraries/MCP_DAC/MCP_DAC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: MCP_DAC.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.5.1
5+
// VERSION: 0.5.2
66
// DATE: 2021-02-03
77
// PURPOSE: Arduino library for MCP_DAC
88
// URL: https://github.com/RobTillaart/MCP_DAC
@@ -12,7 +12,7 @@
1212
#include "SPI.h"
1313

1414

15-
#define MCP_DAC_LIB_VERSION (F("0.5.1"))
15+
#define MCP_DAC_LIB_VERSION (F("0.5.2"))
1616

1717

1818
#ifndef __SPI_CLASS__
@@ -48,6 +48,8 @@ class MCP_DAC
4848
uint16_t maxValue();
4949

5050
// gain = 1 or 2
51+
// gain is default set to 1x as that gives the lowest output voltages
52+
// this is the safest option, datasheet 4.1.1.1 states default = 2x
5153
bool setGain(uint8_t gain = 1);
5254
uint8_t getGain();
5355

libraries/MCP_DAC/README.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,34 @@ The library is not tested with all different devices however stable.
2222
Please post an issue if there are problems with a specific device.
2323

2424

25-
| Type | Channels | Bits | MaxValue | Voltage reference |
26-
|:--------|:--------:|:----:|:--------:|:-----------------:|
27-
| MCP4801 | 1 | 8 | 255 | internal 2.048 V |
28-
| MCP4802 | 2 | 8 | 255 | internal 2.048 V |
29-
| MCP4811 | 1 | 10 | 1023 | internal 2.048 V |
30-
| MCP4812 | 2 | 10 | 1023 | internal 2.048 V |
31-
| MCP4821 | 1 | 12 | 4095 | internal 2.048 V |
32-
| MCP4822 | 2 | 12 | 4095 | internal 2.048 V |
33-
| MCP4901 | 1 | 8 | 255 | external |
34-
| MCP4902 | 2 | 8 | 255 | external |
35-
| MCP4911 | 1 | 10 | 1023 | external |
36-
| MCP4912 | 2 | 10 | 1023 | external |
37-
| MCP4921 | 1 | 12 | 4095 | external |
38-
| MCP4922 | 2 | 12 | 4095 | external |
25+
| Type | Channels | Bits | MaxValue | Voltage reference |
26+
|:--------|:----------:|:------:|:----------:|:-------------------:|
27+
| MCP4801 | 1 | 8 | 255 | internal 2.048 V |
28+
| MCP4802 | 2 | 8 | 255 | internal 2.048 V |
29+
| MCP4811 | 1 | 10 | 1023 | internal 2.048 V |
30+
| MCP4812 | 2 | 10 | 1023 | internal 2.048 V |
31+
| MCP4821 | 1 | 12 | 4095 | internal 2.048 V |
32+
| MCP4822 | 2 | 12 | 4095 | internal 2.048 V |
33+
| MCP4901 | 1 | 8 | 255 | external |
34+
| MCP4902 | 2 | 8 | 255 | external |
35+
| MCP4911 | 1 | 10 | 1023 | external |
36+
| MCP4912 | 2 | 10 | 1023 | external |
37+
| MCP4921 | 1 | 12 | 4095 | external |
38+
| MCP4922 | 2 | 12 | 4095 | external |
3939

4040

4141
The output voltage of the MCP_DAC depends on the voltage supplied,
4242
which is in the range of 2.7V .. 5.5V. Check datasheet for the details.
4343

4444

45-
#### 0.5.0 Breaking change
45+
### 0.5.0 Breaking change
4646

4747
Version 0.5.0 introduced a breaking change to improve handling the SPI dependency.
4848
The user has to call **SPI.begin()** or equivalent before calling **MCP.begin()**.
4949
Optionally the user can provide parameters to the **SPI.begin(...)**
5050

5151

52-
#### 0.4.0 Breaking change
52+
### 0.4.0 Breaking change
5353

5454
The version 0.4.0 has breaking changes in the interface.
5555
The rationale is that the programming environment of the **Arduino ESP32 S3**
@@ -72,24 +72,25 @@ The following library functions have been renamed:
7272

7373

7474

75-
#### 0.3.0 breaking change
75+
### 0.3.0 breaking change
7676

7777
The version 0.3.0 has breaking changes in the interface. The essence is that the
7878
dependency of Wire (ESP32 / RP2040) is removed from the library.
7979
This makes it possible to support the **ESP32-S3** and other processors in the future.
8080
Also it makes the library a bit simpler to maintain.
8181

8282

83-
#### Related
83+
### Related
8484

8585
- https://github.com/RobTillaart/MCP_ADC
86-
- https://github.com/RobTillaart/MAX520
87-
- https://github.com/RobTillaart/MCP_DAC
88-
- https://github.com/RobTillaart/MCP4725
89-
- https://github.com/RobTillaart/DAC8550
90-
- https://github.com/RobTillaart/DAC8551
91-
- https://github.com/RobTillaart/DAC8552
92-
- https://github.com/RobTillaart/DAC8554
86+
- https://github.com/RobTillaart/DAC8550 1 channel, 16 bit
87+
- https://github.com/RobTillaart/DAC8551 1 channel, 16 bit
88+
- https://github.com/RobTillaart/DAC8552 2 channel, 16 bit
89+
- https://github.com/RobTillaart/DAC8554 4 channel, 16 bit
90+
- https://github.com/RobTillaart/MCP_DAC 1, 2 channel, 8,10,12 bit
91+
- https://github.com/RobTillaart/AD5680 (18 bit DAC)
92+
- https://github.com/RobTillaart/MAX520 I2C, 4, 8 channel, 8 bit
93+
- https://github.com/RobTillaart/MCP4725 I2C, 1 channel, 12 bit
9394

9495

9596
## Interface
@@ -98,7 +99,7 @@ Also it makes the library a bit simpler to maintain.
9899
#include "MCP_DAC.h"
99100
```
100101

101-
#### Constructor
102+
### Constructor
102103

103104
- **MCP_DAC(SPIClassRP2040 \*mySPI = &SPI)** Constructor base class for RP2040, hardware SPI.
104105
- **MCP_DAC(SPIClass \*mySPI = &SPI)** Constructor base class other platforms, hardware SPI.
@@ -112,16 +113,20 @@ The select pin is used for device selection in case of multiple SPI devices.
112113
This relates to the number of bits, see table above.
113114

114115

115-
#### Gain
116+
### Gain
116117

117-
- **bool setGain(uint8_t gain = 1)** gain is 1 (default) or 2.
118+
In **reset()** the gain is default set to 1x as that gives the lowest output voltages.
119+
This is the safest option, although datasheet 4.1.1.1 states default = 2x.
120+
121+
- **bool setGain(uint8_t gain = 1)** gain is 1 (default) or 2.
122+
Values of 0 or larger than 2 return false and won't change the current setting.
118123
- **uint8_t getGain()** returns gain set, default 1.
119124

120-
The analog output cannot go beyond the supply voltage.
125+
Note: The analog output cannot go beyond the supply voltage.
121126
So if Vref is connected to 5V, gain = 2 will not output 10 Volts.
122127

123128

124-
#### Write
129+
### Write
125130

126131
- **bool write(uint16_t value, uint8_t channel = 0)** writes value to channel.
127132
Default for channel 0 as that works for the single DAC devices.
@@ -145,14 +150,14 @@ That squeezes the most performance out of it for now.
145150
Code for the other MCP4xxx can be written in same way.
146151

147152

148-
#### Shutdown
153+
### Shutdown
149154

150155
- **void shutDown()** shuts down the device, optional one might need to **triggerLatch()**.
151156
- **bool isActive()** returns false if device is in shutdown mode.
152157
Note: any **write()** operation will set active to true again.
153158

154159

155-
#### Hardware SPI
160+
### Hardware SPI
156161

157162
To be used only if one needs a specific speed.
158163
Check datasheet for details.
@@ -161,7 +166,7 @@ Check datasheet for details.
161166
- **uint32_t getSPIspeed()** returns SPI transfer rate.
162167

163168

164-
#### LDAC
169+
### LDAC
165170

166171
- **void setLatchPin(uint8_t latchPin)** defines the latchPin, this is optional.
167172
The latchPin is used for simultaneous setting a value in both DAC registers.
@@ -172,7 +177,7 @@ Note the latchPin must be the same for all instances that need to be triggered t
172177
Note: pre 0.2.0 versions have the LDAC signal incorrectly inverted.
173178

174179

175-
#### Buffered
180+
### Buffered
176181

177182
**MCP49xxx series only**, see page 20 ==> not functional for MCP48xx series.
178183

@@ -181,7 +186,7 @@ The default mode == false == unbuffered.
181186
- **bool getBufferedMode()** returns set value.
182187

183188

184-
#### Debug
189+
### Debug
185190

186191
- **void reset()** resets internal variables to initial value. (use with care!).
187192
- **bool usesHWSPI()** returns true if HW SPI is used.
@@ -193,7 +198,7 @@ Several functions removed in 0.3.0 as they were too processor specific,
193198
and prevented support for the ESP32-S3.
194199

195200

196-
#### ESP32 connections to MCP4922 (example)
201+
### ESP32 connections to MCP4922 (example)
197202

198203
ESP32 (first series) has **four** SPI peripherals from which two can be used.
199204

@@ -229,14 +234,14 @@ Depending on ESP32 series e.g. HSPI is different, see code snippet below.
229234

230235
## RP2040 specific
231236

232-
#### SPI port selection
237+
### SPI port selection
233238

234239
The SPI Port selections happens in the hardware constructor with e.g. &SPI, &SPI1 etc.
235240
In pre-0.3.0 an experimental feature **void setGPIOpins** was supported to adjust the
236241
hardware pins however this should now be handled by the user outside the library.
237242

238243

239-
#### Pico connections to MCP4922 (example)
244+
### Pico connections to MCP4922 (example)
240245

241246
The RP2040 has **two** SPI peripherals from which two can be used.
242247

libraries/MCP_DAC/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/MCP_DAC"
1717
},
18-
"version": "0.5.1",
18+
"version": "0.5.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/MCP_DAC/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MCP_DAC
2-
version=0.5.1
2+
version=0.5.2
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for Microchip SPI DAC, 8, 10, 12 bit; 1 or 2 channel.

0 commit comments

Comments
 (0)