View previous topic :: View next topic |
Author |
Message |
arawana
Joined: 06 Apr 2008 Posts: 19 Location: SINGAPORE
|
|
Posted: Tue Apr 22, 2008 8:35 am |
|
|
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
|
|
Posted: Tue Apr 22, 2008 8:49 am |
|
|
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
|
|
Posted: Tue Apr 22, 2008 9:01 am |
|
|
hehe~ still same.. u just remove the delay.. |
|
|
Matro Guest
|
|
Posted: Tue Apr 22, 2008 9:07 am |
|
|
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
|
|
Posted: Tue Apr 22, 2008 9:25 am |
|
|
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
|
|
Posted: Tue Apr 22, 2008 10:54 am |
|
|
but still cannot work.. can anyone help me? is there another way? |
|
|
arawana
Joined: 06 Apr 2008 Posts: 19 Location: SINGAPORE
|
|
Posted: Fri Apr 25, 2008 4:21 am |
|
|
still cannot work.. can anyone heLp~~ thanks.. |
|
|
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: 9243 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? |
|
|
|