Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Pulse output on Teensy 3.6

  1. #1

    Pulse output on Teensy 3.6

    I need to generate a continous digital output of 25.0 MHz, dutycycle 50 %, on a pin on the Teensy 3.6 kit. I have been through all the libraries, but none seem to hold the answer. Is it possible to do this? Can anybody offer a bit of help? Thanks for any input!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,857
    No, not 25 MHz.

    You can get integer division of F_BUS, which defaults to 60 MHz but can be 48 MHz or other lower frequencies (listed in kinetis.h).

    So you could get 30 or 24 or 20 MHz, but not 25 MHz.

  3. #3
    Senior Member
    Join Date
    Dec 2013
    Posts
    278
    A big note: I did this on Teensy 3.5 set with the CPU speed at 144 MHz overclock.
    Well at least you can try 24 MHz quickly.
    Code:
    // TEENSY 3.5  CPU @ 144MHz
    
    void setup() {
      pinMode(5, OUTPUT); // pin 5
      analogWriteResolution(2);  // Resolution (# of bits 2) analogWrite PWM Value 0 to 3
      analogWriteFrequency(5, 24000000); // Teensy changes to 24000000 kHz
      analogWrite(5, 2); // PWM Value 2 = 50% duty cycle
    }
    
    void loop() {
    }

  4. #4
    Thanks Chris!
    Funny thing is that your code gives me an output of 20 MHz. If I change the frequency parameter to 25 M, the output changes to 30 MHz. Problem: I am using two SPI channels running independently in parallel at SCK = 20 MHz. These are corrupted by the clock. It seems as if the clock is generated by code, not by a free running timer.

    The big problem with Teensy is the level of documentation. The commands you are using are described in a mix of Arduino and Teensy. Confusing, to say the least.

    Thanks for help so far!

  5. #5
    Senior Member
    Join Date
    Dec 2013
    Posts
    278
    I got all this from: https://www.pjrc.com/teensy/td_pulse.html
    Funny thing is that your code gives me an output of 20 MHz
    This is why I mention I did the testing on TC 3.5 not TC 3.6, try changing the CPU speed in Arduino IDE tools menu.

  6. #6
    Senior Member
    Join Date
    Dec 2013
    Posts
    278
    Problem: I am using two SPI channels running independently in parallel at SCK = 20 MHz. These are corrupted by the clock.
    Try using PWM pin 3 or 4.
    (Timer FTM1 PWM PINS 3, 4)
    (Timer FTM0 PWM PINS 5, 6, 9, 10, 20, 21, 22, 23)

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,857
    Quote Originally Posted by ErikRasmussen View Post
    Problem: I am using two SPI channels running independently in parallel at SCK = 20 MHz. These are corrupted by the clock. It seems as if the clock is generated by code, not by a free running timer.
    We could try to help you with this specific problem, if you can elaborate and maybe post a sample program which demonstrates the problem.

    But perhaps this is merely a misunderstanding about how SPI works? The SCK clock signal is not continuous. You only get short bursts of clock pulses during data transfers. That's how SPI works on virtually all microcontrollers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •