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

Thread: fast delay question 3.6

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    11

    fast delay question 3.6

    dear reader,

    Using a Teensy 3.6.
    For a a project I need to have a very short delay shorter then 1Ás should be near 0.05ÁS (followed by a interrupt).
    Is it possible?

    I checked out :

    https://github.com/PaulStoffregen/FreqCount

    But this is driven by an external clock( the freq to measure) Can I some how set the LPTMR_CSR, PSR, CMR, CNR and / or the MCG_IRCLK to use an internal clock to make a fast delay?

    Thanks hanz




    from the headerfile:
    static inline void counter_init(void)

    {

    SIM_SCGC5 |= SIM_SCGC5_LPTIMER;

    LPTMR0_CSR = 0;

    LPTMR0_PSR = 0b00000100; // bypass prescaler/filter

    LPTMR0_CMR = 0xFFFF;

    LPTMR0_CSR = 0b00100110; // counter, input=alt2, free running mode

    CORE_PIN13_CONFIG = PORT_PCR_MUX(3);

    }

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,534
    Perhaps use a PIT timer in one-shot mode? If F_BUS is 60MHz on a Teensy 3.6 @180MHz, letting it count to 3 would give 0.05uS before launching an interrupt.

  3. #3
    Junior Member
    Join Date
    Sep 2019
    Posts
    11
    Thank you vy much, i'm going to deep in right a way.

    hanz

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,198
    Beware. If you are trying to continuously interrupt at a 20mhz rate, you won't succeed. Depending on what you are doing in your ISR, you typically can't expect more than a 1 to 3 mhz interrupt rate.

    also consider https://forum.pjrc.com/threads/29105...-Second-Pulses

    here is a sketch toggling pin 12 in the isr
    Code:
    // PIT timer ISR toggle pin 12, use scope or analyzer
    //https://forum.pjrc.com/threads/42643-Timer-1-cycle-problems?p=136712&viewfull=1#post136712
    
    const uint8_t out_pin = 12;
    #define OUT_PIN_PTOR GPIOC_PTOR
    #define OUT_PIN_BMASK CORE_PIN12_BITMASK
    
    void setup() {
      pinMode(out_pin, OUTPUT);
    
      SIM_SCGC6 |= SIM_SCGC6_PIT;
      __asm__ volatile("nop");   //timing problem on T3.5
      PIT_MCR = 0x00;
      NVIC_ENABLE_IRQ(IRQ_PIT_CH1);
      PIT_LDVAL1 = 1; // count to 1
      PIT_TCTRL1 |= 0x00000003; // enable Timer 1 interrupts (TIE = 1) & start Timer 1 (TEN = 0)
    }
    
    void pit1_isr(void) {
      PIT_TFLG1 = 1;  // clear interrupt  first
      OUT_PIN_PTOR = OUT_PIN_BMASK;
    }
    
    void loop() {}
    On T3.6, scope shows pin changing every 200 ns, with LDVAL of 1
    Reference: https://forum.pjrc.com/threads/42643...cycle-problems
    Last edited by manitou; 09-17-2019 at 02:43 PM.

  5. #5
    Junior Member
    Join Date
    Sep 2019
    Posts
    11
    Thank you very much Manitou, and tahnk you for the code.

    regards hanz

Posting Permissions

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