Converting pulses per minute (uneven pulse width) to analog output signal

danadak

Joined Mar 10, 2018
4,057
I wonder if there is a way to essentially get the period, and convert that directly over to an analog reading... or a way to get more of an instantaneous reading instead of having to wait for the filter to stabilize?
If the ramp behaviour of the sensor is a known function, like exponential, linear ramp,
power series, yes that can be incorporated into code to take a reading and extrapolate
via a least squares or power curve predictor function.

What is setting time/latency you can live with ?

Regards, Dana.
 
Last edited:

danadak

Joined Mar 10, 2018
4,057
This definitely looks interesting! So is this a specific chip that functions like this? I'm a bit confused on what specific components those might be.
That is a PSOC, Programmable System On Chip.

Several familes from low end PSOC 4, to PSOC 6 dual core targeted to
IOT.

The 5LP family has a component catalog, a component an onchip resource,
catalog file attached. Low end parts have a subset of the catalog.

Boards are low cost, usb, debug, $ 10 - $ 25 depending on preferences.

Tool, PSOC Creator, and compiler free.

An intro - http://web.mit.edu/6.131/www/document/psoc_intro.pdf

A series of short videos - https://www.cypress.com/video-library/PSoC-Software/psoc-creator-101-lesson-1-introduction-0/108116

There are designs that can be completely codeless, simple logic designs like
gates and flops, and designs that use the more sophisticated components with
fixed parameters, that only requires a single code line Start( ); code entry, for
each advanced component used. Parameters are just configured as a right click
and entry, like freq, scale, trigger choice.....More advanced designs also manipulate
in code those parameters, thats where "normal" coding time is spent in "normal"
UP designs. Example changing a PWMs pulse width based on measured V. That
takes code updates to the PWM. That being said also can be used is DMA updating
automatically the PWM registers, an all HW approach, but then that takes code to
setup the DMA.

This design though takes some code. Translation calculation of Freq to V
needs some code/scaling. I am guessing 15 - 20 lines of code overall.

Here is a series of projects done with PSOC 4 low end, and a series done for BT applications -

https://www.element14.com/community/thread/23736/l/100-projects-in-100-days?displayFullThread=true

https://www.cypress.com/blog/problem-solver/100-projects-100-days-psoc-4-ble


Regards, Dana.
 

Attachments

Last edited:

crutschow

Joined Mar 14, 2008
34,280
Okay, here's a simple approach that uses no programmable devices and doesn't require a long time-constant filter.
  • Use an I2C A/D converter.
  • Use an analog integrate and dump to integrate the signal during each sensor pulse period (this will give a voltage proportional to the period, which gives a large signal for a low flow rate, but I assume you can deal with that in the rest of the system). That avoids a long filter time-constant as the signal is available at the end of each signal pulse.
  • At the end of each period, the A/D is triggered to perform one conversion and measure the integrator voltage, then send it across the I2C bus.
  • At the end of the A/D conversion time, the integrator is reset to zero to integrate for the next period.
The integrator would need to be designed with a low-offset, low bias-current op amp to minimize integration errors.

If only a single supply voltage is available, a Howland current-pump, positive integrator can be used.
This has the added advantage that the integration capacitor goes to ground and can be reset by a simple FET switch to ground.

Edit:
An even simpler approach might be to use an I2C interface counter, such as this, to perform digital integration.
  • A high sensor signal starts the counter to count a clock generator signal.
  • The clock could be an inexpensive 32.768 kHz MEMS oscillator such as this.
  • When the signal goes low, the count is transmitted over the I2L bus, giving a measure of the sensor pulse period (32,768 counts per second of high signal time).
This would require no analog components.
 
Last edited:

eetech00

Joined Jun 8, 2013
3,858
Thanks for the suggestions so far!

I dug deeper into the 555 timer approach (monostable multivibrator), and here is what I have come up with so far (I simulated it):
View attachment 179903

The left graph is the flow meter pulse, the middle graph is the 555 timer output, and the right graph is the output passing through an RC filter.
I changed the frequency from anything from 0.666 Hz (40 pulses per minute), to 0.0833 Hz (5 pulses per minute), and it seems to work ok. Downside is its slow to stabilize at a value.... how it is now it takes about 4 minutes to stabilize.

