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

Generating PWM for Servo Motor Application PIC18F

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








Generating PWM for Servo Motor Application PIC18F
PostPosted: Sun Mar 22, 2009 4:50 pm     Reply with quote

Hello all,

I'm working on a motor project and I need some help debugging some code. I am fairly new with the microcontroller world in general, so I apologize in advance if I don't understand the full ins and outs.

I am using a Parallax (Futaba) Continuous Rotation Servo .

Right now I'm just trying to generate a 20ms duty cycle to drive a continuous rotation servo motor. It is my understanding that if you feed the servo a 20ms duty cycle with a width of 1.0 - 2.0 ms of high time, the position of the servo can be controlled. Now I've calibrated the potentiometer of the servo to the neutral position using a 1.5 ms / 20ms signal.

I expect that a 2.0 ms pulsewidth should drive the servo +180 degrees (?). However, upon generating a single pulse the servo rotates barely 5-10 degrees. I observed the pulse on an oscilliscope and I indeed am generating a 20 ms duty cycle with 2.0 ms width. If someone could help me, maybe suggest some alternative way or provide an explanation of why this is happening I'd greatly appreciate it.

------------------------------------------------------Servo Code
Code:

#include <18F4431.H>
#fuses HS, NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define carr1 PIN_B0

long carr1pulse=5*50*16;   //2000 us pulse
long carrDuty=5*50*170;    //17,000 us (Accomodates error)
int carrSignal=0;    

#INT_TIMER1
void CarriageTimerISR() {
   switch(carrSignal)
   {
      case 0:
      {
         set_timer1(65536-carr1pulse);                 
         output_high(carr1);
         carrSignal++;
      }
      break;
      
      case 1:
      {
         set_timer1(65536-carrDuty-carr1pulse);
         output_low(carr1);
         carrSignal++;
      }   
      break;         

      case 2:
      {
             disable_interrupts(INT_TIMER1);
      }   
      break;      
}

void main()   {
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);   // setup interrupts

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);


   while(1);                              // loop forever
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 23, 2009 1:20 pm     Reply with quote

Parallax has a forum. Read this discussion on how long the continuous
rotation servo will spin if it receives just one pulse. Look about halfway
down the page:
http://forums.parallax.com/forums/default.aspx?f=10&m=4769
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