CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Servo Position Test Box for Robotics

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

Servo Position Test Box for Robotics
PostPosted: Fri Jan 23, 2015 6:19 am     Reply with quote

This is a handy tool for your robotics work. It allows you to turn a knob on a pot and adjust the servo pulse output from .5 to 2.5mS, more than enough for the full range of servo movements. The LCD display is a Scott Edwards type and displays four digits of about 10 bit resolution on the pulse width. Very handy since you can use this exact number for a micro controller in a robot or other project to set it in that same spot

I have posted a write up with schematics on my web page as well, for furthur info.

http://www.schursastrophotography.com/PICprojects/Servo011415.html


Code:
//****************************************************************************
//Chris Schur
//Servoboard Knob test box:  12F675
//Date:  1/4/15
//****************************************************************************
/*Description of this Program: This program Will take the push button controlled
servo test board, add a pot and use that instead to vary the pulse output from
.5ms to 2.5ms
*/

//I/O Designations ---------------------------------------------------
// A0 (GPIO0):  (An0) POT INPUT
// A1 (GPIO1):  (An1) LCD & LED OUT
// A2 (GPIO2):  (An2) SERVO PULSE OUTPUT -or- LCD OUT
// A3 (GPIO3):  X (can ONLY be input)
// A4 (GPIO4):  XTAL OUT (An3)
// A5 (GPIO5):  XTAL IN

//--------------------------------------------------------------------
//Include Files:
#include <12F675.h>  //Normally chip, math, etc.  used is here.
//Directives and Defines:
#device ADC=10  //This directive will only work if put RIGHT HERE first...
#fuses NOPROTECT,NOMCLR
#use delay(crystal=10MHz)
#use fast_io(A)
#use rs232(baud = 9600, xmit=Pin_A1, bits=8, parity=N, INVERT, stream = SERIAL)

//****************************************************************************
//Global Variables:
//******************************************/
   
//Functions/Subroutines, Prototypes:


//****************************************************************************
//-- Main Program
//****************************************************************************
void main(void) {
   // Set TRIS I/O directions, define analog inputs, compartors:
             
        set_tris_A(0b101001);  //sets port directions
       
        //(analog inputs digital by default)
        setup_adc_ports(sAN0);
        setup_adc(ADC_CLOCK_DIV_32);
        set_adc_channel(0);
           
   //Initialize variables and Outputs:  --------------------------------------
   
    int16 result; //0 - 1023 out of ADC
    int16 on_pulse;   //servo high pulse width in uS
    output_low(PIN_A1);   //turn off status led
   
   //----------------------------------------------------------------
//MAIN LOOP:
while (true)  {
    //First read ADC
    result = read_adc();
   
    //calculate pulse width:
    on_pulse = (2*result) +500;    //for a range of .5mS to 2.5mS
   
    //next send pulse to servo output:
   
    output_high(PIN_A2); //servo out = 1   
    delay_us(on_pulse);  //high time
    output_low(PIN_A2);  //turn off pulse   
   
    delay_ms(4);        //space between pulses=20 with lcd serial delays
    fputc(12,SERIAL);    //Clear screen
    delay_ms(1);
    fprintf(SERIAL,"%Lu"on_pulse);
    delay_ms(1);
    fputs(" uS",SERIAL);
    delay_ms(2);
   
   }
   
}
//********* Functions which have prototypes at top of program ****************
   
 
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group