0
\$\begingroup\$

I have a sensor (DRV425) which outputs an analog voltage. The voltage level changes to a lower voltage when the sensor pass an object. Please take a look at the screenshot. It shows the output signal of the sensor after passing 6 objects.

enter image description here

The length of the spikes depend on the velocity of the sensor and I want to measure the time between each of this spikes to calculate the velocity of this sensor. My actual idea is to measure the voltage with an ADC and calculate the average of the signal. But this idea is not very robust against some noise or some kind of peaks in the output voltage. So I´m thinking about some better ideas.

  • Does it make sense to use a moving average (exponential moving average) filter on this signal? As far as I know the exponential moving acts as a kind of low pass filter and so I don´t know if this works.
  • Does it make sense to average the data points and check if the average changes to detect if the voltage is above a threshold. This can start a counter and I stop it when the voltage is under a threshold to measure the length of the peak? With this I can calculate the time, by knowing the sample rate of the ADC and with the width of the measured objects I can calculate the velocity.
\$\endgroup\$
  • 2
    \$\begingroup\$ The normal approach would be to use the microcontrollers analog comparator (built in to most 8/16 bit chips), one leg has an RC to represent the average voltage, the other is the input voltage with a bias to reduce false triggering \$\endgroup\$ – Reroute Aug 27 '19 at 7:31
  • \$\begingroup\$ Do you have the name or datasheet for the sensor? \$\endgroup\$ – Prateek Dhanuka Aug 27 '19 at 7:32
  • \$\begingroup\$ @PrateekDhanuka I have added it in my question. \$\endgroup\$ – Kampi Aug 27 '19 at 7:34
  • \$\begingroup\$ @Reroute this was my very first idea, but I need some more sensors later and the microcontroller has only one AC. \$\endgroup\$ – Kampi Aug 27 '19 at 7:36
  • \$\begingroup\$ Do the sensors have to be measured at the same time? as you can for most older AVR chips use the ADC mux to feed the analog comparator, The other approach is just do the same with external comparators feeding a pin each, and just capturing clock on the rising or falling edge. \$\endgroup\$ – Reroute Aug 27 '19 at 7:39
2
\$\begingroup\$

Expanding to an answer,

The normal approach would be to use the microcontrollers analog comparator (built in to most 8/16 bit chips), one leg has an RC to represent the average voltage with a slight load to reduce the voltage on the RC by a little, so the signal needs to fall a certain amount before triggering, the other is the input possibly through the ADC mux for the older AVR style microcontrollers

Example circuit: Falstad Circuit Simulator Linkenter image description here

This is relying on the assumtion your sensors are fairly well matched to one another, if they are not, you would either need a dedicated external comparator per input, or an analog switch to move the input to AIN0's RC network as you switch ADC mux inputs.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. But one last question.. Why you connect the output of the RC with the positive input of the AC? Wouldn´t it be a better solution if you connect the output of the RC with the negative input, so the AC will substract the DC part of the voltage from the input signal? \$\endgroup\$ – Kampi Aug 27 '19 at 10:58
  • 1
    \$\begingroup\$ For most AVR microcontrollers, only the negative input of the comparator connects to the ADC mux, so had to work it that way, the timer capture doesn't care whether it is high or low, only that a change has occurred. \$\endgroup\$ – Reroute Aug 27 '19 at 11:36
  • \$\begingroup\$ microchipdeveloper.com/… for a more visual way of explaining the ADC multiplexer and how its used. I would imagine you would use the T1 Capture function, this stores the timer value when it changed high or low, from this you can read it, wait for the next update and use the 2 for your time difference. \$\endgroup\$ – Reroute Aug 27 '19 at 11:50
1
\$\begingroup\$

Does it make sense to use a moving average (exponential moving average) filter on this signal? As far as I know the exponential moving acts as a kind of low pass filter and so I don´t know if this works.

Yes. But not as a low pass. As a high-pass to remove the DC offset.
This you can then put trough an integrator, since the signal looks like it is AC coupled.
After the integrator you will have something that resembles a square wave.

With that you can simply count the number of samples it is high/low and you know the time.
This way should be less susceptible to external fields or change of dc offset.

Perhaps you can trial this with your scope first. Set the channel AC coupled, and store the waveform data to a file for processing, in scilab for example.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

If you simply need to measure the period between triggered instances of multiple analog sensors, and you do not need to record the amplitude of the signal, but rather, just it's transition, then I would OR the signals using a Schmitt Trigger solution, moving your input signal from the analog domain into the digital domain. The output of the Schmitt Trigger could then, of course, be interfaced to any digital input pin of your micro controller.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.