I wrote a function for moving a servo motor for the XC-1A board. The function works but every time a change the position, the voltage level of the pin goes to the logical level HIGH for a certain amount of time causing an undesired rotation of the servo.
Here is a screenshot of the oscilloscope to explain better the situation:

Here is the code of my function:
Code: Select all
void servo_position(out port pwm_output, int usec_on) {
pwm_output <: 1;
delay_microseconds(usec_on);
pwm_output <: 0;
delay_microseconds(20000 - usec_on);
}
Code: Select all
void rotate_servo(chanend cmdS, out port pwm_output,
streaming chanend spf) {
int pos = 0;
pwm_output <: 0;
while (1) {
select
{
case cmdS :> pos:
pwm_output <: 0;
break;
default:
servo_position(pwm_output,pos);
break;
}
spf <: pos;
}
}

I don't understand why the pin goes HIGH for 500 ns. Any suggestion?