-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ESP32 #5
Conversation
Thanks for this addition I will do a code check |
It looks good, overal just one remark on code level to make other timing adjustments possible However thinking about it, you need a delay of 400 ns and you use 1000 ns. Is there a way to write the delayNanoseconds() - (drawback) it is CPU clock dependent... something like void delayNanoseconds(uint32_t ns)
{
ns >>= 5; // every loop takes about 32 nanoseconds @ 240 MHz
while (ns--)
{
__asm__ __volatile__ ("nop"); // 1 nop = 1000 /240 ~~ 4ns;
}
} One might need initially get the ESP32 board frequency - Freq = getCpuFrequencyMhz(); |
small test uint32_t start, duration;
void setup()
{
Serial.begin(115200);
for (uint16_t n = 100; n < 3100; n += 100)
{
start = micros();
nanoDelay240(n);
duration = micros() - start;
Serial.print(n);
Serial.print("\t");
Serial.println(duration);
delay(10);
}
}
void loop()
{
}
void nanoDelay240(uint16_t n) // 240 ==> at 240 MHz
{
volatile uint16_t i;
for (i = 0; i < n; ++i);
} one iteration seems to be about 91 nanoseconds so to get a 400ns delay ==> n = 4 or 5 ? Can you test? |
Hello Rob, Thanks for all your suggestions, yes I will test it to see if it's possible to reduce the delay furthermore. |
Wow, looks pretty clean signal to me. |
did a test here and found a version that is Think you should be able to squeeze some nanoseconds of, - which add up to microseconds void nanoDelay(uint16_t n)
{
volatile uint16_t i = n;
while (i--);
} |
Think the PR looks good, will merge after you confirmed (or not) if the new nanoDelay() works better. |
Using new nanoDelay, total time from 133us to 113us
I tried with the new nanoDelay, succeed to gain a little more (113us instead of 133us), it's not working if I go lower. |
had a thought, (think that would keep al signals just limits but could save another 25-30% ? That's my final squeeze :) |
Yes, I've got the same idea, already tried it but unfortunately it's not working and the datasheet is not very explicit for theses timings. |
Thanks @alexthomazo and @RobTillaart! When I tried to use level shifter to solve #3 it didn't work and I blame the fault on the level shifter not working properly. |
Merged into master branch, Thanks @alexthomazo for code, investigating and testing! |
0.2.0 version released |
Thanks 🙂 |
Hello,
After some debugging this afternoon, I managed to have a working version of the library working on an ESP32.
It was not working because the ESP32 is way too faster that the Arduino UNO for setting a pin value so the clock was not within the specs of the TM1637. The datasheet specify a minimum clock pulse of 400ns but the ESP32 done that in ~50ns.
I add a delay after each write in order to comply with the TM1637 specs. The delay is only added for the ESP32 in order to not slow down the write on the Arduino.
related to #3