Skip to content

Implement STM32HWEncoder count setting functions and getter for handler#81

Open
Santynolo wants to merge 1 commit intosimplefoc:devfrom
Santynolo:dev
Open

Implement STM32HWEncoder count setting functions and getter for handler#81
Santynolo wants to merge 1 commit intosimplefoc:devfrom
Santynolo:dev

Conversation

@Santynolo
Copy link

This PR adds the following functions:

  • setCurrentAngle(float set_angle)
    Sets the current angle of the encoder by modifying the CNT register in the timer.
  • setEncoderCount(uint32_t ecount)
    Sets the CNT register in the timer.
  • getEncoderTimerHandle()
    Returns the encoder timer handle if the user wants to modify any register

I have also implemented the index pin function that was commented out, and added some debug messages to better debug issues caused by timer configuration and/or pin selection
Tested on an STM32G431 MCU the following:

  • setCurrentAngle()
  • setEncoderCount()
  • Index search

I have also modified the README to reflect these changes.
i'll come back to confirm the index search to be working, but it's so simple i don't see any potential issues.
I have left the ETR line not implemented since i think it's not really necessary? I don't see any potential benefits except full rotations tracking. But i've left a potential init structure commented out in the code for the future.

@Santynolo
Copy link
Author

I did forget to add pinMode here (and have added it)
image
But it seems like this does not work? This interrupt triggers after initFOC() fails to find the index on my end. If anyone could suggest why or test it out themselves (after adding pinMode after the if statement) it would be great...

@runger1101001 runger1101001 self-assigned this Feb 26, 2026
@runger1101001 runger1101001 added the enhancement New feature or request label Feb 26, 2026
@runger1101001 runger1101001 added this to the 1.1.0 milestone Feb 26, 2026
@github-actions
Copy link

Memory usage change @ 890740a

Board flash % RAM for global variables %
adafruit:samd:adafruit_metro_m4 N/A N/A N/A N/A
rp2040:rp2040:rpipico N/A N/A N/A N/A
arduino:sam:arduino_due_x N/A N/A N/A N/A
arduino:samd:nano_33_iot N/A N/A N/A N/A
esp32:esp32:esp32 N/A N/A N/A N/A
esp32:esp32:esp32s2 N/A N/A N/A N/A
STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 N/A N/A N/A N/A
STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE N/A N/A N/A N/A
Click for full report table
Board examples/drivers/drv8316/drv8316_3pwm
flash
% examples/drivers/drv8316/drv8316_3pwm
RAM for global variables
% examples/drivers/drv8316/drv8316_6pwm
flash
% examples/drivers/drv8316/drv8316_6pwm
RAM for global variables
% examples/encoders/calibrated_sensor/calibration_save
flash
% examples/encoders/calibrated_sensor/calibration_save
RAM for global variables
% examples/encoders/linearhall
flash
% examples/encoders/linearhall
RAM for global variables
% examples/encoders/mt6816/mt6816_spi
flash
% examples/encoders/mt6816/mt6816_spi
RAM for global variables
% examples/encoders/calibrated_sensor/calibrated
flash
% examples/encoders/calibrated_sensor/calibrated
RAM for global variables
%
adafruit:samd:adafruit_metro_m4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
rp2040:rp2040:rpipico N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:sam:arduino_due_x N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:samd:nano_33_iot N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
esp32:esp32:esp32 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
esp32:esp32:esp32s2 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/drivers/drv8316/drv8316_3pwm<br>flash,%,examples/drivers/drv8316/drv8316_3pwm<br>RAM for global variables,%,examples/drivers/drv8316/drv8316_6pwm<br>flash,%,examples/drivers/drv8316/drv8316_6pwm<br>RAM for global variables,%,examples/encoders/calibrated_sensor/calibration_save<br>flash,%,examples/encoders/calibrated_sensor/calibration_save<br>RAM for global variables,%,examples/encoders/linearhall<br>flash,%,examples/encoders/linearhall<br>RAM for global variables,%,examples/encoders/mt6816/mt6816_spi<br>flash,%,examples/encoders/mt6816/mt6816_spi<br>RAM for global variables,%,examples/encoders/calibrated_sensor/calibrated<br>flash,%,examples/encoders/calibrated_sensor/calibrated<br>RAM for global variables,%
adafruit:samd:adafruit_metro_m4,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
rp2040:rp2040:rpipico,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:sam:arduino_due_x,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:samd:nano_33_iot,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
esp32:esp32:esp32,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,,,,,N/A,N/A,N/A,N/A
esp32:esp32:esp32s2,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,,,,
STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants