You are here

PWM outputs on Hall1 and Hall2 pins

3 posts / 0 new
Last post
brentfpage
Offline
Last seen: 10 months 3 days ago
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: 10 months 3 days ago
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.

 

mechatronixNick
Offline
Last seen: 1 year 12 months ago
Joined: 2019-12-11 20:16
Posts: 1

Hey brentfpage!

Thanks for the info! I also want to output a PWM signal on a unused GPIO pin but im not really farmiliar with the layout of the source code (or using timers for pwm ouput for that matter i guess arduino made it to easy!), would you mind sharing where you wrote the code to set pin mode "palSetPadMode" and how you set an output pwm signal? Just to get me started. Im thinking i would want the pin mode code in the HW conf file and the actual setting of the pwm in the application file, but i might be mistaken and could really use some pointers on how to do it right. Im using a CheapFOCerV2 that has the unused GPIO-pins on a header wich is real handy!

/Nick