Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Software PWM ( Servo driver)

Status
Not open for further replies.

Hero.sl

New Member
Hey guyz need a little help..
Im writting a software PWM to drive a Turnigy micro servo using PIC16F628A.
Port b is connected to the Parallel port of my PC which I programmed to output 0 - 100. The code is written in CCS C and has no errors. Well the servo rotates according to the input, but there is a vibration once I stop changing the input(for a constant input).

Does any one know what is wrong with the code? I dont have much experience with PIC programming. So if you guyz have a better way to code a sw pwm, please let me know.
btw Im planning to use this program to drive an ESC (connected to a Towerpro BLDC) once im done testing. Will I be able to use it with ESC? are there any changes that I have to make?
Thanks in advance..

int16 high_time=0;

void read_port_b()
{
while(true)
{
high_time = ( input_b() * 10L ) + 1000L; // 1000us to 2000us
}
}

void main()
{

setup_oscillator(OSC_4MHZ);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);

set_tris_a(0x00);
set_tris_b(0xFF);


enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
disable_interrupts(INT_RB);

output_a(0xFF); // Test LED {
delay_ms(1000L);
output_a(0x00);
delay_ms(1000L);
output_a(0xFF);
delay_ms(1000L);
output_a(0x00); // }

set_timer0(100); // initial duty
output_a(0xFF);
delay_us(high_time);
output_a(0x00);

read_port_b();
}



#INT_TIMER0
void Timer0_ISR()
{
disable_interrupts(GLOBAL);
set_timer0(100);
output_a(0xFF);
delay_us(high_time);
output_a(0x00);
clear_interrupt(INT_TIMER0);
enable_interrupts(GLOBAL);
}
 
Are you using a digital or analog servo? Some digital servos are known to chatter when put into a set position. Swap in an analog servo and see if the "vibration" still happens. John
 
Are you using a digital or analog servo? Some digital servos are known to chatter when put into a set position. Swap in an analog servo and see if the "vibration" still happens. John

thanks for your reply John. Itz a digital servo. I think this problem has some thing to do with input_b() function or with the multiplication. I changed the code to increase the duty cycle and decrease it without using the input from PC, then it works fine. No vibration. Any idea?
 
I have no experience with using a PC to control a servo. My suggestion related to the digital servo was based on experience with cheap servo controllers. For example, the early versions based on the 555 chip worked fine with analog servos, but digital ones tended to chatter. When I have used a 12F5xx PIC as a servo controller, both analog and digital worked fine. Your experience using just the PIC is consistent with that observation.

Unfortunately, I can't help you on the PC interface. To confirm that is really the problem, get a general purpose analog servo. If it doesn't chatter, then at least you know where to look for the problem. Those general purpose ("standard") servos typically came packaged with transmitter/receiver sets. Hitec HS300, Futaba S148, and Airtronics 94102 are examples. They are inexpensive when new (<$15) and even cheaper when used. If you were near Cleveland, the only thing I would ask is "how many?" :D Most modelers would probably give you one, or your local hobby shop might let you borrow a display unit.

John
 
I think I just found out what is wrong here..
Itz the multiplication. When I disabled interrupts during the multiplication part,it is working fine.

void read_port_b()
{
while(true)
{
portVal = (int16) input_b();
disable_interrupts(INT_TIMER1);
high_time = ( portVal * 10L ) + 1000L;
enable_interrupts(INT_TIMER1);
}
}

But I think now the frequency is varying. Is there a way to correct it?

can pics queue interrupts? :confused:
 
I have no experience with using a PC to control a servo. My suggestion related to the digital servo was based on experience with cheap servo controllers. For example, the early versions based on the 555 chip worked fine with analog servos, but digital ones tended to chatter. When I have used a 12F5xx PIC as a servo controller, both analog and digital worked fine. Your experience using just the PIC is consistent with that observation.

Unfortunately, I can't help you on the PC interface. To confirm that is really the problem, get a general purpose analog servo. If it doesn't chatter, then at least you know where to look for the problem. Those general purpose ("standard") servos typically came packaged with transmitter/receiver sets. Hitec HS300, Futaba S148, and Airtronics 94102 are examples. They are inexpensive when new (<$15) and even cheaper when used. If you were near Cleveland, the only thing I would ask is "how many?" :D Most modelers would probably give you one, or your local hobby shop might let you borrow a display unit.

John

Thanks John..
Have no much experience with Analog servos and Im just using a little ($3 :D) servo just to check the app before I connect it to the ESC. Guess im ready to go..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top