Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 33 of 33

Thread: counting clock cycles as a fast timer

  1. #26
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Quote Originally Posted by Dizzixx View Post
    ...
    Dizzixx, it is very helpful to take a look at the manuals (Kinetis + ARM Cortex M4)
    Things like "registers are 32Bits" are perfectly documented..

  2. #27
    Junior Member
    Join Date
    Aug 2017
    Posts
    4
    newbie here
    i am dealing also with a Time to Digital problem. The best i have so far is around 16ns accuracy with FreqMeasureMulti and this code

    // Measure 2 frequencies at the same time! :-)
    //FreqMeasureMulti freq1; // tacho counter
    FreqMeasureMulti freq1; // IAS counter


    void setup() {
    Serial.begin(57600);
    while (!Serial) ; // wait for Arduino Serial Monitor
    delay(10);
    Serial.println("FreqMeasureMulti Begin");
    delay(10);
    freq1.begin(5); // tacho counter pin 6
    //freq2.begin(6); // IAS counter pin7

    // analogWriteResolution(10);
    // timer0.begin(timer0_callback, 1.25);
    // pinMode(A21,OUTPUT);
    // analogWrite(A21,0);

    }
    int dim=32000;
    elapsedMillis timeout;
    unsigned long enc_data[32000]={0};
    volatile int16_t t = 0, m=0;

    void loop() { // ciclo di calcolo
    if (freq1.available()) {
    enc_data[t]=freq1.read();
    if (t==(dim)) {
    for ( m=1; m<=(dim); m=m+1 ) {
    // output section
    Serial.print(m);
    //delay(1);
    Serial.print(", ");
    Serial.print(freq1.countToNanoseconds(enc_data[m] ));
    Serial.println();
    }
    while(1) { } //stop loop
    }
    t=t+1;
    }
    }

    Actually i let it log a run and when its done i get measures from serial terminal. My issues are about pushing accuracy and a way to move out data for a real time Time to digital analyzer. For the last i am considerind to build an analog out with MCP4922 while wisely limit the range. Any further advice will be appreciate

  3. #28
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Why is 16ns a problem for you ? That's 62.5 MHz. Your MCPs' max SPI(!!) speed is 20MHz. I havn't read the datasheet in detail.. let's assume it wants 2 bytes: Divide 20Mhz by 16 (->2 Bytes) and you'll get 1.25 MHz theoretical maximum speed. Am I missing something
    Last edited by Frank B; 09-12-2017 at 08:27 PM.

  4. #29
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,716
    Just for a little perspective, this wikipedia page says "hypervelocity" is approx 3000 meters/second. That's really fast!

    But 16ns is *really* short. In fact, an object traveling that fast manages to move only 1/20th of a millimeter (48 microns) during those 16ns.

    Then again, perhaps an even better question would be whether the sensors and all analog signal acquisition involved really truly has a full 60 MHz bandwidth. I'm guessing probably not?

  5. #30
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Hm. Wolfram alpha says, it's 4.8 meters for light. Still extremely fast... ;-)
    https://www.wolframalpha.com/input/?i=16ns
    Last edited by Frank B; 09-12-2017 at 08:37 PM.

  6. #31
    Junior Member
    Join Date
    Aug 2017
    Posts
    4
    Quote Originally Posted by Frank B View Post
    what i meant is I need the best accuracy on Time to Digital Counter routine, I still expect to loose accuracy on putting in code related to TDC conditioning. Advices ?
    Then I need to feed a data out with those results at an approx rate of 30kHz.
    Do you think MCP is viable? Otherwise I think I should deepen in a TCP/IP based protocol (CANbus ?) and since my limited skills i would prefer something cheaper.
    thank you Frank B

  7. #32
    Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    49
    @rozilla Since you are looking to measure very brief events, obviously less than 16nS and perhaps more like 5nS or 1nS you have to change how you are looking at the problem. What you need is something called a 'time to voltage converter". Google it, there are papers describing it out there. It measures the time by charging a capacitor with a (gated) constant current. The resulting voltage is proportional to the time of the event. I don't know if there are chips available to do this, you gotta look around. The accuracy of these things can be phenomenal. The teensy can then be relegated to doing the boring, but important housekeeping routines of your instrument.

    As far as being a 'noob'...... Welcome to the fire of indoctrination.

  8. #33
    Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    49
    Or perhaps you are looking for one of these.....

    http://www.wavecrestdts.com/dts2079.htm

Posting Permissions

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