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

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
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 8:35 am     Reply with quote

result still same.. ADC change but the motor stay at 90deg..


if i put this code it work.. but without ADC.. u just call the function


Code:


void servo1_0(void)
{

   for (i = 0; i <50; i++)             // 0 deg
      {
         output_high (SERVO1);
         delay_us(450);
         output_low (SERVO1);
         delay_us(19550);
      }
}



void servo1_45(void)
{
  for (i = 0; i <50; i++)             // 45 deg
      {
          output_high (SERVO1);
          delay_us(1000);
          output_low (SERVO1);
          delay_us(19000);
      }
}



void servo1_90(void)
{
      for (i = 0; i <50; i++)             // 90 deg
      {
           output_high (SERVO1);
           delay_us(1500);
           output_low (SERVO1);
           delay_us(18500);
      }
}



void servo1_135(void)
{
     for (i = 0; i <50; i++)             // 135 deg
       {
            output_high (SERVO1);
            delay_us(2000);
            output_low (SERVO1);
            delay_us(18000);
       }
}



void servo1_180(void)
{
       for (i = 0; i <50; i++)             // 180deg
       {
            output_high (SERVO1);
            delay_us(2480);
            output_low (SERVO1);
            delay_us(17520);
      }
}

Matro
Guest







PostPosted: Tue Apr 22, 2008 8:49 am     Reply with quote

A last try before looking for other points :
Code:

#include <16F877A.H>
#device ADC=10
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#FUSES HS, NOWDT, NOPROTECT, BROWNOUT, NOLVP

#define servo1 PIN_b0  //pin 38

#BYTE ADCON0 = 0x1F

int16 ch1_result;
double ADC;
int i;

void main()
{
setup_adc_ports(ALL_ANALOG);     // SETTING ADC CHANNEL // A0 A1 A2 A3 A5 E0 E1 E2 Ref=Vdd
setup_adc(ADC_CLOCK_DIV_32);

while(1)
     {
         set_adc_channel(1);  //A1
         ch1_result = read_adc();
         ADC=ch1_result;
         printf("\f ADC: %3.2f",ADC);   
         for (i=0;i<50;i++)
         {
         output_high(SERVO1);
         delay_us(2000+ADC));//initial 0deg
         output_low(SERVO1);
         delay_us(3024-ADC)); //initial 0deg
         }
     }
}

Tell me about this one. ;-)

Matro
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 9:01 am     Reply with quote

hehe~ still same.. u just remove the delay..
Matro
Guest







PostPosted: Tue Apr 22, 2008 9:07 am     Reply with quote

arawana wrote:
hehe~ still same.. u just remove the delay..

No, I removed the right justification too.

Matro.
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 9:25 am     Reply with quote

Oo ic..

Last edited by arawana on Thu Apr 24, 2008 9:31 pm; edited 1 time in total
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 10:54 am     Reply with quote

but still cannot work.. can anyone help me? is there another way?
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 4:21 am     Reply with quote

still cannot work.. can anyone heLp~~ thanks..
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: 9241
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