Right now I am using 4 of the PwmOut pins to drive my motors at 20khz each. The problem is that I also need to control a servo which has a frequency of 50hz and since all of the PwmOuts share the same period, I am forced to software generate the servo control pwm or do it through some other means.
Here's what I tried before but it seems to consume too much cpu time, thereby interfering with the rest of the program.
DigitalOut pwm(p15);
Ticker t;
void generatePWM(){
if (count++ < DUTY_CYCLE)
pwm = 1;
else
pwm = 0;
if (count < 200)
count = 0;
}
int main(){
t.attach_us(&generatePWM, 100);
}
Basically I need to generate a pulsewidth of .4-2.4ms with a period of 20ms. Does anyone have a good way of doing this?
Thanks
Right now I am using 4 of the PwmOut pins to drive my motors at 20khz each. The problem is that I also need to control a servo which has a frequency of 50hz and since all of the PwmOuts share the same period, I am forced to software generate the servo control pwm or do it through some other means.
Here's what I tried before but it seems to consume too much cpu time, thereby interfering with the rest of the program.
Basically I need to generate a pulsewidth of .4-2.4ms with a period of 20ms. Does anyone have a good way of doing this? Thanks