My question perhaps belongs to general ability test or something like that. It is not directly related to Embedded devices.
I have been given a variable resister which can rotate infinitely and is of 10kΩ. ADC is set for value range 0 to 1023 sampling. By which I've to control light luminosity/intensity.
The ADC value range is divided into 32 steps for 1024/32 levels of brightness. The issue is the pot has to be rotated 16 times to get to extremities. Which is very harassing. Now its time when I can't change the pot hardware but the firmware.
I thought of doing as follows, please help me from here:
I'll choose a range window within the [0 1023], say of 32 steps. Lets ignore the ADC noise for now.
Then we have 32 steps in that 32 step windows.
If I start from 0, the intensity will be increasing till 32. The 32 is max intensity possible. Then if I rotate more, the intensity should remain maximum at 32 all the way till 1023.
And as soon as it is started to decrease from 1023, I will have decrease in intensity till ( 1023-32 ) and will remain at 0 intensity all the way till 0.
if I rotate back from any place it should follow the above explained moving window rule. How to start with it?
I did as follows:
void processADC_data()
{
ushort adc0 = (ushort)ADC_DATA;
adc0_Avg = adc0;
// If Noise
/*
ushort adc0_L = (ushort)(adc0 - 40);
ushort adc0_H = (ushort)(adc0 + 40);
adc0 = (ushort)read_ADC( adc0_L,adc0_H );
adc0_Avg = adc0 * 20 + adc0_Avg * 80;
adc0_Avg /= 100;
*/
IsInceasing = (adc0_last - adc0_Avg) < 0 ;
adc0_last = adc0_Avg;
if (IsInceasing)
{
// Extrimity has to be handled
if (!HasPerformedIncreased)
{
adc0_center = (ushort)(adc0_Avg - window);
HasPerformedIncreased = true;
HasPerformedDecrease = false;
}
else if (HasPerformedIncreased)
{
IsCrossingLimit = ( (adc0_Avg - adc0_center) > window );
if(IsCrossingLimit)
{
adc0_Avg = LIGHT_SENS_MAX;
IsCrossingLimit = false;
}
else
{
adc0_Avg = (ushort)(adc0_Avg / LIGHT_SENS_MAX);
}
}
//judge_brightness(adc0_Avg);
}
else
{
// Extrimity has to be handled
if (!HasPerformedDecrease)
{
adc0_center = (ushort)(adc0_Avg + window);
HasPerformedDecrease = true;
HasPerformedIncreased = false;
}
else if (HasPerformedDecrease)
{
IsCrossingLimit = ( (adc0_center - adc0_Avg) > window );
if(IsCrossingLimit)
{
adc0_Avg = LIGHT_SENS_MIN;
IsCrossingLimit = false;
}
else
{
adc0_Avg = (ushort)(adc0_Avg / LIGHT_SENS_MAX);
}
}
}
brightness(adc0_Avg);
}
Thanks