Page 1 of 1

Compiler Doubt

Posted: Thu Apr 13, 2017 2:40 am
by RLOPES780
""You have compiled in FREE mode.
Using Omniscient Code Generation that is available in PRO mode,
you could have produced up to 60% smaller and 400% faster code.
See http://www.microchip.com/MPLABXCcompilers for more information.""

About the above description.
I'm using the pic 18f2423 with the internal clock of 8 mhz, reading through the ad converter 12 bits and fosc/2 of a linear hall ic a1301k. I'm reading teeth of a gear that reaches maximum frequency of 1500 hz. The distance between the Hall and the gear is of 2 mm. The amplitude of the signal is low. At low rotation until about 300 hz I can make the perfect reading. Above this frequency I start to lose pulses and I do not have a correct reading.
I do not know if the problem is with the amplitude of the signal or with the reading speed of the input ad.
With code compiled in FREE mode is my processing speed lower or does it have no interference?

Ricardo

Re: Compiler Doubt

Posted: Thu Apr 13, 2017 8:53 am
by medelec35
Hi Ricardo,
I would not put it down to compiler.
You are polling an ADC input with an internal osc set to 1MHz.
That is the default start up frequency if not using a C code block with

Code: Select all

OSCCON = 0x70;
Since you have set clock frequency 8MHz there will be a mismatch!

Anyone starting a new project is always wise to start with a 1 second flasher test.

My advice is enable PLL so you can use internal oscillator at 32MHz.
Looking at the datasheet you will need to use

Code: Select all

OSCCON = 0x70;
which selects 8MHz internal oscillator.
Then you need to enable PLL (this will multiply osc speed by 4 = 32MHz) by setting

Code: Select all

 OSCTUNE PLLEN
This is done by

Code: Select all

set_bit(OSCTUNE,PLLEN);
Set your clock speed to 32MHz.
Finally use interrupt pin e.g INT0 on pin RB0 so it can detect the pulse rather than polling.
Take a look at this Wiki page
There is a link with examples for different types of interrupts.

Also for comparing polling with interrupts you could have a look here

Martin

Re: Compiler Doubt

Posted: Thu Apr 13, 2017 11:00 am
by RLOPES780
Hello Martin;

Thanks for listening;

The IC hall I am using is not logical but rather linear (following datasheet attached). Its output varies the voltage according to the magnetic field having as output a sine wave. That is why I am using the input adc. For this IC to work This way I put a magnet on its coast and the gear teeth rotate in front of the IC changing the magnetic field.
What happens is that at low frequencies I can read, but I can not read.
Can I send the photo of the gear and the sensor?
When the recommendations passed I added the code in c but gave compilation error. Can you help me?

Ricardo.

Re: Compiler Doubt

Posted: Thu Apr 13, 2017 11:52 am
by RLOPES780
Hello Martin;

How would the setup to work with the pic18f2423 with osc 32mhz internal?
I made a change in the code and attached it.
Would be like this?