2
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

in pseudocode

// initialization
previous = ADC()
brightness = 0

process ADC:
   new = ADC()
      // must use towards-0 division!
      // divide-by-2 because each 1024/16 turn must give 32 steps
   delta = ( new - previous ) / 2   
   if( delta > 0 ):
      brightness = min( brightness + delta, maximum )
      previous = new
   if( delta < 0 ):
      brightness = max( brightness - delta, minimum )
      previous = new   
\$\endgroup\$
  • \$\begingroup\$ I think it worked: short delta = ( short ) ( ( *adc_value - adc_old_val ) * 10 ); if(delta > 0 ) brightness = (short)(min((brightness + delta), 1023)); if(delta < 0 ) brightness = (short)(max( 0, (brightness + delta))); Where multiplier 10 can be used to reduce the turns. Thanks. \$\endgroup\$ – Rick2047 Oct 3 '12 at 7:14
0
\$\begingroup\$

Assuming that your pot is linear, you could measure the rate of change. Then, increment (or decrement) your brightness level as some software function of the rate of change.

This way, you can make it so that your brightness more with faster turning.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.