Page 1 of 1

help with programming logic

Posted: Sat Sep 23, 2017 11:32 pm
by RLOPES780
I am using a Pic 18f2423 with reference voltage on the adc converter of 1.25 volts.
I'm trying to read a gear with a linear output hall sensor model a1301k.
When this gear is spinning I have at the output of the hall sensor a sine wave of approximately 16 millivolts.
When the sensor is on top of the gear tooth I have the minimum voltage (sinusoidal valley). And when the sensor is in the hollow space I have the maximum voltage (sinusoidal crest). But not all the teeth have the same minimum tensions (but approximate), and not all spaces maximum tensions (not teeth) have equal (but approximate) .
I need to do a logic that finds the minimum voltage of the sinusoid and presents result 0 and then find the maximum voltage and present result 1 and is doing so in succession. It can only present 1 after a 0 and 0 after a 1.
I did a logic that is attached where I find the minimum value and then add a minimum value that would be the space of the gear. It works but when I change the size of the gear is my logic does not work anymore.

Grateful;

Ricardo

Re: help with programming logic

Posted: Sun Sep 24, 2017 5:56 pm
by Lagoda
Hi Ricardo,

I think you should use more samples for the decision and have to find local minimum and maximum.
It should be considered whether the actual sample value is smaller or larger than the previous samples.
For example, if the value of samples was growing for a time, but value of three samples successive are getting smaller than the previous one in the order, then was a positiv peak with four sample had been before and have to set up the output in "0".
Due to the noises, measured values may need to add a small hysteresis.
This method causes a small delay in detection.
In my opinion, the hall-sensor signal should be amplified, if it possibile.
The maximum frequency of the signal can also be interesting.

Best Regards,

Lagoda

Re: help with programming logic

Posted: Sun Sep 24, 2017 6:44 pm
by QMESAR
RLOPES780 wrote: I did a logic that is attached where I find the minimum value and then add a minimum value that would be the space of the gear. It works but when I change the size of the gear is my logic does not work anymore.
Unfortunately what you are doing is very odd in my opinion,The Standard procedure will be to translate the Sine signal into a TTL(square wave) signal that can easily be captured with HW modules such as the CCP module of your PIC which results in you having Time / number of pulses and duty cycle .
depending howe you setup and use the CCP module .The problem with your logic is that if you change gear size or speed changes happen your SW will not work as the Amplitude of your sine varies accordingly.

Re: help with programming logic

Posted: Mon Sep 25, 2017 10:40 am
by Benj
I'm with QMESAR on this - 16mV is not a lot to play with and so I would use a simple opamp circuit to amplify this signal to something more usable. By amplifying the signal it should be a lot easier to track the variation across a wider range of gears, assuming your sensor is up to the job, can accuratley monitor the variation and has no excess capacitance.

http://www.electronics-tutorials.ws/opamp/opamp_8.html

Re: help with programming logic

Posted: Mon Sep 25, 2017 5:33 pm
by electronix
You could use a suitable IC for the job such as: LM1815. it translates the sine to a nice clean TTL signal that can be captured by your PIC, I have used this IC in automotive aplications and it works like a charm.

Re: help with programming logic

Posted: Wed Sep 27, 2017 9:00 am
by medelec35
Hi Ricardo,
Will the attached flowchart work for you?

Flowchart assumes no noise of course.
If there is, then a few samples will be required as Lagoda stated.

Martin

Re: help with programming logic

Posted: Thu Sep 28, 2017 1:11 pm
by Steve001
Hi Ricardo,

another way ...

http://www.kerrywong.com/2013/02/06/pre ... asurement/

Regards

Steve

Re: help with programming logic

Posted: Tue Oct 03, 2017 11:47 am
by RLOPES780
Good morning friends;

Thank you for your help.
Continuing. I amplified the exit of the hall and made the program that is attached.
I can read the pulses of the gear teeth.
However I can read up to a range of 1000 hz. Even with a low reading sample in the adc converter. I am working with active PLL with the clock of 32 mhz.
I need to read a frequency higher than that around 2000 hz.
Is this a compiler problem that is free?
Is it possible to use another compiler that runs my programs without limitations to 8-bit pic?

Grateful;

Ricardo.

Re: help with programming logic

Posted: Tue Oct 03, 2017 1:06 pm
by Steve001
Hi Ricardo

I am not sure if this is what you are after,

this ic converts frequency to voltage (used to use it in a past life with digital tacho's) - you will have to clean the sine wave up though to a square wave

http://www.ti.com/lit/ds/sbvs015/sbvs015.pdf

Steve