PDA

View Full Version : how to get an analog potentiometer to settle down?



keithv
- 31st August 2016, 23:41
I'm working on a project that uses the ADC to read an analog potentiometer. It's causing problems for me when the voltage on the ADC fluctuates slightly. Like when the voltage it's reading is 2.4955V and the ADC can't make up its mind whether it's 2.49V or 2.5V. Is there a way to make the voltage settle down?

keithv
- 31st August 2016, 23:42
Can I decrease the resolution of the ADC?

towlerg
- 31st August 2016, 23:51
or just round the output .

keithv
- 31st August 2016, 23:57
or just round the output .

How do I do that? Is there a command line that will round up or down?

CuriousOne
- 1st September 2016, 05:56
Yes, there is such command, but I don't remember it's name, check the manual, it was something like I=I<<I or whatever.

HenrikOlsson
- 1st September 2016, 06:09
If you DEFINE ADC_BITS 8 it will grab the 8 high bits of the 10bit result from the ADC, you'll leave the noise in the lower two bits but at one point or another you're still going to be on the edge where the 3rd bit is flipping back and forth and you're back at square one.

You can always take multiple samples and average them to smooth things out a bit.

/Henrik.

Aussie Barry
- 1st September 2016, 09:00
Try adding a bit of capacitance from the wiper of the pot to ground - say 100nF.
This should minimise some of the variations you are experiencing.

Cheers
Barry
VK2XBP

Dave
- 1st September 2016, 11:51
KeithV, You could always low pass filter the A/D reading if you are not requiring the responce speed. If you require the speed then just read the A/D faster. Something like this:

FILTG CON 32 'FILTER CONSTANT (255 = NO FILTER, 1 = MAXIMUM FILTER)

VOUT VAR WORD 'FILTER HISTORY

LOWPASS: '------------------- LOW PASS FILTER --------------------------
VOUT = VOUT - (VOUT */ FILTG) + A_D_READING
FILTERED_VOLTAGE = VOUT */ FILTG 'FINAL FILTERED OUTPUT COMPUTED
RETURN

I use something similar to it all the time....

Art
- 1st September 2016, 15:41
How do you have the 2.4955V in memory? Is that a word? Because that wouldn’t give you much range past 6 Volts.

You can keep the resolution and take the mean of the last n readings if you can calculate it, which you probably can.
The larger n is, the less responsive your potentiometer is, at least “apparently”,
but the smaller the fluctuation you see, the easier it is to pad out.

If you’re going to blow out a variable used to calculate the mean, you can add and divide small groups of variables
to arrive at a new smaller group of variables, and work down to one number that way.

Heart rate monitors at least used to do this because the interface to the body, and radio between the chest sensor and device was so clumsy.

keithv
- 1st September 2016, 20:17
I tried adding a cap to ground off the wiper. That seemed to help a tiny bit, but not much.

I had the same idea about sampling and averaging in the shower this morning. Unfortunately, I haven't had a chance to try it yet. I'm using a 16F676 which only has 1023 words of program memory, and I've already been "trimming the fat" to get what I've already got working on there. I need to use a PDIP14, so my options are limited. I just ordered some 16F616, so that should give me twice the memory.

HenrikOlsson
- 2nd September 2016, 07:48
There's plenty of modern options in 14 pin packages.
16F1503 is pin compatible, has twice the amount of flash and twice the amount of RAM and costs less than 16F630.
If you need even more then 16F1507/8/9 are all "the same", just more flash and RAM.

Plenty of other to choose from as well.

/Henrik.

keithv
- 2nd September 2016, 19:01
I haven't tried the sampling/averaging fix yet. I'm having some trouble with the new 16F616. With the 16F676, the only problem I had was with the pot not wanting to settle. Now, there's all kinds of problems with the 16F616. It seems like the primary difference between the two chips are the comparators. I'm a little confused by the differences between the 16F676's CMCON register and the 16F616's CM1CON0 and CM2CON0 registers. Seems like if I want CM1CON0 to be configured the same as CMCON = %00000111, I would write it as CM1CON0 = %00000000, but the last 2 bits are a little confusing to me. Do I need to configure both the CM1CON0 and CM2CON0 registers?

Also, could the way I have ADCON1 configured be causing trouble? Seems like FOSC2 is what I want. Faster is better, right?

Below is the configuration section of my code for the 16F616. Sorry for so many questions. I'm still pretty new to this.



#config
__CONFIG _CP_OFF & _WDTE_OFF & _BOREN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
#endconfig


ADCON1 = %00000000
ANSEL = %00000110
CM1CON0 = %00000000 'program worked previously with 16F676 CMCON = %00000111

TRISA = %00001111
TRISC = %00000000

' Set TMR0 to interrupt every 16.384 milliseconds
OPTION_REG = %10000101 ' Set TMR0 configuration and enable PORTB pullups
INTCON = %10100000 ' Enable TMR0 interrupts
On Interrupt Goto tickint