TM1638 & pwm compatibility issue

Status
Not open for further replies.

txinto

Member
Hello!

If I run this code:

Code:
#include <TM1638.h>

// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(8, 9, 10);

void setup() {
  // display a hexadecimal number and set the left 4 dots
  module.setDisplayToHexNumber(0x1234ABCD, 0xF0);
}

void loop() {
  byte keys = module.getButtons();

  // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
  module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));
}

everything works as a charm. I press a button and the the correstpoding led lights on.

But if I simply introduce an analogWriteFrequency() function on the setup, then only the first button is read.

Code:
#include <TM1638.h>

// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(8, 9, 10);

void setup() {
  // display a hexadecimal number and set the left 4 dots
  module.setDisplayToHexNumber(0x1234ABCD, 0xF0);
  analogWriteFrequency(6, 375000);
}

void loop() {
  byte keys = module.getButtons();

  // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
  module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));
}

Is there a compatibility issue? Anything is missing?
I've used the serial monitor to check that the problem is in button reading, not in the leds control.

I've also tried to use different PWM pins, corresponding to the different FMTx of he Teensy v3.2. Same with several different frequencies.

Best regards. Thank you in advance.
 
analogWriteFrequency will affect all 8 channels of the FTM0 flex timer by modifying its modulus value. That is documented on the Teensy Website about PWM.
Thus if you can't put your display on different pins, try generating your PWM on pin 3 or 4 which use the FTM1.
 
Hi, thanks for your fast reply.

Unfortunately, I included changing the PWM to pin 3 into my previous tests, with no success.

I've also tried to use different PWM pins, corresponding to the different FMTx of he Teensy v3.2. Same with several different frequencies.

I have teste it again now, to be sure, but the issue occurs.

See you!
 
An update. Setting the PWM resolution also causes the issue to appear.

That is very strange. analogrWriteRes() alters no hardware IO registers. it just does
analog_write_res = bits;

I downloaded https://github.com/rjbatista/tm1638-library and compiled your sample sketch. i don't have the 1638 hardware, but sketch "ran" with no connected pins. The library just uses digital Write/Read to clock the data, so i don't see how PWM settings have any effect. library does use the old style digitalWrite of an INPUT pin to effect INPUT_PULLUP.



what version of IDE/teensyduino are you running? do you have a photo of your hardware configuration?
 
Last edited:
That is very strange. analogrWriteRes() alters no hardware IO registers. it just does
analog_write_res = bits;

I downloaded https://github.com/rjbatista/tm1638-library and compiled your sample sketch. i don't have the 1638 hardware, but sketch "ran" with no connected pins. The library just uses digital Write/Read to clock the data, so i don't see how PWM settings have any effect. library does use the old style digitalWrite of an INPUT pin to effect INPUT_PULLUP.



what version of IDE/teensyduino are you running? do you have a photo of your hardware configuration?

Hello, I've located the issue. It is in the toolchain.

This setup does not work:

- Windows machine
- Teensy v3.1
- Arduino v1.8.1
- TeensyDuino v1.35

This setup DOES work:
- Windows machine
- Teensy v3.1
- Arduino v1.6.8
- TeensyDuino v1.28

I'll try to send to you the two hex files.

Best regards, and thank you.
 
Hello again. I am going progressively from TeensyDuino 1.28 to TeensyDuino1.35.
The target is to see when the issue appeared, to give you more information about it.

Begin:

The base arduino IDE is v1.6.8

- v1.29: OK.
- v1.30: OK.

We need to switch to IDE v1.6.9

- v1.31: OK.
- v1.32: OK.
- v1.33: OK.
- v1.34: NOK.
- v1.35: NOK.

End:

So, the issue appears between Teensyduino v1.33 and v1.34. I'm quite sure the Arduino IDE is not affecting.

I'll try to downgrade my system to the v1.33 version, with the newest IDE possible (v1.6.13)

Best regards.
 
Hello again. I can bring more information for you.

I am developing a project and, until today, using the Arduino IDE v1.6.13 + TeensyDuino v1.33 has worked fine. But today I have activated a call no a new function and I've lost the functionality of the three last buttons of the TM1638.

The first check I did was to empty the function, and the issue is still present. This means that calling an empty function is causing it to appear.

It seems to be a problem of the "overflowing type". I don't know if the overflowing thing is the memory, the stack, the time....

After that, I have compiled it using platformio and there was no issue!

I've prepared a project that can be compiled under platformio and under arduino, that shows exactly when the issue is appearing. It also includes the hex files generated by both systems. I've tried to compare the two hex files, but they are completely diferent.

http://gatatac.org/attachments/download/232/tm1638issue.zip

The function that is unveiling the problem is prj_output.cpp/prjOutput(), that is called from src.ino.

If you simply delete the call in src.ino, there is no issue.
If you add the call, issue appears.
If you delete the function contents in prj_output.c but still call the function from src.ino, the issue appears.

You can check the call here:

https://github.com/gatATAC/lin1d/blob/1adc272b7771bb9b1382fbcceefcaf3f677504c1/src/src.ino#L230

And the function is here:

https://github.com/gatATAC/lin1d/bl...82fbcceefcaf3f677504c1/src/prj_output.cpp#L69

Hope this helps. I've continue using platformio, but I'll check the issue after any new TeensyDuino release.

Best regards and thank you.
 
Status
Not open for further replies.
Back
Top