Setting Electrical Angle Zero by Zeroing Encoders

Hi All,

I’m working with a project that uses AMT212B encoders to commutate some BLDC motors. These are absolute encoders, with a non-volatile, user-settable zero.

I’m “sprucing up” everything in preparation for a public demo, and to streamline the startup sequence I’m trying to eliminate the need for each motor to run sensorAlign() on startup. For the purposes of the project, I have several identical systems (MCU + multiple BLDC motors) that I need to have running the same code, so simply hardcoding the correct zero angle offset isn’t a viable option. Instead, I would like to write a “calibration script” that zeros the encoders at the correct angle, so I can set all motors’ zero_angle_offset to zero in code, and skip the sensorAlign() step at startup.

I had been planning to simply replicate the steps of sensorAlign() in my own code but replace the line zero_electric_angle = electricalAngle() with ZeroEncoder(), but I’m finding I can’t do that since setPhaseVoltages() is a private function. Does anyone have any advice for how to replicate the functionality of sensorAlign() in my own code?

Thanks.

squirellydan

Hi,

setPhaseVoltage will be public in the next release… I just merged this to the dev branch, so you can check out the dev branch if you’d like.

But may I ask why not use the function initFOC() which takes the electrical angle as input parameter? If you provide the electrical angle and direction to initFOC(), the alignment will be skipped…

Thanks! That’s perfect.

And in my case I have two systems (2 distinct MCUs) that each have multiple motors, and need to be running the same code. So if I just pass the electrical angle to initFOC, each time I want to deploy the code to an MCU, I would need to manually change the electrical angles to be correct for that individual system.