pwm t3

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

Inlets

frac32.positive pwm ratio

frac32.positive pwm ratio

frac32.positive pwm ratio

frac32.positive pwm ratio

Outlets

None

Init
static const PWMConfig pwmcfg = {400000, /* 400kHz PWM clock frequency.  */
                                 4096,   /* PWM period is 4096 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(&PWMD3, &pwmcfg);

palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2));
Control Rate
pwmEnableChannel(&PWMD3, 0, (pwmcnt_t)(inlet_pa6 >= 0 ? inlet_pa6 >> 15 : 0));
pwmEnableChannel(&PWMD3, 1, (pwmcnt_t)(inlet_pa7 >= 0 ? inlet_pa7 >> 15 : 0));
pwmEnableChannel(&PWMD3, 2, (pwmcnt_t)(inlet_pb0 >= 0 ? inlet_pb0 >> 15 : 0));
pwmEnableChannel(&PWMD3, 3, (pwmcnt_t)(inlet_pb1 >= 0 ? inlet_pb1 >> 15 : 0));
Dispose
pwmStop(&PWMD3);

Privacy

© 2024 Zrna Research