# How to stabilize adc output display on 7 segment

I am designing a simple voltmeter. I am using 8 bit ADC of PIC16F72 and Mikro C compiler with a multiplexed 7 segment display. I am getting ADC value on 7 segment display but its continuously fluctuating (for example 1670mV fluctuates in between 1660 & 1680mV). I have tried everything in hardware, adding a cap on ADC and ground etc.

Here is my code:

void StabilizeVoltage()
{
if (flgAC)
{
a= Voltage_FLOAT;
Voltage_INT=a;
//if(63<Voltage_INT && Voltage_INT<78 )
if(Voltage_INT <=1050 )
{
Relay1=0;
Relay2=0;
Relay3=0;
Relay4=0;
}
else if (1050<Voltage_INT && Voltage_INT<=1150)
{
Relay1=1;
Relay2=0;
Relay3=0;
Relay4=0;
}
else if (1150<Voltage_INT && Voltage_INT<=1350)
{
Relay1=1;
Relay3=1;
Relay2=0;
Relay4=0;
}
else if (1350<Voltage_INT && Voltage_INT<=1450)
{
Relay1=1;
Relay3=1;
Relay2=1;
Relay4=0;
}
else if (1450<Voltage_INT )
{
Relay1=1;
Relay3=1;
Relay2=1;
Relay4=1;
}
}
flgAC = 1;
}
void main()
{
InitIO();
InitTimer2();
InitDisplay();
while(1)
{
UpdateDisplay();
StabilizeVoltage();
}
}


Do I need any software filter ??

• You state that you tried 'everything', can you add a circuit diagram so we can see more clearly what you have so far? – jippie Aug 17 '14 at 14:59
• Is there a ~100nF cap across the power rails near the PIC power pins? – jippie Aug 17 '14 at 15:48

One possible software solution is the very simple to implement exponential moving average (http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average). It only requires one global variable and a few lines of code. It is a little more work to accomplish but this can also be done with fixed point code (ie. int) for much greater efficiency (I wouldn't worry about it if all your doing is reading an ADC and displaying it).

For example:

//K is the filter coefficient and must be smaller than 1 and greater than zero (0<K<1)
//The smaller the K is, the more the filter will smooth, but it will also take longer
//to reach its value when the input changes.
#define K 0.01f

{
static float memory;