hi there,
I have 4 rotary type variable resistors each attached to one of the
ADC channel of an atmega8 (PC5-PC2).
An unsigned integer array of size 4 named as "min" holds the minimum ADC value for each of the resistors (i.e when resistance is maximum)
similarly an unsigned integer array of size 4 named as "max" holds the maximum ADC value for each of the resistors (i.e when resistance is minimum)
Both of above are measured during runtime.
The problem arises under following case
4 LEDs are set to glow when respective resistor's ADC value crosses the minimum value.
but here only three of the LEDs glow when min their repective min value is crossed while the 4th one one takes much higher ADC value than minimum measured for it to glow (almost maximum)!
why does it happens so ?
again to cross check my circuit I set the LEDs to glow when the ADC value is more than mid of min and max values (syntactically (max+min)/2)
this time it works correctly and the LED glows after its respective ADC value reaches midway
also If I specifically set only the 4th LED to glow when the ADC value of its associated resistor goes above half of the min value then it glows after ADC has crossed about 1/4th of min to max
how is this possible ? why there is such anomalous behaviour?
here are code snippets
I have 4 rotary type variable resistors each attached to one of the
ADC channel of an atmega8 (PC5-PC2).
An unsigned integer array of size 4 named as "min" holds the minimum ADC value for each of the resistors (i.e when resistance is maximum)
similarly an unsigned integer array of size 4 named as "max" holds the maximum ADC value for each of the resistors (i.e when resistance is minimum)
Both of above are measured during runtime.
The problem arises under following case
4 LEDs are set to glow when respective resistor's ADC value crosses the minimum value.
but here only three of the LEDs glow when min their repective min value is crossed while the 4th one one takes much higher ADC value than minimum measured for it to glow (almost maximum)!
why does it happens so ?
again to cross check my circuit I set the LEDs to glow when the ADC value is more than mid of min and max values (syntactically (max+min)/2)
this time it works correctly and the LED glows after its respective ADC value reaches midway
also If I specifically set only the 4th LED to glow when the ADC value of its associated resistor goes above half of the min value then it glows after ADC has crossed about 1/4th of min to max
how is this possible ? why there is such anomalous behaviour?
here are code snippets
Rich (BB code):
//taking min values
for(int i=1;i<5;i++)
{
min[i-1]=getADC(i);//getADC returns ADC value for i+1 th channel
}
//similar for max
Rich (BB code):
//check ADC value
for(short i=1;i<5;i++)
{reading[i-1]=getADC(i);
if(reading[i-1]>min[i-1])
{ledSelective(i,1);}
else
{ledSelective(i,0);}
//led Selective glows up LED for resistor i
Rich (BB code):
//check against mid way value (WORKING ONE)
for(short i=1;i<5;i++)
{reading[i-1]=getADC(i);
if(reading[i-1]>((max[i-1]+min[i-1])/2))
{ledSelective(i,1);}
else
{ledSelective(i,0);}