I wonder if there is a way to essentially get the period, and convert that directly over to an analog reading... or a way to get more of an instantaneous reading instead of having to wait for the filter to stabilize?

The reason why I can't do it digitally with a microcontroller and timer is because the only interface I have available is I2C. For this project, I2C is the only interface I have available for this.... so I can use I2C to interface up to an ADC.... but I am not really aware of any other way to get this information via I2C... so it seemed analog might work. I can also only take a reading every couple seconds or so. So there is not really a way for me to time the pulses directly.
You might take a look at the Microchip T9400 in F-to-V mode. It's spec'd DC-10Khz.
 

Bordodynov

Joined May 20, 2015
3,177
Place a binary counter (6 digits are sufficient) and reset it before starting the account. You do not need to convert the result into an analogue one. Then you will need 6 resistors (the simplest DAC).
 

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Okay, here's a simple approach that uses no programmable devices and doesn't require a long time-constant filter.
  • Use an I2C A/D converter.
  • Use an analog integrate and dump to integrate the signal during each sensor pulse period (this will give a voltage proportional to the period, which gives a large signal for a low flow rate, but I assume you can deal with that in the rest of the system). That avoids a long filter time-constant as the signal is available at the end of each signal pulse.
  • At the end of each period, the A/D is triggered to perform one conversion and measure the integrator voltage, then send it across the I2C bus.
  • At the end of the A/D conversion time, the integrator is reset to zero to integrate for the next period.
The integrator would need to be designed with a low-offset, low bias-current op amp to minimize integration errors.

If only a single supply voltage is available, a Howland current-pump, positive integrator can be used.
This has the added advantage that the integration capacitor goes to ground and can be reset by a simple FET switch to ground.

Edit:
An even simpler approach might be to use an I2C interface counter, such as this, to perform digital integration.
  • A high sensor signal starts the counter to count a clock generator signal.
  • The clock could be an inexpensive 32.768 kHz MEMS oscillator such as this.
  • When the signal goes low, the count is transmitted over the I2L bus, giving a measure of the sensor pulse period (32,768 counts per second of high signal time).
This would require no analog components.
Thanks for the info. I tried googling "analog integrate" and I couldn't figure out what this is?

I did look into that LS7366R chip which looked interesting... but this chip doesn't look available to be available. There are only one or two websites that have a breakout board with the chip installed on it, but you cannot purchase the chips individually for your own designs.
 

crutschow

