Wireless servo controller II

servo_headerWe described simple method, how to drive modellers servo. Today, we are going to try to drive this servo from potentiometer connected to TR module ADC. It is reaction to forum thread where is discussion about airplane model control possibility.

We are going to use redesigned ADC usage example (sensor module source code) in this way:


while(1)
{	
    //clrwdt();
    waitDelay(5);				
    ReadAnalogInput();
		
    voltage = ADC_result / 4;    //10b to 8b
    voltage = voltage * 181;     // 181/256 = aprox. 0.707031
    bufferRF[0] = 'S';
    bufferRF[1] = voltage.high8 + 70;	
			
    PIN  = 0;
    DLEN = 2;
    RFTXpacket(); 	
}

Our servo is driven by values in range from 70 to 250. So we need convert 10bit ADC output to 8bit number in this range. It may be done by:

  1. voltage = ADC_result / 4 → we will get 8bit number. (or we can set ADC to 8bit)
  2. Convert 8bit number (voltage) to range 70-250. I may be done by formula: (voltage*0.707031)+70 it is the same as (voltage*181/256)+70.
  3. If we use only high8 byte of voltage variable, it is same as division by 256.

Full source code is available at the end of article.

It seems, that reaction time is enough, as you can see in following video.

Enjoy.

Download Attachments

  • c C12-SE-DIW2.zip
    ADC2Servo sensor source code
    File size: 2 kB Downloads: 307

Leave a Reply

Your email address will not be published. Required fields are marked *