## help with programming logic

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

RLOPES780
Posts: 109
Joined: Tue Apr 07, 2015 11:01 am
Been thanked: 3 times
Contact:

### help with programming logic

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
Attachments
SR CARLOS.fcfx

Lagoda
Posts: 152
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 66 times
Been thanked: 60 times
Contact:

### Re: help with programming logic

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
These users thanked the author Lagoda for the post:
Benj (Mon Sep 25, 2017 10:36 am)
Rating: 5%

QMESAR
Valued Contributor
Posts: 1187
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 379 times
Been thanked: 604 times
Contact:

### Re: help with programming logic

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.
These users thanked the author QMESAR for the post:
Benj (Mon Sep 25, 2017 10:36 am)
Rating: 5%

Benj
Matrix Staff
Posts: 14684
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4669 times
Been thanked: 4287 times
Contact:

### Re: help with programming logic

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

electronix
Posts: 58
Joined: Sat Aug 22, 2009 5:45 pm
Has thanked: 17 times
Been thanked: 7 times
Contact:

### Re: help with programming logic

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.
These users thanked the author electronix for the post (total 2):
QMESAR (Mon Sep 25, 2017 8:45 pm) • Lagoda (Tue Sep 26, 2017 7:22 am)
Rating: 10%

medelec35
Valued Contributor
Posts: 8624
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2482 times
Been thanked: 3570 times
Contact:

### Re: help with programming logic

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
Attachments
SR CARLOS V2.fcfx
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Steve001
Valued Contributor
Posts: 1107
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 454 times
Been thanked: 509 times
Contact:

### Re: help with programming logic

Success always occurs in private and failure in full view.

RLOPES780
Posts: 109
Joined: Tue Apr 07, 2015 11:01 am
Been thanked: 3 times
Contact:

### Re: help with programming logic

Good morning friends;

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.
Attachments
SR CARLOS.fcfx

Steve001
Valued Contributor
Posts: 1107
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 454 times
Been thanked: 509 times
Contact:

### Re: help with programming logic

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
These users thanked the author Steve001 for the post:
QMESAR (Tue Oct 03, 2017 5:45 pm)
Rating: 5%

Success always occurs in private and failure in full view.