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

Thread: Coincidences Counter (two pulse sources)

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    2

    Coincidences Counter (two pulse sources)

    Hello everybody,
    I'm using Teensy 3.6, Arduino IDE.

    First of all, A coincidence happens when detecting pulses from two different sources, in a time window of let's say 5 ns, we see a rising edge on both pulse sources.

    I am trying to count coincidences coming from two different pulse sources, my main question is, can I get to count pulses coming of two different sources using Teensy 3.6?

    I started using Teensy recently so I'm using the simplest code to count pulses but it is valid for only one pulse source:

    Code:
    #include <FreqCount.h>
    
    void setup() {
      Serial.begin(57600);
      FreqCount.begin(1000);
    }
    
    void loop() {
      if (FreqCount.available()) {
        unsigned long count = FreqCount.read();
        Serial.println(count);
      }
    }
    Any suggestions?

    Thanks

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    5ns - 200MHz.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,553
    Tighter timing than ~17 ns (one cycle of F_BUS at 60 MHz) probably isn't practical. If you absolutely need 5 ns, you're probably going to need a FPGA or other special hardware.

    For timers on Teensy 3.6, you probably want to start with the FreqMeasureMulti library. The bad news is you will definitely need to edit the library code. The good news is most of that editing will amount to just deleting stuff. FreqMeasureMulti captures timestamps when the edges occur. It extends the 16 timer to 32 bits, then subtracts each timestamp from the previous, to get the elapsed time. For this, you can get rid of all that processing and just put the raw 16 bit timestamps in the queue, to be read by the main program. They're captured from the same timer, so if you get 2 readings that are identical or differ by just 1 count, then they occurred at nearly the same time.

    But again, remember the timers clock from F_BUS (60 MHz), not F_CPU (180 MHz). It is possible to attempt overclocking F_BUS, if you edit kinetis.h. See the comments in that file. However, even with overclocking, getting to 5 ns precision probably isn't achievable on Teensy 3.6. One or two cycles of F_BUS is probably as good as you can do.

  4. #4
    Junior Member
    Join Date
    Mar 2019
    Posts
    2
    Thanks for answering me.

    The thing is, I bought the Teensy 3.6 based thinking that I can work it on 240 MHz frequency which is enough for 5 ns speed. Which is at least what I need because I will be counting photons and they come at around this time window.
    So what is F_BUS and how does it differ from F_CPU (What do they do)?
    And if I wanted to get an FPGA for the same job, is the clock frequency the thing I should be looking at or what?

    I'll try to play with FreqMeasureMulti library to see how far I can get it to work.

    Big fan of your work btw, keep it up!

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Quote Originally Posted by AbYaSSer6 View Post
    Thanks for answering me.

    The thing is, I bought the Teensy 3.6 based thinking that I can work it on 240 MHz frequency which is enough for 5 ns speed.
    ? you would have 1 cycle ? A CPU can not do much with 1(one) cycle. And the periphals (on Teensy, clocked by F_BUS) are slower than the cpu.
    You need fast external hardware such as flipflops & counters, or a FPGA.

Posting Permissions

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