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

Thread: FreqMeasure Library - Smooth it out

  1. #1

    FreqMeasure Library - Smooth it out

    Hello fellow Teensy friends,

    I just tried the FreqMeasure library, where I have a continental Ethanol sensor hooked up, it pulses from 50 - 150hz, but the average values I get fluctuates allot.
    I'm using the example from here: https://www.pjrc.com/teensy/td_libs_FreqMeasure.html haven't changed anything at all from that code. As you may see, it takes 30 samples and averages them out.

    Click image for larger version. 

Name:	test.png 
Views:	20 
Size:	10.6 KB 
ID:	26201

    Any ideas?

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,366
    Apparently there are counterfeits of this sensor around. Do you have an indepedent means to check the output frequency
    such as a 'scope (some multimeters can do frequency too)?

    I believe its 5V output so is not directly safe to use with T4.x for instance.

    And which sensor is it exactly? (link please).

  3. #3
    Quote Originally Posted by MarkT View Post
    Apparently there are counterfeits of this sensor around. Do you have an indepedent means to check the output frequency
    such as a 'scope (some multimeters can do frequency too)?

    I believe its 5V output so is not directly safe to use with T4.x for instance.

    And which sensor is it exactly? (link please).
    I don’t have a scope I’m afraid.

    Interesting! This should be a legit one. I bought it from a Motorsport company in my country. Here it is: https://www.streetpower.se/givare-oc...ol-givare.html

    EDIT: Here is what I did today, I skipped the average stuff alltogether to just get the real time HZ from the sensor. Without any filtering code it's fluctuating like crazy. I have IPA (99% Alcohol) in the sensor now, I have also tried with no alcohol, there is a difference so something is happening atleast.
    I would say that any value above 200hz can be ignored completely. But it will still not be reliable.

    Click image for larger version. 

Name:	values.png 
Views:	22 
Size:	11.8 KB 
ID:	26215
    Last edited by Dogbone06; 10-18-2021 at 11:06 AM.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,366
    IPA is not the alcohol it is designed for, it is for ethanol, not isopropanol - the clue really is in the name!!

    Reading a bit more it seems these sensors actually measure permittivity so its probably not going to work if any moisture
    is present (about the highest permittivity of any liquid).

  5. #5
    Thatís not entirely true tho. Ofc Iím going to buy E85 and test with. But Ethanol is alcohol made from Corn or Wheat. An ethanol sensor measures the percentage of alcohol in the fluid given to it. In my case it should show 99% as thatís what IPA is.

    We will see what difference I get with E85.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,223
    Might be interesting to get a look at the actual waveform this sensor creates, ideally using an oscilloscope, but even a logic analyzer which hides analog problems would be interesting.

  7. #7
    Quote Originally Posted by PaulStoffregen View Post
    Might be interesting to get a look at the actual waveform this sensor creates, ideally using an oscilloscope, but even a logic analyzer which hides analog problems would be interesting.
    I'm going to try E85, I have also ordered a glass E85 tube tester, so that I can see what's going on. I should get myself a logic analyser or oscillioscope, alltho not one of those super expensive ones. Any ideas for a fair priced one?

    I'd say that these high values are ghost values, this sensor outputs a maximum of 200hz. And I know the Teensy is very aquare after watching you on youtube going to 65mhz.

  8. #8
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Quote Originally Posted by MarkT View Post
    IPA is not the alcohol it is designed for, it is for ethanol, not isopropanol - the clue really is in the name!!
    Reading a bit more it seems these sensors actually measure permittivity so its probably not going to work if any moisture
    is present (about the highest permittivity of any liquid).
    Right, found this page.
    Ethanol [C2H5OH] has a relative permittivity of ~25, IsoPropylAlcohol [C3H8O] of ~18.
    Interesting to see what the E85 and tube tester will show.

    Quote Originally Posted by Dogbone06 View Post
    I should get myself a logic analyser or oscillioscope, alltho not one of those super expensive ones. Any ideas for a fair priced one?
    Depends on what purpose you see for your scope. Just to get a fair indication of a waveform and its properties or more advanced stuff?
    Perhaps check out this page first, to get an idea on what you want/need and what you want to spend.

    Paul

  9. #9
    Quote Originally Posted by PaulS View Post
    Right, found this page.
    Ethanol [C2H5OH] has a relative permittivity of ~25, IsoPropylAlcohol [C3H8O] of ~18.
    Interesting to see what the E85 and tube tester will show.


    Depends on what purpose you see for your scope. Just to get a fair indication of a waveform and its properties or more advanced stuff?
    Perhaps check out this page first, to get an idea on what you want/need and what you want to spend.

    Paul
    Yesterday I got myself a liter of E85 from the pump into a clean bottle. I deal with chemicals on a daily basis so rest asured, this bottle is okay with the E85.

    Got a looped hose to and from the sensor with E85 filled up. These are the readings I get. I took the code straight out of Speeduino, the logic is pretty simple.
    Most likely the E85 I got is E71, that's not at all unusual, specially now when it's getting colder. But the other two values is obviously an issue.

    Any ideas?

    Click image for larger version. 

