Blink example changes freequency?

Status
Not open for further replies.

Kukulkan

Member
Hi,

I just installed everything for Teensy 3.1 on my Linux (Kubuntu). I use the makefile from Sudar (https://github.com/sudar/Arduino-Makefile) and finally managed to upload using teensy_loader_cli like this:

Code:
teensy_loader_cli -mmcu=mk20dx256 -s -v $(OUT_PATH)Test.hex

Ok, now I successfully compiled this script:

Code:
const int ledPin = 13;

void setup() {
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);  
  delay(300);
  digitalWrite(ledPin, LOW);
  delay(100);
}

It starts to blink, but now the strange thing:

Randomly, between about 10 to 30 seconds later, it starts to blink faster (somehow about double the speed). After a few seconds it turns back to normal. I tried with different delay-values but always the same. It looks like the speed of the loop() is varying between two different speeds.

Any idea what this may be?

Second question: How do I set the CPU speed of my Teensy 3.1 using the makefile?

Thank you,

Kukulkan
 
I just found out that it does not happen if I compiled and uploaded the same code using the Arduino IDE. This is really strange.

Is there something I can do wrong by using Sudar makefile?

I'm also not sure about the teensy_loader_cli. If I set -w, I have to press the reset button every time. But if not, nothing happens. I found -s working in many cases (but not all) by trial and error. I know this page (https://www.pjrc.com/teensy/loader_cli.html), but still not sure about the right option. Can I call the GUI version from command-line, too? Will this be better?

Thanks,

Kukulkan
 
If you already have the Arduino IDE with the Teensyduino core files and the original Teensy makefile and the selectable options for different USB modes, processor speeds, and compiler optimizations installed, why would you compile your Teensy code with a different makefile. That makes absolutely no sense to me...

And the fact that everything compiles and works fine with the Arduino/Teensyduino IDE lets me think that the other makefile is either buggy or outdated. You should rather contact its author for support.
 
I mainly want to use the makefile to call it from inside an acceptable editor (even KATE is better than the Arduino IDE).

Asking the Makefile author (Sudar) is no bad idea, but I do not even understand how the makefile can make the Teensy vary its delay() values during runtime (where the makefile is finished). I believe he is sending me back to here to find out what's going on...
 
I just had a quick look onto that makefile stuff on GitHub. Although there has been a recent update there to parse the Teensyduino boards.txt file and to determine and set automatically the fastest speed, it doesn't take into account the other various USB and compiler optimization options. For me, it looks badly maintained if not outdated and I wouldn't work with that.
 
If not, you might always use the original makefile from here : https://github.com/PaulStoffregen/cores/blob/master/teensy3/Makefile

Please let me know if the problem happens when using this sample makefile.

At the moment all my dev cycles are going into USB host, but if the problem happens with this makefile I'll put it on my list of bugs to investigate. Sorry, even after USB host is running well, I can't really spend dev time on troubleshooting other makefiles.
 
No problem, I will try Sloeber and also other makefiles. Currently, I also think that the makefile is doing something wrong here. Thus, no need to take a deeper look.
 
If you already have the Arduino IDE with the Teensyduino core files and the original Teensy makefile and the selectable options for different USB modes, processor speeds, and compiler optimizations installed, why would you compile your Teensy code with a different makefile.
While it has improved quite a bit, the Arduino build system still isn't very good (to put it politely). It's slow as molasses and unreliable. (I'm using my own build system based on CMake/Ninja.)

\\

Arduino-Makefile by default uses the highest CPU frequency available in the CPU speed menu. For Teensy 3.1 that's 168'000'000, quite a bit of an overclock. Maybe your Teensy has problems with that. You can set the CPU clock with the 'F_CPU' environment variable; e.g. 'export F_CPU=96000000' for 96MHz.

In general, the various IDE menu settings result in different compiler options or preprocessor macros being defined. For the CPU clock that would be '-DF_CPU=96000000' or if you have the USB type set to USB serial, '-DUSB_SERIAL' is getting passed.

You should enable verbose compiler output in the IDE preferences and compare the compiler command lines.
 
Status
Not open for further replies.
Back
Top