Joined Mar 14, 2008
34,280
I tried googling "analog integrate" and I couldn't figure out what this is?
Read this for starters.
I did look into that LS7366R chip which looked interesting... but this chip doesn't look available to be available.
Sorry to hear that. :(
Perhaps you could use this event counter.
But it has only 1/4 second resolution, so that's 0.4% of one minute.
Is that adequate for your requirements?
 
I would suggest that you feed the signal into a flip-flop so that you get a 'square' wave signal out which get around your pulse issue. Then I would use a PLL with a suitable divider to track the frequency and then use the control signal to give you your analogue voltage. The issue with be loop stability but if you run the PLL at a relatively low frequency it will track reasonably well.
 

crutschow

Joined Mar 14, 2008
34,280
I would suggest that you feed the signal into a flip-flop so that you get a 'square' wave signal out which get around your pulse issue. Then I would use a PLL with a suitable divider to track the frequency and then use the control signal to give you your analogue voltage. The issue with be loop stability but if you run the PLL at a relatively low frequency it will track reasonably well.
Good luck getting a PLL to work at 16.7mHz (1 pulse per minute). :rolleyes:
 

Phil-S

Joined Dec 4, 2015
238
CMOS logic is one way - look up leading or trailing edge detection. I used a couple of CMOS chips to generate well defined pulses from a gas meter (Hall sensor) in the range 0 to 6 pulses per minute, plus allowing for the boiler turning off with the meter magnet sitting on the Hall sensor.
Or, do yourself a favour and look at an Arduino or a small MCU like the ATTiny 85. it will do all the conversions you want (not sure about native I2C), has accurate enough timing to give you a rate in pulses per second/minute/hour/day etc. Again, you would need to check whether it has PWM. The Atmega 328 chip (Uno or Nano) would probably do it all. Check out website Technoblogy. Author does some pretty useful things with the ATTiny's
 

djsfantasi

Joined Apr 11, 2010
9,156
CMOS logic is one way - look up leading or trailing edge detection. I used a couple of CMOS chips to generate well defined pulses from a gas meter (Hall sensor) in the range 0 to 6 pulses per minute, plus allowing for the boiler turning off with the meter magnet sitting on the Hall sensor.
Or, do yourself a favour and look at an Arduino or a small MCU like the ATTiny 85. it will do all the conversions you want (not sure about native I2C), has accurate enough timing to give you a rate in pulses per second/minute/hour/day etc. Again, you would need to check whether it has PWM. The Atmega 328 chip (Uno or Nano) would probably do it all. Check out website Technoblogy. Author does some pretty useful things with the ATTiny's
The ATTiny has up to four PWM pins. Two are native, but there are widely available hacks to get two more.
 

AnalogKid

Joined Aug 1, 2013
10,986
I think djs is on to something, but it doesn't have to be that complicated. AND, it depends on what the TS means by "read"ing an analog voltage. If he wants to buffer it, scale it, and drive an analog meter, then this idea will not work. If he wants to create an analog voltage to read it with an A/D, then a "digital integrator" (counter) should do it, and eliminate the analog stages altogether.

Each output pulse leading edge latches the output of a counter that is driven by a fixed-frequency clock, and then resets the counter. Both of those things can happen in way less than 1 ms, so as not to introduce a significant error term into the output. Counter depth (number of bits) and output code (BCD, binary, etc.) are determined by the TS and set the clock rate. A down-counter will give a larger number for shorter time periods, equivalent to larger flow.

1 pulse per gallon? Really? Any way to replace the sensor with one that runs faster?

ak
 

danadak

Joined Mar 10, 2018
4,057
Here is an approach -

upload_2019-6-21_13-15-37.png

One chip solution. Frequency counter drives 12 bit VDAC to translate freq to V. Basically you get
a ~ 3.5 decade range, It would be possible to use inteligent switched R divider to extend the
range. That would also be onchip except for R's needed for the divider.

The schematic is all onchip, the DDS (onchip) used to generate a test input, that can be
eliminated. Most of the chips resources not used, many left for other functionality. Look
at right hand window of resouces used/left. I used the LCD so that I could look at freq
measured and V generated for debug purposes. You could also eliminate that if not needed.

Cypress PSOC. Tool and compiler free. Board needed ~ $ 10

upload_2019-6-21_13-21-57.jpeg

The code was mostly LCD formatting code. If LCD not used code is ~ 10
lines needed. Just start commands for the components and variable definitions.
A component is an onchip resource.

Note counter can accommodate very narrow pulses, down to the pulse width of its
sampling clock which is 24 Mhz, ~ 2 clock cyles, or 50 nS.

Accuracy pretty good, Vref is onchip for VDAC. Timing accuracy not using a
xatl is +/- 1.5% using its IMO for freq cntr gate.

Regards, Dana.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,156
I think djs is on to something, but it depends on what the TS means by "read"ing an analog voltage. If he wants to buffer it, scale it, and drive an analog meter, then this idea will not work. If he wants to create an analog voltage to read it with an A/D, then a "digital integrator" (counter) should do it.

Each output pulse leading edge latches the counter output and then resets the counter. Both of those things can happen in way less than 1 ms, so as not to introduce a significant error term into the output. Counter depth (number of bits) and output code (BCD, binary, etc.) are determined by the TS and set the clock rate. A down-counter will give a larger number for shorter time periods, equivalent to larger flow.

1 pulse per gallon? Really? Any way to replace the sensor with one that runs faster?

ak
Or if using an ATTiny is possible, use it’s built-in ADC to read the analog voltage and calculate the PWM parameters, which are then output on a PWM pin.
 

Plamen

Joined Mar 29, 2015
101
Hey guys, I have a flow meter that outputs pulses based on the flow. 1 pulse per gallon of liquid.
There is a rotating mechanism inside the flow meter. The faster it rotates, the more pulses it generates:
1 pulse per minute, up to 40 pulses per minute. (same as 1 gallon per minute up to 40 gallons per minute).
Also, the faster the flow, the more narrow the pulse width is because the mechanism is spinning faster.

A typical application would be to count the number of pulses per minute and correlate that to flow.
Another option would be to count the time between pulses and correlate that to flow.

What I am wanting to do is to create a circuit that takes these pulses, and converts it to an analog signal (0vdc to 3.3vdc). I will then read this analog voltage and correlate that to a flow.

If the pulse widths were set to be the same, regardless of flow rate, then I could use a low-pass filter to convert this to analog.

But since the pulse widths decrease as flow rate increases, a low-pass filter will not work because the duty cycle isn't changing.

Is there another method for accomplishing this? I feel like if there is a way I could somehow normalize the pulse width of these pulses, then I could then use a LP filter, but I am not sure how to do that?

Thanks and any help is greatly appreciated!
Petkan:
There are two ways to make the frequency to analog voltage conversion irrespective of level and duty cycle i.e. without averaging:
The first approach is differentiating RC circuit, making a triangular pulses of constant area (the level will have to be stabilised). The second approach is the use of mono-stable, triggerred by the input pulses and maintaining constant on time (and level) i.e. allowing LP filtering (averaging). LTC699X family of timing chips from Analog.com (previously from Linear.com) are a perfect match. A tiny SO6 package, supporting 1% tolerance without RC circuits. Make sure to download the TimerBlox design utility (free), allowing to fill a questionnaire and get complete schematic with all component values. Also download LTSpice (again free) to be able to play with sample circuit and tweak components as required. You can simulate the whole circuit in LTSpice. I used the first method (differentiating ) in my first needle meter frequency meter.
An open collector stage pulls (pull up resistor) to a reference voltage and drives a capacitor/diode circuit. The cap is charged via the resistor (and diode to GND) for the off time. During On time it charge pumps via the diode into the needle meter (from common CD point to GND). The meter averages the negative exponential triangular pulses
 

AnalogKid

Joined Aug 1, 2013
10,986
The idea of having one edge of the input trigger a monostable to create a stream of constant width / variable frequency pulses and then lowpass filtering that has been around for a while. A "pulse-counting demod" was a feature in high-end FM stereo receivers in the 70's (Heathkit?). Also, it was used in high-end broadcast-quality video recorders in the late 60's. But for this thread, that 1 pulse per minute means the output filter time constants will introduce serious lag in the output signal.

ak
 
Last edited:

Phil-S

Joined Dec 4, 2015
238
Maybe I've missed something here, but I can't see what the OP wants to do with the analogue output.
If the object is to display the flow, then an MCU and a simple print to LCD or 7-segment would do and not involve outputting voltages.
But that involves a bit more coding which the OP doesn't want to do.
The only reason to want a voltage out, is either to feed it into a mechanical meter or an external LCD or feed it into something like a comparator.
I do essentially the same with pulses from a utility electricity meter or gas meter. The rising or falling edge goes to an interrupt on a 328. It times the intervals between edges and a bit of simple maths converts to kWhr which displays on a 7-segment display - it gets updated on every pulse.
From what I've read above, all good suggestions, it's going to take a lot of time and effort and possible failure if OP rules out coding.
There are plenty of examples available with code out there and all that is required is to buy a Uno or whatever, download the IDE and try it.
 

danadak

Joined Mar 10, 2018
4,057
How about an IC that can convert a slow pulse train ( frequency ) from a Hand-Held Tachometer into a Voltage, like ...
LM2907 + 3 Resistors + 2 Capacitors ( Zener Regulated Design Fig 19 )

http://www.ti.com/lit/ds/symlink/lm2917-n.pdf

Can the circuit in Fig 19 be designed for a smooth output voltage with just 1 pulse / minute = 1/60 Hz
Answer is yes, although it is a dithered DAC filtered by the cap loading. I can
make measurements of pk-pk noise if you wish. Plus one in code, only updates
the DAC if its value has changed from last freq reading. That eliminates large
excursions. But it is a dithered dac constantly being clocked. But short answer
is yes, the frequency is irrelevant to DAC performance.[

Note there is nothing stopping one for using one of the onchip opamps and doing
a LPF on the DAC output, but that adds offset error to be considered. Or the digital
filter onboard....all these methods add latency if that is of concern.

What is the freq range, resolution, VDAC accuracy you are seeking ?


Regards, Dana.

PS : Just realized your reference to post 19 was not the solution I posted,
ignore the above.
 
Last edited:
Top