pwm t8

PWM output using hardware timer 8 at a fixed frequency of 97.65 Hz
Author: Johannes Taelman
License: BSD
Github: gpio/out/pwm t8.axo

Inlets

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(&PWMD8, &pwmcfg);
palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(3));
PWMD8.tim->CCER |= STM32_TIM_CCER_CC1NE | STM32_TIM_CCER_CC1NP;
Control Rate
pwmEnableChannel(&PWMD8, 0, (pwmcnt_t)(inlet_pa5 >= 0 ? inlet_pa5 >> 15 : 0));
Dispose
pwmStop(&PWMD8);

Privacy

© 2024 Zrna Research