BaseFlight PWM - FabLabSeoul/WingProject GitHub Wiki

์ด ๊ธ€์€ ์˜คํ”ˆ ์†Œ์Šค Baseflight ํ”„๋กœ์ ํŠธ ์†Œ์Šค๋ฅผ ๋ถ„์„ํ•œ ๊ธ€์ด๋‹ค.

์˜ˆ์ œ ์†Œ์Šค๋Š” STM32\stm32vldiscovery_package\Project\Examples\PWM_Baseflight ๊ฒฝ๋กœ์— ์žˆ๋‹ค.

PA10,9 (Rx,Tx) ์€ USART ํฌํŠธ๋กœ ์‚ฌ์šฉ๋˜๋ฉฐ, ๋””๋ฒ„๊น…์šฉ printf() ํ•จ์ˆ˜๋ฅผ ์œ„ํ•ด ์“ฐ์ธ๋‹ค. PA8 ์—์„œ ์„œ๋ณด์šฉ 50Hz PWM ์‹ ํ˜ธ๊ฐ€ ๋‚˜์˜จ๋‹ค. ์˜ˆ์ œ์—์„œ๋Š” Servo ๋ชจํ„ฐ๋ฅผ -90 ~ +90 ๋„ ์‚ฌ์ด๋ฅผ ์˜ค๊ฐ€๊ฒŒ ํ•œ๋‹ค.

Baseflight์˜ PWM ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” drv_pwm.h, drv_pwm.c ๋กœ ๊ตฌ์„ฑ๋˜์ง€๋งŒ, drv_timer.c, drv_timer.h ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ์žˆ์–ด์•ผ ๋™์ž‘ํ•œ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ PWM์€ ํƒ€์ด๋จธ์™€ ๊ฐ™์ด ๋™์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

typedef struct {
    volatile uint16_t *ccr;
    volatile uint16_t *cr1;
    volatile uint16_t *cnt;
    uint16_t period;

    // for input only
    uint8_t channel;
    uint8_t state;
    uint16_t rise;
    uint16_t fall;
    uint16_t capture;
} pwmPortData_t;
  • pwmPortData_t ๊ตฌ์กฐ์ฒด
    • ์‚ฌ์šฉ ์ค‘์ธ PWM ํฌํŠธ์˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค. ์ •ํ™•ํžˆ ๋งํ•˜์ž๋ฉด, ํฌ์ธํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๊ณ , ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • baseflight๋Š” ๋ฏธ๋ฆฌ ์ •ํ•ด์ง„ PWM1 ~ PWM14 ํฌํŠธ ์ค‘ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด ์ž…๋ ฅ์šฉ๊ณผ ์ถœ๋ ฅ์šฉ์œผ๋กœ ํฌํŠธ๋ฅผ ์„ค์ •ํ•œ๋‹ค.
  • ๊ฐ๊ฐ์˜ PWM1~14 ํฌํŠธ๋งˆ๋‹ค GPIO ์™€ Pin, Channel์ด ๊ฒฐ์ •๋œ ์ƒํƒœ๋‹ค. ๊ทธ๋ž˜์„œ ์–ด๋–ค PWM์„ ์“ธ๊ฑด์ง€๋งŒ ๊ฒฐ์ •๋˜๋ฉด, ๋‚˜๋จธ์ง€๋Š” ์ž๋™ํ™”๋˜๊ฒŒ ์„ค๊ณ„๋˜์—ˆ๋‹ค.
    • const timerHardware_t timerHardware[];

pwmInit() ํ•จ์ˆ˜์—์„œ ๋ฏธ๋ฆฌ ์ •ํ•ด์ ธ์žˆ๋Š” multiPPM, multiPWM ๋ฐฐ์—ด๋กœ PWM ํฌํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์ด ๋•Œ gps ๋‚˜ adc ์šฉ์œผ๋กœ ํฌํŠธ๊ฐ€ ์“ฐ์ธ๋‹ค๋ฉด, ํ•ด๋‹น PWM ํฌํŠธ ๋„˜์–ด๊ฐ€๊ณ  ๋‹ค์Œ PWM ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์ตœ๋Œ€ PWM14๊นŒ์ง€ ์“ธ์ˆ˜ ์žˆ๋„๋ก ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋˜์—ˆ๋‹ค. ๋‚˜๋จธ์ง€๋Š” ์ผ๋ฐ˜ PWM ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ๋˜‘๊ฐ™๋‹ค.

์„œ๋ณด๋ชจํ„ฐ PWM ์‹ ํ˜ธ

pwmWriteServo() ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด PWM์‹ ํ˜ธ๋ฅผ ๋ณด๋‚ธ๋‹ค. ์ผ๋ฐ˜ ์„œ๋ณด๋ชจํ„ฐ 50Hz ๋กœ PWM์‹ ํ˜ธ๋ฅผ ๋ณด๋‚ธ๋‹ค.

void pwmWriteServo(uint8_t index, uint16_t value)
{
    if (index < numServos)
        *servos[index]->ccr = value;
}

๋ชจํ„ฐ PWM ์‹ ํ˜ธ

pwmWriteMotor() ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋ชจํ„ฐ PWM์‹ ํ˜ธ๋ฅผ ๋ณด๋‚ธ๋‹ค.

void pwmWriteMotor(uint8_t index, uint16_t value)
{
    if (index < numMotors)
        pwmWritePtr(index, value);
}
โš ๏ธ **GitHub.com Fallback** โš ๏ธ