diff --git a/libraries/TLC5917/CHANGELOG.md b/libraries/TLC5917/CHANGELOG.md index 68be5355..822c25b4 100644 --- a/libraries/TLC5917/CHANGELOG.md +++ b/libraries/TLC5917/CHANGELOG.md @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.2] - 2024-06-02 +- add **TLC5917_NORMAL_MODE** and **TLC5917_SPECIAL_MODE** +- add **uint8_t getMode()** +- rename setCurrentAdjustMode() to **void setSpecialMode()** +- rename **getChannels()** into **channelCount()** (looked like getChannel) +- refactored **writeConfiguration()** +- add **uint8_t getConfiguration()** +- add **bool setGain(bool CM, bool HC, uint8_t CC)** +- add **bool setCurrentGain(float n)** +- add **float getVoltageGain()** +- add **float getCurrentGain()** +- update readme.md +- add / update examples. +- minor edits. + ## [0.1.1] - 2024-06-02 - fix **setChannel()** - rename **getChannels()** to **channelCount()** @@ -13,7 +28,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - update readme.md - minor edits - ## [0.1.0] - 2024-03-17 - initial version diff --git a/libraries/TLC5917/README.md b/libraries/TLC5917/README.md index 96eaf3a3..f8cf1411 100644 --- a/libraries/TLC5917/README.md +++ b/libraries/TLC5917/README.md @@ -18,14 +18,17 @@ TLC5917 is an Arduino library for TLC5917 8-Channel Constant-Current LED Sink Dr **Experimental** -This library allows control over the 8 channels of a TLC5917 device. +The **TLC5917** library allows control over the 8 channels (outputs) of a TLC5917 device. +This library also support more than one device in a daisy chain (see below). -The library allows to set outputs individually or a group in one call. +The library allows to set the channels (outputs) individually or a group in one call. +Furthermore it allows to set a current gain for all devices connected. -The TLC5916 is a derived class that is functional identical to the TLC5917 (for now). -When implementation proceeds this might change. +The **TLC5916** is a derived class that is functional identical to the TLC5917 (for now). +When implementation proceeds this might change, the difference is in support for fetching +the status and error modi. This is not supported by the library -The library is **experimental** and needs more testing with hardware. +The library needs more testing with hardware. Please share your experiences. (Changes of the interface are definitely possible). @@ -33,7 +36,7 @@ Please share your experiences. #### Daisy chaining -This library supports daisy chaining. +This library supports daisy chaining of TLC5917 modules. A constructor takes the number of devices as parameter and an internal buffer is allocated (8 elements per device). This internal buffer is clocked into the devices with **write()**. @@ -65,7 +68,7 @@ The blank pin is explained in more detail below. To be used for multiple devices, typical 2 or more. Defines the pins used for uploading / writing the PWM data to the module. The blank pin is explained in more detail below. -- **~TLC5917()** destructor +- **~TLC5917()** destructor. Frees the allocated memory. #### Base @@ -73,8 +76,7 @@ The blank pin is explained in more detail below. The TLC is disabled by default, as the device has random values in its grey-scale register. One must call **enable()** explicitly. - **int channelCount()** return the amount of channels == 8 x number of devices. -- **int getChannels()** return the amount of channels == 8 x number of devices. -Will be obsolete in 0.2.0. + #### Set/Get channels @@ -85,16 +87,16 @@ The user has to take care the the size of array holds the right amount of bytes. - **bool setAll(bool on)** set all channels on or off. - **bool getChannel(uint8_t channel)** get current state of a channel in the cached buffer. - **void write()** writes the whole buffer (deviceCount x 8 values) to the device(s). -- **void write(int n)** writes a part of the buffer (only **n** values) to the device. +- **void write(int n)** writes a part of the internal buffer (only **n** values) to the device. Typical used to speed up if less than max number e.g. only 17 channels are used and needs to be updated. **experimental, might have side effects** **write()** must be called after setting all values one wants to change. -Doing that per channel is far less efficient if one wants to update multiple +Updating per channel is possible but far less efficient if one has to update multiple channels as fast as possible. -See also **TLC5917_performance.ino** for an indication of time. +See also **TLC5917_performance.ino** for an indication of time needed. #### Blank line TODO CHECK @@ -115,37 +117,61 @@ a separate **enable()** per device you might need to connect the devices "in parallel" instead of "in series" (daisy chained). The blank parameter in the constructor should be set to -1 (out of range value). +It might be possible to use a PWM pin on the OE line to dim the LEDS. +This is neither tested or supported by the library. + #### Configure gain See datasheet page 23 for details. -- **void setCurrentAdjustMode()** -- **void setNormalMode()** -- **void writeConfiguration(uint8_t config)** See page 23 datasheet +- **void setNormalMode()** to send the data for the LEDS. +- **void setSpecialMode()** to configure the gain. + + +The special mode needs to be set for the following functions: + +- **void writeConfiguration(uint8_t configuration)** See page 23 datasheet. +Writes same configuration to all devices. One must call setSpecialMode() first +and setNormalMode() after.. +- **uint8_t getConfiguration()** returns last written configuration +bit mask (from cache). +- **bool setGain(bool CM, bool HC, uint8_t CC)** CC = {0..63} +returns false if CC >= 64 +- **bool setCurrentGain(float n)** n = 0.250 - 3.000 (nicer range). +Over the range 0.250 - 2.989 the max error is 0.0124 +Over the range 2.989 - 3.000 the max error goes up to 0.023 +So except for end of the range the error is (IMHO) small. +Returns false if out of range (n < 0.250 or n > 3.0). +- **float getVoltageGain()** see below (from cache). +- **float getCurrentGain()** see below (from cache). + | bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |:---------:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| -| meaning | CM | HC | CC0 | CC1 | CC2 | CC3 | CC4 | CC5 | +| abbrev | CM | HC | CC0 | CC1 | CC2 | CC3 | CC4 | CC5 | | default | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | -CM limits the output current range. -- High Current Multiplier (CM = 1): 10 mA to 120 mA. -- Low Current Multiplier (CM = 0): 3 mA to 40 mA. +CM == Current Multiplier +- limits the output current range. +- Low (CM = 0): 3 mA to 40 mA. +- High (CM = 1): 10 mA to 120 mA. == CM(0) x 3 VG (voltage gain) = (1 + HC) × (1 + D/64) / 4 -where D = CC0 × 32 + CC1 × 16 + CC2 × 8 + CC3 × 4 + CC4 × 2 + CC5 + +where D = CC0 × 32 + CC1 × 16 + CC2 × 8 + CC3 × 4 + CC4 × 2 + CC5 + D = 0..63 CG (current gain) = VG x pow(3, CM - 1) ``` Default -CG = VG x 3; -VG = 2 x ( 1 + 63/64) / 4 = 127/128 +VG = 2 x ( 1 + 63/64) / 4 = 127/128 +CG = VG x 3 = ~2.977 ``` -TODO test with hardware to understand this in detail. -Actual current depends on Rext (see datasheet). +TODO: test with hardware to understand this in detail. +Actual current depends on Rext == external resistor (see datasheet). ## Performance @@ -159,24 +185,28 @@ See **TLC5917_performance.ino** for an indicative test. - update documentation - buy hardware - - test test test -- get basic functionality running + - test test test #### Should -- get basic functionality running - investigate daisy chaining. (hardware needed). - max CLOCK speed when chained (50% DutyCycle) - what is clock in practice (e.g. an ESP32 240 MHz) +- now the CurrentGain is set to the same value for all devices. + - needs array, one value (uint8_t or float) per device, investigate. #### Could -- add examples -- **void getChannel(uint8_t array)** fill array with current data -- **index operator []** to set channels? +- **index operator []** to get set channels, might be better? +- reading error codes from SDO +#### Wont (unless needed) -#### Wont +- **void getChannel(uint8_t array)** fill an array with current data. +- error handling in special mode + - over-temperature, open-load, short to GND, short to VLED (5917 only). +- investigate if hardware SPI is possible + - which mode? ## Support diff --git a/libraries/TLC5917/TLC5917.cpp b/libraries/TLC5917/TLC5917.cpp index d297b0a2..0b8a0916 100644 --- a/libraries/TLC5917/TLC5917.cpp +++ b/libraries/TLC5917/TLC5917.cpp @@ -1,7 +1,7 @@ // // FILE: TLC5917.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.2 // DATE: 2024-03-17 // PURPOSE: Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. // URL: https://github.com/RobTillaart/TLC5917 @@ -24,7 +24,9 @@ TLC5917::TLC5917(int deviceCount, uint8_t clock, uint8_t data, uint8_t LE, uint8 _data = data; _le = LE; _oe = OE; + _mode = TLC5917_NORMAL_MODE; _buffer = (uint8_t *) calloc(_channelCount, sizeof(uint8_t)); + _configuration = 0xFF; // page 23 datasheet } @@ -54,17 +56,13 @@ int TLC5917::channelCount() return _channelCount; } -int TLC5917::getChannels() // OBSOLETE -{ - return _channelCount; -} - bool TLC5917::setChannel(uint8_t channel, bool on) { if (channel >= _channelCount) return false; - if (on) _buffer[channel / 8] |= (1 << (channel & 0x07)); - else _buffer[channel / 8] &= ~(1 << (channel & 0x07)); + uint8_t mask = 1 << (channel & 0x07); + if (on) _buffer[channel / 8] |= mask; + else _buffer[channel / 8] &= ~mask; return true; } @@ -93,7 +91,8 @@ bool TLC5917::setAll(bool on) bool TLC5917::getChannel(uint8_t channel) { if (channel >= _channelCount) return false; - return (_buffer[channel / 8] & (1 << (channel & 0x07))) > 0; + uint8_t mask = 1 << (channel & 0x07); + return (_buffer[channel / 8] & mask) > 0; } @@ -114,6 +113,7 @@ void TLC5917::write(int chan) if (chan > _channelCount) chan = _channelCount; if (chan < 0) return; + #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) // register level optimized AVR @@ -131,19 +131,18 @@ void TLC5917::write(int chan) { for (uint8_t mask = 0x80; mask; mask >>= 1) { - *_clockRegister &= cbmask2; if (_buffer[channel] & mask) { - *_dataOutRegister |= outmask1; + *_dataOutRegister |= outmask1; // digitalWrite(_dat, HIGH); } else { - *_dataOutRegister &= outmask2; + *_dataOutRegister &= outmask2; // digitalWrite(_dat, LOW); } - *_clockRegister |= cbmask1; + *_clockRegister |= cbmask1; // digitalWrite(_clk, HIGH); + *_clockRegister &= cbmask2; // digitalWrite(_clk, LOW); } } - *_clockRegister &= cbmask2; #else @@ -157,12 +156,11 @@ void TLC5917::write(int chan) { for (uint8_t mask = 0x80; mask; mask >>= 1) { - digitalWrite(_clk, LOW); digitalWrite(_dat, _buffer[channel] & mask ? HIGH : LOW); digitalWrite(_clk, HIGH); + digitalWrite(_clk, LOW); } } - digitalWrite(_clk, LOW); #endif @@ -201,7 +199,7 @@ bool TLC5917::isEnabled() // NOT OPTIMIZED // // Page 19 -void TLC5917::setCurrentAdjustMode() +void TLC5917::setSpecialMode() { digitalWrite(_le, LOW); digitalWrite(_oe, HIGH); @@ -224,6 +222,8 @@ void TLC5917::setCurrentAdjustMode() digitalWrite(_le, LOW); digitalWrite(_clock, HIGH); digitalWrite(_clock, LOW); + + _mode = TLC5917_SPECIAL_MODE; } @@ -248,34 +248,117 @@ void TLC5917::setNormalMode() digitalWrite(_clock, HIGH); digitalWrite(_clock, LOW); + + _mode = TLC5917_NORMAL_MODE; } -void TLC5917::writeConfiguration(uint8_t config) +uint8_t TLC5917::getMode() +{ + return _mode; +} + + +// 9.4.3 Writing Configuration Code in Special Mode +void TLC5917::writeConfiguration(uint8_t configuration) { uint8_t _clk = _clock; uint8_t _dat = _data; - uint8_t _devices = _channelCount/8; + uint8_t _devices = _channelCount / 8; // write same configuration to all devices for (int i = 0; i < _devices; i++) { - for (uint8_t mask = 0x80; mask; mask >>= 1) + // handle bit 7- 1 + for (uint8_t mask = 0x80; mask > 1; mask >>= 1) { - digitalWrite(_clk, LOW); - digitalWrite(_dat, config & mask ? HIGH : LOW); + digitalWrite(_dat, configuration & mask ? HIGH : LOW); digitalWrite(_clk, HIGH); + digitalWrite(_clk, LOW); } + // bit 0 should have an LE pulse + digitalWrite(_le, HIGH); + digitalWrite(_dat, configuration & 0x01 ? HIGH : LOW); + digitalWrite(_clk, HIGH); digitalWrite(_clk, LOW); + digitalWrite(_le, LOW); } - - // pulse latch to hold the signals in configuration register. - // not exactly like Page 18 figure 13. - digitalWrite(_le, HIGH); - digitalWrite(_le, LOW); + _configuration = configuration; } +uint8_t TLC5917::getConfiguration() +{ + return _configuration; +} + + +// Page 23 +bool TLC5917::setGain(bool CM, bool HC, uint8_t CC) +{ + if (CC > 63) return false; + _configuration = CC; + if (CM) _configuration |= 0x80; + if (HC) _configuration |= 0x40; + writeConfiguration(_configuration); + return true; +} + + +float TLC5917::getVoltageGain() +{ + uint8_t CC = _configuration & 0x3F; // 0..63 + uint8_t HC = (_configuration & 0x40) ? 1 : 0; + float VG = (1.0 + HC) * (1.0 + CC * 0.015625) / 4; // 0.015625 = 1/64 + return VG; +} + + +float TLC5917::getCurrentGain() +{ + float CG = getVoltageGain(); + // uint8_t CM = _configuration & 0x80; + if (_configuration & 0x80) CG *= 3; + return CG; +} + + +bool TLC5917::setCurrentGain(float n) +{ + if (n < 0.250) return false; + if (n > 3.000) return false; + + uint8_t CM = 0; + uint8_t HC = 0; + uint8_t CC = 0; + + // n == (1 + HC) × (1 + D/64) / 4 * pow(3, CM - 1); + // handle CM=1: values 1.0 - 2.977 == 150 - 255 + // note values 128 - 149 not used (twice in table) + if (n >= 1.0) + { + CM = 1; + n /= 3; + } + // n == (1 + HC) × (1 + D/64) / 4 + // handle HC=1: values 0.5 - 1.0 == 64 - 127 + if (n >= 0.5) + { + HC = 1; + n /= 2; + } + + // n == (1 + CC/64)/4; + // values 0.25 - 0.5 + n *= 4; + n -= 1; + if (n < 0) n = 0; + CC = round(n * 64); + if (CC >= 64) CC = 63; // truncate at top. + setGain(CM, HC, CC); + return true; +} + ///////////////////////////////////////////////////////////// // diff --git a/libraries/TLC5917/TLC5917.h b/libraries/TLC5917/TLC5917.h index 889d1627..5fa030f0 100644 --- a/libraries/TLC5917/TLC5917.h +++ b/libraries/TLC5917/TLC5917.h @@ -2,13 +2,13 @@ // // FILE: TLC5917.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 +// VERSION: 0.1.2 // DATE: 2024-03-17 // PURPOSE: Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers. // URL: https://github.com/RobTillaart/TLC5917 -#define TLC5917_LIB_VERSION (F("0.1.1")) +#define TLC5917_LIB_VERSION (F("0.1.2")) #include "Arduino.h" @@ -28,8 +28,11 @@ #define OUTPUT 0 */ -#define TLC5917_OK 0x0000 -#define TLC5917_CHANNEL_ERROR 0xFFFF +#define TLC5917_OK 0x0000 +#define TLC5917_CHANNEL_ERROR 0xFFFF + +#define TLC5917_NORMAL_MODE 0x00 +#define TLC5917_SPECIAL_MODE 0x01 class TLC5917 @@ -42,38 +45,50 @@ public: virtual ~TLC5917(); bool begin(); - int channelCount(); // replaces getChannels which looks too much like getChannel. - int getChannels(); // will be obsolete in 0.2.0 + int channelCount(); bool setChannel(uint8_t channel, bool on); - bool setChannel(uint8_t * array); // size must be deviceCount. + // size array must be equal or larger than deviceCount. + bool setChannel(uint8_t * array); bool setAll(bool on); bool getChannel(uint8_t channel); - // write the buffer to the TLC5917 device(s). + // write the buffer to the TLC5917 device(s). void write(int n); void write(); - // control the blank (OE) line. + // control the blank (OE) line. void enable(); void disable(); bool isEnabled(); // returns status - // configuration mode - // TODO test if this works for single device. - // TODO test if this works for cascaded devices. - void setCurrentAdjustMode(); + // GAIN configuration mode + // TODO test if this works for single device. + // TODO test if this works for cascaded devices. + void setSpecialMode(); void setNormalMode(); - void writeConfiguration(uint8_t config); + uint8_t getMode(); + + // writes the same configuration to all devices. + void writeConfiguration(uint8_t configuration); + uint8_t getConfiguration(); + bool setGain(bool CM, bool HC, uint8_t CC); // CC 0..63 + bool setCurrentGain(float n); // n = 0.250 - 3.000 + float getVoltageGain(); + float getCurrentGain(); protected: int _channelCount; uint8_t * _buffer; + uint8_t _clock; uint8_t _data; uint8_t _le; // latch enable uint8_t _oe; // output enable + + uint8_t _mode; + uint8_t _configuration; }; diff --git a/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino index c884de49..67918539 100644 --- a/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino +++ b/libraries/TLC5917/examples/TLC5917_NightRider/TLC5917_NightRider.ino @@ -1,7 +1,7 @@ // // FILE: TLC5917_NightRider.ino // AUTHOR: Rob Tillaart -// PURPOSE: demo +// PURPOSE: demo running leds. // URL: https://github.com/RobTillaart/TLC5917 @@ -24,7 +24,11 @@ void setup() Serial.print("TLC5917_LIB_VERSION: \t"); Serial.println(TLC5917_LIB_VERSION); - tlc.begin(); + if (tlc.begin() == false) + { + Serial.println("error"); + while (1); + } tlc.enable(); } diff --git a/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino index 4f76a2fa..54456d64 100644 --- a/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino +++ b/libraries/TLC5917/examples/TLC5917_demo/TLC5917_demo.ino @@ -1,7 +1,7 @@ // // FILE: TLC5917_demo.ino // AUTHOR: Rob Tillaart -// PURPOSE: demo +// PURPOSE: demo basic usage // URL: https://github.com/RobTillaart/TLC5917 diff --git a/libraries/TLC5917/examples/TLC5917_demo_gain/TLC5917_demo_gain.ino b/libraries/TLC5917/examples/TLC5917_demo_gain/TLC5917_demo_gain.ino new file mode 100644 index 00000000..3578f51a --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_demo_gain/TLC5917_demo_gain.ino @@ -0,0 +1,87 @@ +// +// FILE: TLC5917_demo_gain.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo writeConfiguration() to set gain. +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + + +const int DEVICES = 1; +const int CLOCK = 13; +const int DATA = 12; +const int LE = 11; +const int OE = 10; + +TLC5917 tlc(DEVICES, CLOCK, DATA, LE, OE); + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + Serial.println(); + + if (tlc.begin() == false) + { + Serial.println("error"); + while (1); + } + + Serial.print("Channels: "); + Serial.println(tlc.channelCount()); + + // set all leds ON + tlc.enable(); + for (int ch = 0; ch < tlc.channelCount(); ch++) + { + tlc.setChannel(ch, true); + } + tlc.write(); + + Serial.print("MODE:\t"); + Serial.println(tlc.getMode()); + tlc.setSpecialMode(); + Serial.print("MODE:\t"); + Serial.println(tlc.getMode()); + uint32_t start = millis(); + for (int conf = 0; conf < 256; conf++) + { + tlc.writeConfiguration(conf); + delay(100); + } + uint32_t stop = millis(); + tlc.setNormalMode(); + Serial.print("TIME:\t"); + Serial.println(stop - start); + Serial.print("MODE:\t"); + Serial.println(tlc.getMode()); + + Serial.println("\ndone..."); + + tlc.setSpecialMode(); +} + + +void loop() +{ + // increase gain + for (int conf = 0; conf < 256; conf++) + { + tlc.writeConfiguration(conf); + delay(10); + } + // decrease gain + for (int conf = 255; conf > 0; conf--) + { + tlc.writeConfiguration(conf); + delay(10); + } + +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.ino b/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.ino new file mode 100644 index 00000000..0018ac92 --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.ino @@ -0,0 +1,63 @@ +// +// FILE: TLC5917_gain_table.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo getCOnfiguration and getXXXGain() +// creates a table e.g. for Excel or plotter. +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + + +const int DEVICES = 1; +const int CLOCK = 13; +const int DATA = 12; +const int LE = 11; +const int OE = 10; + +TLC5917 tlc(DEVICES, CLOCK, DATA, LE, OE); + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + Serial.println(); + + if (tlc.begin() == false) + { + Serial.println("error"); + while (1); + } + + tlc.setSpecialMode(); + + Serial.println("\tCONF\tVGAIN\tCGAIN"); + for (int conf = 0; conf <= 255; conf++) + { + if (conf % 16 == 0) Serial.println(); + + tlc.writeConfiguration(conf); + Serial.print("\t"); + // comment next line for nice plotter view + Serial.print(tlc.getConfiguration()); + Serial.print("\t"); + Serial.print(tlc.getVoltageGain(), 3); + Serial.print("\t"); + Serial.println(tlc.getCurrentGain(), 3); + } + Serial.println(); + + tlc.setNormalMode(); + Serial.println("\ndone..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.txt b/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.txt new file mode 100644 index 00000000..713911e1 --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_gain_table/TLC5917_gain_table.txt @@ -0,0 +1,280 @@ +TLC5917_gain_table.ino +TLC5917_LIB_VERSION: 0.1.2 + + + CONF VGAIN CGAIN + + 0 0.250 0.250 + 1 0.254 0.254 + 2 0.258 0.258 + 3 0.262 0.262 + 4 0.266 0.266 + 5 0.270 0.270 + 6 0.273 0.273 + 7 0.277 0.277 + 8 0.281 0.281 + 9 0.285 0.285 + 10 0.289 0.289 + 11 0.293 0.293 + 12 0.297 0.297 + 13 0.301 0.301 + 14 0.305 0.305 + 15 0.309 0.309 + + 16 0.312 0.312 + 17 0.316 0.316 + 18 0.320 0.320 + 19 0.324 0.324 + 20 0.328 0.328 + 21 0.332 0.332 + 22 0.336 0.336 + 23 0.340 0.340 + 24 0.344 0.344 + 25 0.348 0.348 + 26 0.352 0.352 + 27 0.355 0.355 + 28 0.359 0.359 + 29 0.363 0.363 + 30 0.367 0.367 + 31 0.371 0.371 + + 32 0.375 0.375 + 33 0.379 0.379 + 34 0.383 0.383 + 35 0.387 0.387 + 36 0.391 0.391 + 37 0.395 0.395 + 38 0.398 0.398 + 39 0.402 0.402 + 40 0.406 0.406 + 41 0.410 0.410 + 42 0.414 0.414 + 43 0.418 0.418 + 44 0.422 0.422 + 45 0.426 0.426 + 46 0.430 0.430 + 47 0.434 0.434 + + 48 0.438 0.438 + 49 0.441 0.441 + 50 0.445 0.445 + 51 0.449 0.449 + 52 0.453 0.453 + 53 0.457 0.457 + 54 0.461 0.461 + 55 0.465 0.465 + 56 0.469 0.469 + 57 0.473 0.473 + 58 0.477 0.477 + 59 0.480 0.480 + 60 0.484 0.484 + 61 0.488 0.488 + 62 0.492 0.492 + 63 0.496 0.496 + + 64 0.500 0.500 + 65 0.508 0.508 + 66 0.516 0.516 + 67 0.523 0.523 + 68 0.531 0.531 + 69 0.539 0.539 + 70 0.547 0.547 + 71 0.555 0.555 + 72 0.563 0.563 + 73 0.570 0.570 + 74 0.578 0.578 + 75 0.586 0.586 + 76 0.594 0.594 + 77 0.602 0.602 + 78 0.609 0.609 + 79 0.617 0.617 + + 80 0.625 0.625 + 81 0.633 0.633 + 82 0.641 0.641 + 83 0.648 0.648 + 84 0.656 0.656 + 85 0.664 0.664 + 86 0.672 0.672 + 87 0.680 0.680 + 88 0.688 0.688 + 89 0.695 0.695 + 90 0.703 0.703 + 91 0.711 0.711 + 92 0.719 0.719 + 93 0.727 0.727 + 94 0.734 0.734 + 95 0.742 0.742 + + 96 0.750 0.750 + 97 0.758 0.758 + 98 0.766 0.766 + 99 0.773 0.773 + 100 0.781 0.781 + 101 0.789 0.789 + 102 0.797 0.797 + 103 0.805 0.805 + 104 0.813 0.813 + 105 0.820 0.820 + 106 0.828 0.828 + 107 0.836 0.836 + 108 0.844 0.844 + 109 0.852 0.852 + 110 0.859 0.859 + 111 0.867 0.867 + + 112 0.875 0.875 + 113 0.883 0.883 + 114 0.891 0.891 + 115 0.898 0.898 + 116 0.906 0.906 + 117 0.914 0.914 + 118 0.922 0.922 + 119 0.930 0.930 + 120 0.938 0.938 + 121 0.945 0.945 + 122 0.953 0.953 + 123 0.961 0.961 + 124 0.969 0.969 + 125 0.977 0.977 + 126 0.984 0.984 + 127 0.992 0.992 + + 128 0.250 0.750 + 129 0.254 0.762 + 130 0.258 0.773 + 131 0.262 0.785 + 132 0.266 0.797 + 133 0.270 0.809 + 134 0.273 0.820 + 135 0.277 0.832 + 136 0.281 0.844 + 137 0.285 0.855 + 138 0.289 0.867 + 139 0.293 0.879 + 140 0.297 0.891 + 141 0.301 0.902 + 142 0.305 0.914 + 143 0.309 0.926 + + 144 0.312 0.938 + 145 0.316 0.949 + 146 0.320 0.961 + 147 0.324 0.973 + 148 0.328 0.984 + 149 0.332 0.996 + 150 0.336 1.008 + 151 0.340 1.020 + 152 0.344 1.031 + 153 0.348 1.043 + 154 0.352 1.055 + 155 0.355 1.066 + 156 0.359 1.078 + 157 0.363 1.090 + 158 0.367 1.102 + 159 0.371 1.113 + + 160 0.375 1.125 + 161 0.379 1.137 + 162 0.383 1.148 + 163 0.387 1.160 + 164 0.391 1.172 + 165 0.395 1.184 + 166 0.398 1.195 + 167 0.402 1.207 + 168 0.406 1.219 + 169 0.410 1.230 + 170 0.414 1.242 + 171 0.418 1.254 + 172 0.422 1.266 + 173 0.426 1.277 + 174 0.430 1.289 + 175 0.434 1.301 + + 176 0.438 1.312 + 177 0.441 1.324 + 178 0.445 1.336 + 179 0.449 1.348 + 180 0.453 1.359 + 181 0.457 1.371 + 182 0.461 1.383 + 183 0.465 1.395 + 184 0.469 1.406 + 185 0.473 1.418 + 186 0.477 1.430 + 187 0.480 1.441 + 188 0.484 1.453 + 189 0.488 1.465 + 190 0.492 1.477 + 191 0.496 1.488 + + 192 0.500 1.500 + 193 0.508 1.523 + 194 0.516 1.547 + 195 0.523 1.570 + 196 0.531 1.594 + 197 0.539 1.617 + 198 0.547 1.641 + 199 0.555 1.664 + 200 0.563 1.687 + 201 0.570 1.711 + 202 0.578 1.734 + 203 0.586 1.758 + 204 0.594 1.781 + 205 0.602 1.805 + 206 0.609 1.828 + 207 0.617 1.852 + + 208 0.625 1.875 + 209 0.633 1.898 + 210 0.641 1.922 + 211 0.648 1.945 + 212 0.656 1.969 + 213 0.664 1.992 + 214 0.672 2.016 + 215 0.680 2.039 + 216 0.688 2.062 + 217 0.695 2.086 + 218 0.703 2.109 + 219 0.711 2.133 + 220 0.719 2.156 + 221 0.727 2.180 + 222 0.734 2.203 + 223 0.742 2.227 + + 224 0.750 2.250 + 225 0.758 2.273 + 226 0.766 2.297 + 227 0.773 2.320 + 228 0.781 2.344 + 229 0.789 2.367 + 230 0.797 2.391 + 231 0.805 2.414 + 232 0.813 2.437 + 233 0.820 2.461 + 234 0.828 2.484 + 235 0.836 2.508 + 236 0.844 2.531 + 237 0.852 2.555 + 238 0.859 2.578 + 239 0.867 2.602 + + 240 0.875 2.625 + 241 0.883 2.648 + 242 0.891 2.672 + 243 0.898 2.695 + 244 0.906 2.719 + 245 0.914 2.742 + 246 0.922 2.766 + 247 0.930 2.789 + 248 0.938 2.812 + 249 0.945 2.836 + 250 0.953 2.859 + 251 0.961 2.883 + 252 0.969 2.906 + 253 0.977 2.930 + 254 0.984 2.953 + 255 0.992 2.977 + + +done... diff --git a/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.2.txt b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.2.txt new file mode 100644 index 00000000..63ded1b5 --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_performance/performance_0.1.2.txt @@ -0,0 +1,25 @@ +Arduino UNO +IDE: 1.8.19 + +(AVR optimized write() on UNO) +TLC5917_performance\TLC5917_performance.ino +TLC5917_LIB_VERSION: 0.1.2 +Channels: 800 +SETCHANNEL TRUE: 2572 +SETCHANNEL FALSE: 2848 +SETALL TRUE: 232 +WRITE: 14304 + +Done... + + +(default write() on UNO for reference) +TLC5917_LIB_VERSION: 0.1.2 +Channels: 800 +SETCHANNEL TRUE: 2572 +SETCHANNEL FALSE: 2848 +SETALL TRUE: 232 +WRITE: 75364 + +Done... + diff --git a/libraries/TLC5917/examples/TLC5917_test_setCurrentGain/TLC5917_test_setCurrentGain.ino b/libraries/TLC5917/examples/TLC5917_test_setCurrentGain/TLC5917_test_setCurrentGain.ino new file mode 100644 index 00000000..a48a4ce6 --- /dev/null +++ b/libraries/TLC5917/examples/TLC5917_test_setCurrentGain/TLC5917_test_setCurrentGain.ino @@ -0,0 +1,71 @@ +// +// FILE: TLC5917_test_setCurrentGain.ino +// AUTHOR: Rob Tillaart +// PURPOSE: test setCurrentGain function. +// URL: https://github.com/RobTillaart/TLC5917 + + +#include "TLC5917.h" + + +const int DEVICES = 1; +const int CLOCK = 13; +const int DATA = 12; +const int LE = 11; +const int OE = 10; + +TLC5917 tlc(DEVICES, CLOCK, DATA, LE, OE); + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TLC5917_LIB_VERSION: \t"); + Serial.println(TLC5917_LIB_VERSION); + Serial.println(); + + if (tlc.begin() == false) + { + Serial.println("error"); + while (1); + } + + tlc.setSpecialMode(); + float averageError = 0; + float maxError = 0; + // above 2.989 the abs error goes beyond 0.012 + // at 3.000 the error is 0.023 + for (float gain = 0.250; gain <= 2.989; gain += 0.001) + { + tlc.setCurrentGain(gain); + float tmp = tlc.getCurrentGain(); + float diff = gain - tmp; + Serial.print(gain, 3); + Serial.print("\t"); + Serial.print(tmp, 3); + Serial.print("\t"); + Serial.print(diff, 3); + Serial.println(); + + averageError += diff; + if (maxError < abs(diff)) maxError = abs(diff); + } + + Serial.println(); + Serial.print("AVGERR: \t"); + Serial.println(averageError, 4); + Serial.print("MAXERR: \t"); + Serial.println(maxError, 4); + + tlc.setNormalMode(); + Serial.println("\ndone..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TLC5917/keywords.txt b/libraries/TLC5917/keywords.txt index 3fe82b57..2710192e 100644 --- a/libraries/TLC5917/keywords.txt +++ b/libraries/TLC5917/keywords.txt @@ -20,9 +20,14 @@ enable KEYWORD2 disable KEYWORD2 isEnabled KEYWORD2 -setCurrentAdjustMode KEYWORD2 +setSpecialMode KEYWORD2 setNormalMode KEYWORD2 writeConfiguration KEYWORD2 +getConfiguration KEYWORD2 +setGain KEYWORD2 +setCurrentGain KEYWORD2 +getVoltageGain KEYWORD2 +getCurrentGain KEYWORD2 # Instances (KEYWORD2) @@ -34,3 +39,5 @@ TLC5917_LIB_VERSION LITERAL1 TLC5917_OK LITERAL1 TLC5917_CHANNEL_ERROR LITERAL1 +TLC5917_NORMAL_MODE LITERAL1 +TLC5917_SPECIAL_MODE LITERAL1 diff --git a/libraries/TLC5917/library.json b/libraries/TLC5917/library.json index b1acf800..61dd6a91 100644 --- a/libraries/TLC5917/library.json +++ b/libraries/TLC5917/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TLC5917.git" }, - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/TLC5917/library.properties b/libraries/TLC5917/library.properties index b4f78b1a..490153a9 100644 --- a/libraries/TLC5917/library.properties +++ b/libraries/TLC5917/library.properties @@ -1,5 +1,5 @@ name=TLC5917 -version=0.1.1 +version=0.1.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for TLC5917 8-Channel Constant-Current LED Sink Drivers.