|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 25, 2008 1:16 pm |
|
|
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
|
|
Posted: Fri Apr 25, 2008 9:10 pm |
|
|
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) |
Posted: Wed Oct 22, 2008 2:19 pm |
|
|
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
|
|
Posted: Sat Feb 28, 2009 4:02 am |
|
|
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 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
|
more servos.c driver ranges |
Posted: Sat Nov 20, 2010 12:47 am |
|
|
How to get more ranges with servos.c built-in PCW compiler driver ? |
|
|
SSR
Joined: 09 Nov 2011 Posts: 14
|
|
Posted: Wed Dec 21, 2011 11:44 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Dec 21, 2011 12:43 pm |
|
|
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
|
|
Posted: Mon Aug 29, 2016 7:05 pm |
|
|
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? |
|
|
|
|
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
|