You are here

PWM outputs on Hall1 and Hall2 pins

2 posts / 0 new
Last post
brentfpage
Offline
Last seen: 3 days 3 hours ago
VESC Free
Joined: 2020-06-07 04:59
Posts: 2
PWM outputs on Hall1 and Hall2 pins

I'd like to output PWM signals on the Hall1 (GPIOB pin 6) and Hall2 (GPIOB pin 7) pins of my hardware version 4.12 VESC.  I know about the existing code that allows this to be done for addressable ws2811 LEDs, but I'd like to simply output a duty cycle between 0 and 3.3 V.  I was thinking of essentially taking code from servo_simple, which outputs a servo on GPIOB pin 5 using TIM3, and adapting it to output PWMs on pins 6 and 7.  Are there any obvious reasons as to why this wouldn't work?

servo_simple uses the pad setup command:

palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(GPIO_AF_TIM3) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING);

Would the same thing work for GPIOB pins 6 and 7?  My concerns include:

- TIM3 may not be appropriate for pins 6 and 7, and maybe TIM4 (which is used for the ws2811 leds) should be used instead

- pins 6 and 7 may not be compatible with the mode " PAL_MODE_ALTERNATE(GPIO_AF_TIM3) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING "

 

brentfpage
Offline
Last seen: 3 days 3 hours ago
VESC Free
Joined: 2020-06-07 04:59
Posts: 2

For anyone who may be interested, I did the following (WARNING: I'm not sure if this is bad for the VESC; I have not experienced any problems)

hall_filters.sch in https://github.com/vedderb/bldc-hardware/blob/master/design/BLDC_4.pdf?r... shows that the Hall pins are connected through 2k2 pullup resistors to VCC.  I had to solder these out in order to allow the pins to go low.  I also soldered out the 10k resistors along the pin outputs and replaced them with wire so that I could choose custom output resistance with external hardware.

With these changes, the ws2811.c code can almost be used directly, except the pin mode must be changed from open drain to push-pull.  For example, for GPIOB pin 7 (a.k.a. hall pin 2), the appropriate pad mode command is:

palSetPadMode(GPIOB, 7,
    PAL_MODE_ALTERNATE(GPIO_AF_TIM4) |
    PAL_STM32_OTYPE_PUSHPULL|
    PAL_STM32_OSPEED_MID1);

For a duty cycle, what works is just setting all of the indices of bitbuffer to a common value, e.g., .5 * TIM_PERIOD.  I also messed with TIM_PERIOD a bit to get the pulse widths that I wanted.