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..
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);
}