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

problem with variable ADC & RC servo motor
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 1:16 pm     Reply with quote

Try this program. It uses the CCS servos.c driver file. When you turn
the trimpot (on pin AN1) to the right, the servo should go forward and
when you turn the trimpot to the left it should go in reverse. It only
has four speed steps in each direction. If this program doesn't work,
then I think you have a hardware problem, maybe with the connections
to the servo. I compiled this program with vs. 4.071 and looked at the
waveforms on pin B0 to check it.
Code:
#include <16F877.H>
#device adc=8
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define LEFT_SERVO_PIN   PIN_B0
#define RIGHT_SERVO_PIN  PIN_B1

#include <servos.c>

//=========================================
void main()
{
int8 value;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(1);

init_servos(); 


while(1)
  {
   value = read_adc();
   value = (int8)(value / 28.4);   // Get value in 0 to 8 range

//   printf("value = %u  ", value);

   if(value >= 4)  // Is it 4 to 8 ?
     {
//      printf("Forward %u\n\r", value -4);
      set_servo(LEFT,  FORWARD, value - 4);  // Go forward
     }
   else   // It's in 0 to 3 range.
     {
//      printf("Reverse %u\n\r", 4 - value);
      set_servo(LEFT, BACKWARD, 4 - value);  // Go reverse
     }

   delay_ms(500);

  }

}
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 9:10 pm     Reply with quote

ok its work Thanks~~

it not have many range.. I have to make it more range... so it can become more accurate and smooth.. can i?

actually i want to make a animtronic using potentiometer or flex force to control the RC servo robot movement..

but why I cannot use my coding?
nazri-malaysia
Guest







servo + sensor(IR sensor)
PostPosted: Wed Oct 22, 2008 2:19 pm     Reply with quote

Could somebody teach me how to create a program that combine servo motor and sensor?

- use pic16F877A,
- use 2 servo which is, left and right. It also can move straight, left and right.
- use 3 IR sensor which is left, right and front.

Test simulation on proteus 7 pro.

This project I call, self control robot.
I hope all my friends in this forum can help me.
Guest








PostPosted: Sat Feb 28, 2009 4:02 am     Reply with quote

Code:
while(1)
  {
   value = read_adc();
   value = (int8)(value / 28.4);   // Get value in 0 to 8 range

//   printf("value = %u  ", value);

   if(value >= 4)  // Is it 4 to 8 ?
     {
//      printf("Forward %u\n\r", value -4);
      set_servo(LEFT,  FORWARD, value - 4);  // Go forward
     }
   else   // It's in 0 to 3 range.
     {
//      printf("Reverse %u\n\r", 4 - value);
      set_servo(LEFT, BACKWARD, 4 - value);  // Go reverse
     }

   delay_ms(500);

  }

Hi, guys ... sorry, newbie here Sad This is my first project with C programming. I have 2 question regarding this code ...

1- how can I increase the resolution and speed ?
2- what is 28.4 ? How do I calculate it out.
MAKInnovation



Joined: 16 Nov 2010
Posts: 61

View user's profile Send private message

more servos.c driver ranges
PostPosted: Sat Nov 20, 2010 12:47 am     Reply with quote

How to get more ranges with servos.c built-in PCW compiler driver ?
SSR



Joined: 09 Nov 2011
Posts: 14

View user's profile Send private message AIM Address

PostPosted: Wed Dec 21, 2011 11:44 am     Reply with quote

Hi all.

Is there any method to continuously run servo for all the 360 degrees with variation in speed?

What i am doing is that, i am giving a 1.5 ms pulse after every 18.5 ms and it only moves to +90 degrees and remain there. How could i make it turn 360 degrees?
temtronic



Joined: 01 Jul 2010
Posts: 9112
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 21, 2011 12:43 pm     Reply with quote

Yes, you can get an RC hobby type servo to go 360*. You must tear it apart and modify it to allow it to go 360*. This obviously has nothing to do with PIC C programming so you're best to Google or consult with those in the RC hobby / robotics websites. It is a fairly easy modification.
Also you should read more about these servos and how they work to understand the timing vs. position information.
samuel



Joined: 04 May 2016
Posts: 14

View user's profile Send private message

PostPosted: Mon Aug 29, 2016 7:05 pm     Reply with quote

Code:

#include <16F877.H>
#device adc=8
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define LEFT_SERVO_PIN   PIN_B0
#define RIGHT_SERVO_PIN  PIN_B1

#include <servos.c>

//=========================================
void main()
{
int8 value;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(1);

init_servos(); 


while(1)
  {
   value = read_adc();
   value = (int8)(value / 28.4);   // Get value in 0 to 8 range

//   printf("value = %u  ", value);

   if(value >= 4)  // Is it 4 to 8 ?
     {
//      printf("Forward %u\n\r", value -4);
      set_servo(LEFT,  FORWARD, value - 4);  // Go forward
     }
   else   // It's in 0 to 3 range.
     {
//      printf("Reverse %u\n\r", 4 - value);
      set_servo(LEFT, BACKWARD, 4 - value);  // Go reverse
     }

   delay_ms(500);

  }

}

this is an awesome code. i tested it with the MG90S Tower pro servo and it works. However, it could turn only 90 degrees , what can i do on this code to achieve 180 degree rotation from 0 degree?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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