Search results

  1. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    This still works for me using Teensyduino: Teensy 4.0 Arduino 1.8.19 Teensyduino 1.56 Windows 10
  2. L

    TeensyMM SparkFun Input and Display Board demo

    Here is a program I wrote to demonstrate all the features of the SparkFun MicroMod Input and Display Board when using a TeensyMM processor: Features are: 2.4" TFT ILI9341 display various buttons/joystick microSD slot 6 APA102 LEDs Buzzer The file is at...
  3. L

    MicroMod Beta Testing

    I'm working on a demo program to show how to use all the features on the "Input and Display" carrier board. It took some digging to find all the info on it. For the display, CS is pin 4 and DC is pin 5. And you have to put a "<>.invertDisplay(true);" in to get the right colors.
  4. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    I ran the sketch from the first post with Teensyduino 1.54, Arduino 1.8.15, compiled with Debug, and it worked. So it appears the issue was fixed in 1.54.
  5. L

    Teensy 4.0 Internal Temperature measurement

    It looks like this is caused by using unsigned integers in tempmon.c. As temperature goes up, nmeas goes down. When it gets below s_hotCount (i.e. above 95 degrees), the value goes negative, which is a large positive number due to unsigned int. Fix is probably to change nmeas and s_hotCount to...
  6. L

    Simultaneously reading 8 GPIO pins

    To set the pins as GPIO Inputs: pinMode(16, INPUT); pinMode(17, INPUT); pinMode(20, INPUT); pinMode(21, INPUT); pinMode(22, INPUT); pinMode(23, INPUT); pinMode(26, INPUT); pinMode(27, INPUT); Here's how to move those bits down to the lower 8 bits: uint32_t sample...
  7. L

    Simultaneously reading 8 GPIO pins

    Here's a short sketch that reads 1024 32-bit values from Port 6 in an efficient manner: #define BUFFER_SIZE 1024 uint32_t buffer[BUFFER_SIZE]; void setup() { uint32_t *buffer_ptr = &buffer[0]; uint32_t *end_of_buffer = &buffer[BUFFER_SIZE]; while (buffer_ptr < end_of_buffer) {...
  8. L

    Simultaneously reading 8 GPIO pins

    If you really only have about 10-18 clock cycles, assembly language is probably the only way. I wrote a logic analyzer that reads and stores 32 bits in 8 clock cycles, but it is in assembly. On the Teensy 4, a GPIO read takes 8 clock cycles and a write takes 1 clock cycle. Luckily with the...
  9. L

    GPIO_GDIR issue

    It's declared volatile, which tells the compiler to not optimize it out but read it every time. The &= and |= will do a read/write sequence. A plain = will only do a write.
  10. L

    GPIO_GDIR issue

    GPIO reads take longer than writes. If you can eliminate as many reads as possible, it will help. If you know the GPIO7_GDIR isn't changed except by the ISR, you can read it once at startup and compute static values to write. Maybe the same with GPIO2_ISR. Also if you can read and save GPIO6_PSR...
  11. L

    InternalTemperature problem

    For a Teensy 4, TEMPERATURE_NO_ADC_SETTING_CHANGES and TEMPERATURE_MAX_ACCURACY aren't used. InternalTemperature is just a wrapper around tempmonGetTemp. The original poster was probably using a Teensy 3, where it does make a difference.
  12. L

    InternalTemperature problem

    Try adding a call to "begin" in setup: #include <InternalTemperature.h> void setup() { Serial.begin(9600); InternalTemperature.begin (TEMPERATURE_NO_ADC_SETTING_CHANGES); delay(500); } void loop() { Serial.print("\nvoltage = "); Serial.println(getVoltage()); delay(500)...
  13. L

    Using XBAR_INOUT for input and output at the same time

    What if you use an output from the And-Or-Inverter (AOI) module? xbar_connect(XBARA1_IN_AOI1_OUT0, XBARA1_IN_IOMUX_XBAR_INOUT07); xbar_connect(XBARA1_IN_AOI1_OUT0, XBARA1_IN_IOMUX_XBAR_INOUT08); xbar_connect(XBARA1_IN_AOI1_OUT0, XBARA1_IN_IOMUX_XBAR_INOUT09); You would have to set the AOI...
  14. L

    Teensy 4.0 Bitbang - FAST.

    See thread here for an example of disabling dual issue. Be aware that code will run significantly slower if dual issue is disabled.
  15. L

    loop execution time with dual-issue disabled Teensy 4.0

    Apparently setting those bits in ACTLR doesn't disable all instructions. There is a bit, DISFOLD (bit 2), that completely disables dual issue. After setting it, the example takes 9 cycles. Replace (*ACTLR) |= 0x001F0000 ; // DISDI (*ACTLR) |= 0x03E00000 ; // DISISSCH1 with (*ACTLR) |=...
  16. L

    My Teensy Logic Analyzer

    Yes! Many of us have an extra teensy sitting around. My intent was to make it as easy as possible to set up and run. The instructions are here. It is just a zip/tar file that unpacks to a single directory. If you want to remove it, just delete the directory. Search the user's guide for Demo...
  17. L

    Generate 38 kHz square wave for mixing with a sine wave

    You can read a PWM signal via software. Here's a program that outputs a 38kHz signal on pin 10 and reads 40 samples 1 microsecond apart. You will see the sample change value every 12-13 samples. void setup() { const int NumSamples = 40; int samples[NumSamples]; analogWriteFrequency...
  18. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    I went back and verified my results just to make sure. I looked at the timing in the interrupt routine before the callback and after the callback. GPT Pre-callback time: 108 nsec Post-callback time: 108 nsec TMR Pre-callback time: 133 nsec Post-callback time: 42 nsec So the...
  19. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    I made some more measurements. I increased the logic analyzer to 120 MHz and removed all of the dsb's, so the measurements are more consistent now. Note that clock cycles are more precise at lower CPU speeds, since the higher CPU speeds are much larger than the logic analyzer sample rate. I...
  20. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    The "150 MHz" is actually F_BUS for the GPT. I printed out F_BUS_ACTUAL and it is 75.6 for 150, 150 for 450 and 600, and 204 for 816. So that should make the points in the graph more linear. My logic analyzer (a Teensy 3.6) was running at 80 MHz, so at the higher CPU speeds it had trouble...
  21. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    I decided to get the logic analyzer out and measure how long the timer interrupts take in the TeensyTimerTool library with a Teensy 4.0. I varied both CPU speed and Timer clock speed (I used the GPT timer). As expected, at the higher CPU speeds, the Timer clock speed becomes a bigger factor in...
  22. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    For writing a pulse, in the timer interrupt callback, I would set the pin high, delayNanoseconds (500), set the pin low, start the timer for the next interrupt.
  23. L

    Teensy 4 Timed Interrupts faster than one microsecond?

    I haven't used interrupts much as I wanted to go as fast as possible. I am sampling at a specific rate, so I poll on ARM_DWT_CYCCNT, which increments every CPU clock cycle. It takes about 4 or 5 clock cycles to sample and compare in a loop, and I could do what I needed in about 25 clocks, so I...
  24. L

    TimerOne - slow 1 Hz pulses works on Uno, but not on Teensy 3.2?

    A better solution instead of TimerOne would be to use analogWriteFrequency. The Teensy 3.2 allows up to 3 different frequencies (FTM0,1,2). You could use pins 3 and 5, for example, as follows: analogWriteFrequency (3, 1.0); // 1 Hz analogWrite (3, 26); // 10% duty cycle...
  25. L

    TimerOne - slow 1 Hz pulses works on Uno, but not on Teensy 3.2?

    For the Teensy 3.2, the lowest frequency possible with TimerOne is a function of F_BUS/2. The maximum timer count is 32768 * 128 = 4,194,304. If CPU Speed is the default 96 MHz, F_BUS is 48 MHz, so the minimum frequency is 48/2 MHz / 4,194,304 = 5.7 Hz. F_BUS can be reduced by reducing the CPU...
  26. L

    My Teensy Logic Analyzer

    New release for using your Teensy as a logic analyzer - now supports 8 channels on Teensy 4.x, up to 75 MHz sample rate. https://github.com/LAtimes2/TeensyLogicAnalyzer
  27. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    Teensy 4 does have port names - ports 6/7/8/9. See this forum entry for more details. In the diagrams, the GPIO column is the port and bit number, but you need to add 5 to the port number. For example, pin 1 is GPIO 1.2, which means it is port 6 (1+5), bit 2.
  28. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    More digging this morning. Appears to be a timing issue near this line in startup.c: usb_pll_start(); reset_PFD(); //TODO: is this really needed? If I comment out the reset_PFD, it starts working. Also adding nop's in various places nearby/within makes it work. (Note the nop's with why oh...
  29. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    The change does cause the problem to go away. However, it is because it changes the memory map. I can make the problem re-appear by adding nop's to align the memory such that it fails again. So if Paul fixes some of the TODOs in this routine, the problem could come back in future releases. I...
  30. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    I've traced this problem down to the last line of configure_cache in startup.c. By adjusting the number of nop's in front of it, I can make it consistently work or fail. Also, if this line only enables the data cache, it works; if it only enables the instruction cache, it fails, so the...
  31. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    Thanks for the info. I will continue to investigate - maybe a good excuse to try gdb.
  32. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    Can anyone else duplicate the problem in the first post or is it just me? Note that it locks up the Teensy and you have to press the button to get into the bootloader.
  33. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    I started digging into this in startup.c, and as soon as I uncommented any of the debug lines 59-63, it started working. I add 1 nop and it still failed, but 2 nop's work. The nop's can be added anywhere in ResetHandler. This makes me think something doesn't like its alignment offset. Looking...
  34. L

    Teensy 4.1: Storing the value of 18 pins' input quickly

    You would connect one color (e.g. red) to pins 24 (LSB), 25, 19, 18, 14, 15 (MSB). The next color (green) to 40 (LSB) through 23 (MSB), and last color (blue) to 20 (LSB) through 27 (MSB). rawValue = GPIO6_PSR; red = ((rawValue & 0x000F0000) >> 14) + ((rawValue & 0x00003000) >> 12); green =...
  35. L

    No USB serial with Teensy 4.x compiled Optimize: Debug

    I compiled the short sketch below with Optimize: Debug and no USB serial port is created under Windows or Linux. It works when using any other Optimize setting, and works with Teensy 3.5 compiled Debug. Teensy 4.0 and 4.1 Arduino 1.8.13 Teensyduino 1.52 and 1.53 Windows 10, Ubuntu void setup()...
  36. L

    New Internal Temperature Library

    The library is now available via the Arduino library manager: Tools -> Manage Libraries ... Search for InternalTemperature Install
  37. L

    New Internal Temperature Library

    I will do that. Thanks
  38. L

    New Internal Temperature Library

    I have added support for Teensy 4, so you can have common routines for both T3 and T4. Also added overtemp and undertemp alarms that you can attach ISR functions that are called when the temperature exceeds the limit. There is an example for T4 that performs CPU throttling when the temperature...
  39. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    Teensy 4 has a delayNanoseconds(), but not Teensy 3. This line has about 40 nanosecond overhead plus 40 nanosecond delay per loop at 240 MHz (80 nanoseconds at 120 MHz): for (int volatile index = 0; index < 1; index++); So 40 nanoseconds for 0, 80 for 1, 120 for 2, 160 for 3, etc.
  40. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    I tried my example above compiled with "Fastest with LTO" at speeds up to 240 MHz and it worked every time. It may be a subtle timing issue with your setup - what defines 'not working'. If a pin is not assigned to GPIO via the MUX (by calling pinMode (x, OUTPUT)), then the value in GPIO_PDOR...
  41. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    I was not able to duplicate your problem. Both ways always set both pins. I first set and cleared the bits individually, then set and cleared them together. Here is my code: pinMode (29, OUTPUT); pinMode (30, OUTPUT); uint32_t i = 0xFFFFFFFF; while (1) { GPIOB_PSOR = ((i & 0x40) <<...
  42. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    Sorry, I've been using PDOR and didn't notice the one letter difference. It looks like it should work with PSOR, but I've never used those registers so don't have any experience with them. I'll give it a try this evening.
  43. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    It looks like you are setting bits 18 and 19 in GPIOB. In the second example, both bits are set from i at the same time. In the first example, the first line sets bit 18 from i with bit 19 set to 0, and the second line sets bit 19 from i with bit 18 set to 0. At the end, bit 18 will always be 0...
  44. L

    My Teensy Logic Analyzer

    It's here! Teensy 4.0 beta release. Currently only supports 3 channels, final release will have 8 channels. https://github.com/LAtimes2/TeensyLogicAnalyzer The high-computation modes (triggers/RLE) are up to 5 times faster than T3, but GPIO input is slower (8 CPU clock cycles), so max speed is...
  45. L

    My Teensy Logic Analyzer

    For speed and consistency, it reads an entire input port at once. So it is limited by the number of pins tied to each port. 12 pins is about the max, and I've thought about adding that, but it would be a lot of work for what it adds. The Teensy 4 should have enough speed to read multiple ports...
  46. L

    My Teensy Logic Analyzer

    I've been busy at work, but still hope to get to this soon :)
  47. L

    Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR

    Pins 24 and above are on different GPIO ports between Teensy 3.2 and Teensy 3.5/3.6. For 3.5/3.6, here is a table of pin numbers to port/bit number, and also a table of ports A-E to pin numbers. It is color-coded by pin location (front/back) and port number. I also attached the spreadsheet for...
  48. L

    Limits of Fast, Precise Timing for Teensy 3.6 External ADC Data Acquisition

    I've been experimenting with using a PWM pin for the clock and polling on it. It works consistently at 10 MHz using the code below. If all the pins are on a single GPIO port, I can read it and store the data in almost same amount of time as setting the trigger pulse in the example. Just to whet...
  49. L

    Limits of Fast, Precise Timing for Teensy 3.6 External ADC Data Acquisition

    One thought I have is to use a hardware PWM signal with 50% duty cycle to drive the clock and synchronize the software to read the ADC at the right time, perhaps via interrupt or polling. Here an example creating a 20 MHz clock on pin 3: analogWriteFrequency (3, 20000000); analogWrite (3...
  50. L

    Limits of Fast, Precise Timing for Teensy 3.6 External ADC Data Acquisition

    I was running your examples and was able to duplicate the timing numbers. With a few small changes as shown below, I was able to get your next-to-last example to be about 10 times faster. [I had to slow my T6 down to 120 MHz so that my logic analyzer could keep up] One change is to make the pin...
Back
Top