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 support@ccsinfo.com

Help with Servo Motors: Control of Servo Motor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MastaMoose



Joined: 07 May 2009
Posts: 3

View user's profile Send private message

Help with Servo Motors: Control of Servo Motor
PostPosted: Sat May 09, 2009 5:06 pm     Reply with quote

hi, i am new to both this forum and PIC programing in general. I am using:
-CCS PCM compiler
-2 PIC 16F877
-MPLAB 8.30

So my problem is that i want to control a servo motor, "remotely." What this means is that i want to have two PICs (as mentioned above) that will correspond serially.

Also, the first of said PICs is connected to a potentiometer and will serially transmit the digital data to the second PIC. The second PIC is charged with converting the digitally recieved data to produce a pulse train that will drive a servo motor.

The problem is that my code is sending, and recieving everything okay, but the servo motor does not move. I am sure of the specification however, meaning i am sure that the last code snippet that generates the pulse works on its own when interfaced with a pot through a single chip, but does not work when one chip is input and the other is output.
_________________
Masta Moose


Last edited by MastaMoose on Sat May 09, 2009 5:08 pm; edited 1 time in total
MastaMoose



Joined: 07 May 2009
Posts: 3

View user's profile Send private message

Continued with code
PostPosted: Sat May 09, 2009 5:07 pm     Reply with quote

Here is my code:

Thus I wish to implement potentiometer controller servo motor. The code is as follows:

SENDER CODE:
Code:

//Takes pot input and converts it and then sends it out serially
//****************************************************
//****************************************************         
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#define ADC = 8
#use rs232 (baud=9600, xmit=pin_c6,rcv=pin_c7, parity=N)

//This is the main function
/*****************************************************/
/*****************************************************/
void main ()
{
     //This is the code to setup the ADC stuff
     int A2D_Value = 0;
     SET_TRIS_B ( 0x00 );
     setup_adc_ports ( RA0_ANALOG );
     setup_adc ( ADC_CLOCK_INTERNAL );
     set_adc_channel ( 0 );
     DELAY_MS(10);
     
     //now we are going to send the A2D value of the input serially
         
     while(1)
     {
        A2D_Value = read_adc(ADC_START_AND_READ);     
        putc(A2D_Value);
     }
}


RECEIVER CODE:
Code:

//This code takes the serially transmitted Digtal value and generates a //pulse to control a servo motor
/**********************************************************/
/*********************************************************/

#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#define ADC = 8
#use rs232 (baud=9600, xmit=pin_c6,rcv=pin_c7, parity=N)

char timed_getc()
{ //this i changed from char to int
   long timeout;
   timeout=0;
   while(!kbhit()&&(++timeout<50000)) // 1/2
   delay_us(10);
   if(kbhit())
   {
      return(getc());
   }
   else
   {
      return(0);
   }
}

void main()
{
   char value;   
   float value2;
   long x;
   {
      while (TRUE)
      {
        while(!kbhit());
        set_tris_D (0X00);
      value=timed_getc();
        value2=value;
      x = 1250 + (500*value2/256);
        OUTPUT_D (0b11111111);
        DELAY_US(x);
          OUTPUT_D (0b00000000);
          DELAY_US(20000-x);
     }
   }
}

_________________
Masta Moose
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat May 09, 2009 5:20 pm     Reply with quote

Try to put some delay between two transmissions.

And did you try to send fixed values to other pic and did the servo react?

I posted a multi servo code here on forum. You could adapt this code to your needs. The way you are doing it is putting PIC on delay all the time Wink
MastaMoose



Joined: 07 May 2009
Posts: 3

View user's profile Send private message

PostPosted: Sun May 10, 2009 10:32 am     Reply with quote

okay i tried puting a delay of 20 milliseconds after the sending code and the servo started reacting but i only got a quarter of the range. I will have to check it more on monday when i get back to the lab. So i will update this on monday. Thank you for your help.
_________________
Masta Moose
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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