Page 1 of 1

help with adc 12bit

Posted: Mon Oct 24, 2016 11:38 pm
by RLOPES780
I need a code with hysteresis 10 mv.
He needs to work well when reading adc is greater than 1.3 V my exit will be 1 and when the reading is less than 1.29 V my output will be 0. I'm reading a gear tooth with a hall and then I will have only two transition stages ( with tooth or toothless) and therefore need a hysteresis in changing stages .The difference of tension between tooth and tooth is not only 10 mv at the iC hall.
I'm using pic18f2423 with 12-bit ad converter and I'm using mcp1525 2.5 V to VREF +.
I Medelec help in the code that I am attaching .What is happening is that I'm simulating these tensions with a potentiometer and when I have the voltage below 1.29 V the output is okay. But when I raise output above 1.29 V to 1.30 V (my region hysteresis) the output is cycling and stabilizes only when it exceeds 1.33 V which should be 1.3 V. I do not know if I'm correct but my reference voltage is 2.5 V and the Resolution of the ad converter is 4095 then 2.5 / 4095 = 0.0006 which should differentiate the hysteresis 10 mv. It seems that the code is not this getting to understand the adc 12 bit if I'm correct. I am attaching the code for someone to help.

Grateful;

Ricardo

Re: help with adc 12bit

Posted: Tue Oct 25, 2016 8:37 am
by celebriums
Hello
You have to increase the resolution read.

LEI > 1.3000 and LEI<1.3000 must be

Re: help with adc 12bit

Posted: Tue Oct 25, 2016 5:37 pm
by Benj
Hello,
I do not know if I'm correct but my reference voltage is 2.5 V and the Resolution of the ad converter is 4095 then 2.5 / 4095 = 0.0006 which should differentiate the hysteresis 10 mv.
1.29V / 0.0006V = 2150
1.3V / 0.0006 = 2166

Your currently using GetVoltage which uses floating point maths. Probably much more efficient to ReadAsInt and then use integer maths and the values shown above. This would also get around rounding errors.

FRC is not a recommended conversion speed, maybe play around with this and the Aquisition cycles until your ADC readings are more stable.

Maybe Conversion Speeds of /8 or /16 or /32 and Aq Cycles 10 / 20.

Re: help with adc 12bit

Posted: Tue Oct 25, 2016 6:32 pm
by RLOPES780
Hello Benj.
Grateful for your attention.
My lower value is 1.29 = 2150.
My biggest value is 1/30 = 2166.
My hysteresis is 0.01 = 16.
But testing on real circuit the following happens:
The output is on until the voltage 1,325 and not 1,29.
Between 1,325 and 1.345 the output is pulsing. (?)
And above 1,345 the output is off and not worth 1.3.
It seems that the ad converter not solve this with 12 bits.
I have attached the code that you exemplified above is what mean?
I ask your help.

Grateful;

Ricardo.

Re: help with adc 12bit

Posted: Tue Oct 25, 2016 8:33 pm
by Benj
Hi Ricardo,

Check the ADC component properties regarding the following.
FRC is not a recommended conversion speed, maybe play around with the conversion speed and the Aquisition cycles until your ADC readings are more stable.

Maybe Conversion Speeds of /8 or /16 or /32
Aq Cycles 10 or 20.
12-bit ADC is going to pick up a lot of noise unless everything is very well designed and shielded, 10mV is not a lot of signal, could you use say an op amp to amplify this voltage to give you a better range?

Re: help with adc 12bit

Posted: Tue Oct 25, 2016 11:20 pm
by RLOPES780
Hello Benj.

I'm using a linear output hall IC and this is the maximum gain I could have.
I made the changes that you showed me and still remained the problem.
I put a potentiometer to simulate and increased the range of the hysteresis to 40 mv.
And it worked and 10 mv also did not work.
You have reason 10 mv is a very low level and still have the noise.
But it has to reach a conclusion.
I am very grateful for the help of you and I hope the Flowcode that already is good, keep getting better.
Grateful

Re: help with adc 12bit

Posted: Wed Oct 26, 2016 8:57 am
by medelec35
Hi Ricardo,
What about tying

Code: Select all

GetAverageInt
Instead of

Code: Select all

GetInt
?
That has helped me when there was ADC reading fluctuations and I wanted results to be as steady as possible.
Just start by entering a fairly high value for both E.g.250.

Martin