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

Thread: FreqMeasure Teensy 3.2 Library question - measuring Freq and PWM (or low time)

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    6

    FreqMeasure Teensy 3.2 Library question - measuring Freq and PWM (or low time)

    Hey guys, I'm trying to use the FreqMeasure library from 50Hz - 150Hz. I have already found the frequency measure to be very accurate and it is meeting my requirements perfectly. I am also looking to see what the negative (or positive, both work) duty cycle is of the signal to calculate the low time. My signal is encoded in both the frequency and negative pulse width (which I can measure from positive duty cycle).

    For reference: I have tried using the pulseIn function that comes with AVR, and it has a bit of error it it. I don't know if it is due to it being a very generic function and has some overhead or if it is a different problem. (For a frequency of 75Hz, I can see anywhere from 74 to 76). I would like to be within at least 1/2 of a Hz.

    Is there a way to edit the FreqMeasure library to output the PWM which would let me calculate negative pulse width? Any help and guidance would be appreciated .

  2. #2
    Junior Member
    Join Date
    Apr 2019
    Posts
    6
    Here is code written with interrupts, however I see a pretty big error with this too, which I'm not sure about.

    void loop() {
    timeStart = millis();
    attachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN), falling, FALLING);

    delay(timeStart + 100 - millis());
    }

    void falling() {
    t1 = micros();
    //detachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN));
    attachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN), rising, RISING);
    }

    void rising() {
    t2 = micros();
    //detachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN));
    attachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN), falling_2, FALLING);
    }

    void falling_2() {
    t3 = micros();
    detachInterrupt(digitalPinToInterrupt(ETHANOL_SENS _PIN));
    period = t3 - t1;
    freq = 1000000.0/period;
    // Some other return code
    }

    OUTPUT: https://imgur.com/A2rMIPW

    As you can see, something is causing the signal to fluctuate and it is fairly repeating. Any ideas?

Tags for this Thread

Posting Permissions

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