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

Thread: 20Mz PWM on a teensy ?

  1. #1

    20Mz PWM on a teensy ?

    Hello,

    I try to generate a 20mh 50% duty cycle signal on the teensy 3.6

    I can barely achieve 6Mhz, which is weird, since the teensy runs at 240Mhz

    anyone sees something wrong with my code ?

    thanks for your help

    Code:
    #define MCLK 9
    
    void setup() {
      pinMode(MCLK, OUTPUT);
      CORE_PIN9_CONFIG = PORT_PCR_MUX(1); // no slew rate limit
      noInterrupts();  // look pretty for the oscilloscope trigger
    }
    
    void loop() {
        digitalWriteFast(MCLK, 0);
        digitalWriteFast(MCLK, 1);
    }
    Click image for larger version. 

Name:	Untitled.jpg 
Views:	9 
Size:	66.0 KB 
ID:	18807

  2. #2
    Try and set a higher sampling rate on your Saleae.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Two issues.

    1: By default pinMode() turns on the slew rate limit feature. This greatly reduces noise and undesirable high speed effects when normal wires are used, but it also limits how fast the pin can change.

    2: There is significant overhead after loop() runs. Use a while (1) loop to check the raw performance.

    This code gives a 48 MHz waveforms on pin 9 when run on Teensy 3.6 overclocked to 240 MHz.

    Code:
    void setup() {
      noInterrupts();
      pinMode(9, OUTPUT);
      CORE_PIN9_CONFIG = PORT_PCR_MUX(1); // no slew rate limit
      while (1) {
        digitalWriteFast(9, HIGH);
        digitalWriteFast(9, LOW);
      }
    }
    
    void loop() {
    }
    Measuring this signal well, even with a high bandwidth oscilloscope, is tricky. The high speed edges create a lot of overshoot and ringing if a normal wire is used.

    Here's a prior thread with more info.

    https://forum.pjrc.com/threads/41874...l=1#post132359

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    You can also get a 20 MHz waveform from the PWM hardware, but not at 50% duty cycle. The timers run at 60 MHz (when Teensy 3.6 runs at any multiple of 60 MHz), so a 20 MHz carrier is only 3 timer clocks.

    Code:
    void setup() {
      analogWriteFrequency(9, 20000000);
      analogWrite(9, 128);
    }
    
    void loop() {
    }

  5. #5
    I cant find an option for that

  6. #6
    it works while the previous code freezes the teensy
    but I now reach 4mhz
    I try to find where to raise the saleae sampling rate

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Quote Originally Posted by phil123456 View Post
    while the previous code freezes the teensy
    If you turn off interrupts, the USB interrupt can't respond to Arduino's request to automatically reboot. Teensy is running, just not handling any interrupts when I/O occurs.

    Expect to need to press the pushbutton on Teensy to reprogram.

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,207
    At minimum you need 40Mhz - that's the minimum need for sampling 20MHz but can say nothing about timing details. For your pwm, I'd go for 100MHz absolutely minimum. If your saleae can do more, choose even more.

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,207
    ..or use a oscilloscope.

  10. #10
    ok with the scope the signal goes to 2 Mz and 48Mz with digitalWriteFast

    thanks gys

    maybe Saleae cant go that fast becos of the usb port

  11. #11
    ok I plugged my saleae 16 and found an option to set it to 100MS/s, now I get 20 Mhz
    I feel stupid :-)

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,207
    Mine, a clone, can do 100MHz.
    The newer official ones are capable of much much more for even more $$

    Edit: Crosspost

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,207
    No, correct measuring is a science...

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,093
    Just an FYI - With the Saleae logic analyzers - If you have a lot of channels being captured, your sample rate is lower.

    For example with my Pro 8, with two channels, I can capture at 500mhz. but with all 8 only 250mhz... With my other non-pro versions, there is more of a change.
    With 2 I can run 100mhz, but 3 drops to 50 and all 8 drops to 25... I have not tried the new software yet with my older 16 to see what speeds it can do.

  15. #15
    yeah just realized that now :-)
    with 4 chanels, I get 50MPs

Posting Permissions

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