Speed Controllers - multirotor/Multirotor GitHub Wiki

To control a speed controller we create a PwmOut-object. Right now it supports the use of timers 3-5 of which each has 4 channels. This makes it possible to have 12 speed controllers connected and individually controlled simultaneously. It takes the following parameters:

PwmOut(uint32_t timer, enum tim_oc_id channel, uint32_t port, uint16_t gpio_pin, uint32_t frequency, uint16_t duty_cycle_ms)

Where:

timer - The timer of the Cortex M4 CPU that should be used. Timer 3-5 are supported.
channel - The output channel ascossiated with the given timer.
port - The GPIO-port where our output-pin is located.
gpio_pin - The GPIO-pin that is connected to the timer output channel.
frequency - The frequency in hertz.
duty_cycle_ms - The on duty cycle in microseconds.

#include "pwmout.h"
int main(void)
{
     PwmOut MotorA(TIM3, TIM_OC1, GPIOA, GPIO6, 488, 1060);
     PwmOut MotorB(TIM3, TIM_OC2, GPIOA, GPIO7, 488, 1000);
     PwmOut MotorC(TIM3, TIM_OC3, GPIOB, GPIO0, 488, 1060);
     PwmOut MotorD(TIM4, TIM_OC1, GPIOB, GPIO6, 488, 1060);
     PwmOut MotorE(TIM5, TIM_OC1, GPIOA, GPIO0, 488, 1060);
     while(1)
     {
          MotorA.set(1140); /* 10% Throttle */
          MotorB.set(1220); /* 20% Throttle */
          MotorC.set(1300); /* 30% Throttle */
          MotorD.set(1380); /* 40% Throttle */
          MotorE.set(1460); /* 50% Throttle */
     }
}

Two methods are available to interface the speed controller:

void set(uint16_t value) - Sets the duty cycle in microseconds.

uint16_t get() const - Gets the last set duty cycle in microseconds.