Name:	eth.png 
Views:	22 
Size:	5.5 KB 
ID:	26250

    Code:
      if (FreqMeasure.available()) {
          float HZ = FreqMeasure.countToFrequency(FreqMeasure.read());
    
          // SPEEDUINO CODE START
          if (HZ < 50) {
            ethanol = 0; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage.
            HZ = 0;
          } else
          if (HZ > 151) { //1 pulse buffer
            if (HZ < 169) {
              ethanol = 100;
              HZ = 0;
            } else {
              //This indicates an error condition. Spec of the sensor is that errors are above 170Hz)
              ethanol = 0;
              HZ = 0;
            }
          } else {
            ethanol = HZ - 50; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage.
          }
    
          //Off by 1 error check
          //if (ethanol == 1) { ethanol = 0; }
    
          Serial.println(ethanol);
          // SPEEDUINO CODE END
      }

  10. #10
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Could it be that the amplitude of the output signal of the sensor is just too low such that Teensy is missing pulses?
    By the way, which Teensy model are you using?
    And did you perhaps receive the glass E85 tube tester?

    Paul

  11. #11
    Not sure, it could be! The glass tube should arrive next week.

    Iím using a Teensy MicroMod

  12. #12
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Quote Originally Posted by Dogbone06 View Post
    I’m using a Teensy MicroMod
    Caution here: the pins of the Teensy MicroMod can only handle max 3V3 [similar to Teensy 4.x]. Perhaps you are already overdriving the pins...

    Paul

  13. #13
    No, according to the flex fuel sensor PDF. Using a 1.2k resistor is perfect for 3.3V. So thatís not a problem.

  14. #14
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Quote Originally Posted by Dogbone06 View Post
    ... the flex fuel sensor PDF.
    Do you happen to have a link to that PDF?

    Paul

  15. #15
    I donít right now. But I have this picture which is the important part.

    https://i.ibb.co/6RB3M78/04-BD232-B-...DA214515-E.jpg

  16. #16
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Ah OK, the sensor has an open-collector output. So you used a pullup resistor of 1K2 to 3V3?

    Paul

  17. #17

  18. #18
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Allright.
    On the 0, 9 & 10 values you see: is the sensor 100% filled with E85 fuel? I mean no airbubbles?

  19. #19
    With E85 that I got from the gaspump, I see 0, 10, 11 and 71. The 71 value is most likely correct. There is a little air in the hose but Iím turning the sensor to make sure that the bubble is in the other side of the hose. I also have the hose twisted sort of upwards and the sensor is standing in the table. Hose is stiff and 46 degrees in the air. This makes the little bubble stay there. I have tried turning the sensor in all kinds of directions while looking at the screen. I see no change in the behavior.

  20. #20
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    I'm afraid it's now time to connect an oscilloscope to the sensor output to see what's going on...

  21. #21
    Time to buy one I guess. Itís also a nice tool to have to check whatís going on. I donít know much about them, I know what they do roughly but not much about functions.

    Any ideas what a good one could be? Checking waveforms and HIGH/LOW state is the basics id need it for atleast.

  22. #22
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    696
    Perhaps the Hantek DSO2C10 is suitable for you? It's a basic scope for around euro 250.

  23. #23
    Quote Originally Posted by PaulS View Post
    Perhaps the Hantek DSO2C10 is suitable for you? It's a basic scope for around euro 250.
    Looks like a good idea, I will buy this one or something similar soon. My friend has one of those small handheld ones for cheap, I might go with that. Otherwise, the one you linked!

  24. #24
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,366
    Quote Originally Posted by Dogbone06 View Post
    But Ethanol is alcohol made from Corn or Wheat. An ethanol sensor measures the percentage of alcohol in the fluid given to it. In my case it should show 99% as thatís what IPA is.
    I'm pretty sure the sensor measures permittivity, not alcohol content directly - in other words its using permittivity as a
    proxy for ethanol content. Since petrol is non-polar it has a low and predictable permittivity, but anything with an OH group
    (very polar) will have higher permittivity (water especially as it entirely OH groups). The ratio of the permittivities
    of ethanol to isopropanol will give a guess at the conversion factor, but any moisture is going to be a major confounding
    factor due to its very high permittivity.

    ethanol : 24.5
    isopropanol: 17.9
    water: 80.1
    gasoline: 2.0

    I reckon 100% (dry) isopropanol will read as 75% ethanol given those figures.

    (ethanol also comes from barley BTW, notably in Scottish distilleries

  25. #25
    Interesting data indeed. Unfortunately I havenít gotten the sensor to stop being so volatile.

    In Sweden, we have an energy and pollution sticker on each pump. Ethanol here is made from Wheat or ĒVeteĒ in Swedish. I think the Americans make it from Corn.

Posting Permissions

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