pwm t4 servo

pwm output timer 4, scaled for servo motors
Author: Johannes Taelman
License: BSD
Github: gpio/out/pwm t4 servo.axo

Inlets

frac32.positive pwm ratio

frac32.positive pwm ratio

Outlets

None

Init
static const PWMConfig pwmcfg = {400000, /* 400kHz PWM clock frequency.  */
                                 4096,   /* PWM period is 128 cycles.    */
                                 NULL,
                                 {{PWM_OUTPUT_ACTIVE_HIGH, NULL},
                                  {PWM_OUTPUT_ACTIVE_HIGH, NULL},
                                  {PWM_OUTPUT_ACTIVE_HIGH, NULL},
                                  {PWM_OUTPUT_ACTIVE_HIGH, NULL}},
                                 /* HW dependent part.*/
                                 0};

pwmStart(&PWMD4, &pwmcfg);
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(2));
Control Rate
pwmEnableChannel(&PWMD4, 2,
                 (pwmcnt_t)((inlet_pb8 >= 0)
                                ? (150 + (inlet_pb8 >> 17) - (inlet_pb8 >> 19))
                                : 4096));
pwmEnableChannel(&PWMD4, 3,
                 (pwmcnt_t)((inlet_pb9 >= 0)
                                ? (150 + (inlet_pb9 >> 17) - (inlet_pb9 >> 19))
                                : 4096));
Dispose
pwmStop(&PWMD4);

Privacy

© 2024 Zrna Research