View previous topic :: View next topic |
Author |
Message |
Aamir
Joined: 11 Apr 2010 Posts: 13
|
Analog to PWM controlling |
Posted: Sun Apr 11, 2010 2:19 pm |
|
|
I am working on a robotic structure using PIC16F877A and servo motors. There are 6 motors in all, controlling them all was not an issue. But one servo needs to be controlled via analog input which is creating a confusion.
So is there any help regarding controlling the servo (PWM) from analog input of PIC?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Aamir
Joined: 11 Apr 2010 Posts: 13
|
|
Posted: Sun Apr 11, 2010 2:48 pm |
|
|
Well I guess I have been through this code, but the problem is would I be able to provide PWM on all 6 motors simultaneously? Right now what I have done is to provide a high signal, delay, a low signal and delay such that it makes 50Hz of desired duty cycle. And somehow I managed to code them in such a way that all motors are working in 'simultaneously'.
Now the issue is will this CCP1 effect in my programming? |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Sun Apr 11, 2010 2:56 pm |
|
|
PCM programmer, I think that Aamir wants to control RC servo, not an usual PWM.
For RC servo, do a little search here on forum it was quite some topics written on the subject. For RC servo you need to send 50Hz pulses with this specifics: pulse length (on time) must be from ~1ms to 2ms and the rest ~19ms is off time.
Depending on pulse width the servo position will be, generally 1ms is full left, 1.5ms is middle and 2ms is full right .... this times will vary depending on manufacturer.
So what you need to do is to convert your analog input to different pulse "delays" |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Aamir
Joined: 11 Apr 2010 Posts: 13
|
|
Posted: Mon Apr 12, 2010 2:46 pm |
|
|
Yes exactly, I am working on RC servos. But here is what I am currently doing.
I have 6 motors, all will operate in predefined movements. But one motor (actually the gripper for robotic arm) must move as per the input of force sensor (analog input).
Now what I need is to control the positions of this motor without using CCP pins, as they may cause the other operations to with held while I am providing pulses to all 6 motors.
To make things more clear I want this work done by PIC, rather than 555 Timer
http://www.youtube.com/watch?v=u8vr6nMSh80
But please I want a solution without using CCP as it may disturb my other motors process, or not?? |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Tue Apr 13, 2010 6:52 am |
|
|
I don't see how this is a big problem. You start the A/D at some point in the 1/50 sec cycle, maybe when one of the other servos starts its pulse. You grab the result of the A/D and turn it into a pulse width for the 6th servo, maybe ahead of time or maybe at the last moment when servo 6 starts its pulse. But servo 6 just operates the same way as the other 5. Have I missed something here? |
|
|
Aamir
Joined: 11 Apr 2010 Posts: 13
|
|
Posted: Tue Apr 13, 2010 1:14 pm |
|
|
well here is what i am doing
Code: | #include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#bit grey=7.0
#bit orange=7.1
#bit yellow=7.2
#bit white=7.3
#bit blue=7.4
#bit green=7.5
void main (void)
{
set_tris_c(0);
while(1)
{
do
{
grey=orange=yellow=green=white=blue=1;
delay_us(1500);
grey=0;
delay_us(100);
orange=yellow=0;
delay_us(100);
white=0;
delay_us(100);
green=0;
delay_us(100);
blue=0;
delay_us(18100);
}while(!input(PIN_E1));
}
}
|
'green' is the motor i want to stop in accordance with ADC input.
can anyone help me out in this?? |
|
|
|