Skip to content

Commit

Permalink
V 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Nov 17, 2021
1 parent 564fb5e commit 787292a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ Connections to MCU:
2. GPIO = CLK = Clock
3. GPIO = DIO = Data input / output
4. GND
5. VCC 5V.

This device is 5V if using 3.3V MCU, level shift.
5. VCC

This library supports three variants of the TM1638, which for purposes of this documentation,
will be named Model 1 ,Model 2 and Model 3.
Expand Down Expand Up @@ -215,17 +213,13 @@ Object, set the fourth parameter "swap_nibbles" to True, The default is false.

This library uses a software SPI-like protocol and may not work fully on
micro-controllers running at a very high frequency, without some adjustments to timing.
Its a SPI-like interface with a single bidirectional data wire DIO.
It is a SPI-like interface with a single bidirectional data wire DIO.
The TM1638 is basically a slow SPI device (< 500kHz) in DIO mode. The clock uses the equivalent of SPI mode 3 (normally high, clocks data on the rising edge). The problem is that the native Arduino shiftIn()/shiftOut() wire functions are simply too fast for this device (technically the clock signalling for the TM1638 is inverted but as it triggers on a rising edge still it is tolerant of that).
To make this work with fast devices, the shift clocking is slowed with a small delay (on the order of a microsecond).

HighFreqshiftin function:

As of version 1.6 a new parameter *(_HIGH_FREQ)* has been introduced to constructor it is false by default. Set to true for high frequency MCU ~> 100Mhz. This should fix the issue of HF MCU not reading buttons correctly(ESP-Xs). The High_Freq parameter causes a custom shift-in function to be used.
The delay in this function is fixed at 1.
If the user is still having issues with high frequency MCU.
It may be necessary in some cases to increase delay to 2 or more according to some feedback received by email. This delay will be user adjusted in future version at the initialise stage.
Also in the ,function, It might help to move the digitalWrite(clockPin, HIGH) and its associated delay to the top of the for loop it is in, this is where it is in the "official" arduino shiftin function source code.
As of version 1.6 a new parameter *(_HIGH_FREQ)* has been introduced to constructor it is false by default. Set to true for high frequency MCU ~> 100Mhz. This should fix the issue of HF MCU not reading buttons correctly(ESP-Xs). The High_Freq parameter causes a custom shift-in function to be used. The delay in this function is fixed at 1 uS, it can be changed manually by adjusted the defines in common header file.

The Teensy results have been sent in by email, I don't have these MCU's them at time of writing.

Expand All @@ -238,7 +232,7 @@ The Teensy results have been sent in by email, I don't have these MCU's them at
| ESP8266 | 160Mhz | Working |
| ESP 32 | 240 MHz | Working, with high_freq set to true |
| Teensy 4.0| 150Mhz | Working model 1, no Data rest of models |
| Teensy 4.0| 396Mhz | Not working on model1 , no Data rest of models |
| Teensy 4.0| 396Mhz | Not working on m1 pre v1.6, no data after, no Data rest of models |

*Note C* : Driving multiple displays.

Expand Down
3 changes: 3 additions & 0 deletions extra/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
* Example file added by [wunderbaum](https://github.com/wunderbaum) see pull request 3.
* Optimisations to example files.

* Version 1.8.0 November 2021
* Minor update
* Some users (two) have reported the high frequency shiftIn function does not work fully with some micro-controller boards at high frequency(ESP32 240Mhz) and the fix is minor adjustment to sequence in said function. Never saw the issue in my testing. The change makes the function sequence similar to the official Arduino shiftIn function structure in the Arduino Core (wiring.shift.c) , See issue 16 on github for full details.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TM1638plus
version=1.7.0
version=1.8.0
author=Gavin Lyons <glyons66@hotmail.com>
maintainer=Gavin Lyons <glyons66@hotmail.com>
sentence=TM1638plus is an Arduino library to control TM1638 seven segment modules.
Expand Down
12 changes: 7 additions & 5 deletions src/TM1638plus_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ uint8_t TM1638plus_common::HighFreqshiftin(uint8_t dataPin, uint8_t clockPin, u
uint8_t i = 0;

for(i = 0; i < 8; ++i) {

digitalWrite(clockPin, HIGH);
delayMicroseconds(TM_HFIN_DELAY);

if(bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (7 - i);

digitalWrite(clockPin, HIGH);
delayMicroseconds(1);
digitalWrite(clockPin, LOW);
delayMicroseconds(1);
delayMicroseconds(TM_HFIN_DELAY);
}
return value;
}
Expand All @@ -45,8 +47,8 @@ void TM1638plus_common::HighFreqshiftOut(uint8_t dataPin, uint8_t clockPin, uint
digitalWrite(dataPin, !!(val & (1 << (7 - i))));

digitalWrite(clockPin, HIGH);
delayMicroseconds(1);
delayMicroseconds(TM_HFOUT_DELAY);
digitalWrite(clockPin, LOW);
delayMicroseconds(1);
delayMicroseconds(TM_HFOUT_DELAY);
}
}
3 changes: 3 additions & 0 deletions src/TM1638plus_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define TM_GREEN_LED 0x01 // Model 3
#define TM_OFF_LED 0x00

#define TM_HFIN_DELAY 1 // uS Delay used by shiftIn function for High-freq MCU
#define TM_HFOUT_DELAY 1 // uS Delay used by shiftOut function for High-freq MCU

// font , map of ASCII values/table to 7-segment, offset to position 32.
const PROGMEM unsigned char SevenSeg[] = {
0x00, /* (space) */
Expand Down

0 comments on commit 787292a

Please sign in to comment.