0
\$\begingroup\$

I'm coding a PIC24FJ256GA106 to make a PIPD velocity control for a BLDC motor by using the Hall sensors instead of back-emf. Currently I can control start, stop and direction of rotation of the motor.

When I try to measure the current velocity of the motor I'm facing a problem, because I'm reading the time between position changes of the Hall sensors, which allows me to detect when the motor has moved 60 mechanical grades. Using that, I can calculate the velocity of the motor as if the motor has a constant velocity, but this gives me problems when the motor is accelerating or or slowing down its velocity.

Looking at the internet, I found a couple of papers from ST and Microchip where they describe how specific models of ASIC for BLDC motor control work for calculating the velocity of the motor. The Microchip document explains that they simply calculate the velocity as I explained before, measuring time between position changes and considering the velocity change if it is linear.

The ST document on the following link

https://www.st.com/resource/en/application_note/cd00004396-l6235-three-phase-brushless-dc-motor-driver-stmicroelectronics.pdf

explains that they use a monostable circuit which generates a fixed width pulse being triggered by the rising edge of the Hall sensor pulse. This fixed width pulse forms a square signal whose "on time" is the fixed width of pulse generated by the monostable circuit, and the "off time" is the remaining time until the next rising edge of the Hall sensor occurs. This finally makes a square signal of variable duty cycle and from that it is possible to obtain a DC signal with a voltage proportional to the velocity of the motor. From that, I can calculate the velocity of the motor.

On the second method, I don't plan to add a monostable physical circuit to the system that I have, but I can easily add that behavior to my code. The only problem here is that my motor has a nominal velocity of 4000 r.p.m. and when I do the code for the fixed pulse with an appropriate width for this velocity, I think it will be narrow enough to have a very low DC voltage from the square signal when the velocity of the motor is too low. The outcome will be the same problem as if I was using the method of measuring time and calculating the linear velocity, as explained first.

So, is there a method for calculating the velocity using the Hall sensors accurate enough to have good velocity calculations when the motor is accelerating or decelerating, or not?

\$\endgroup\$
8
  • \$\begingroup\$ You need to quantify or at least clarify what you mean by "accurate enough". It's unclear from your description what amount of error in your velocity measurement is acceptable or unacceptable. You talk about it being an issue when the motor is accelerating or decelerating, during which time by definition the speed is changing. In order for someone to evaluate a method of calculating the velocity they would need to know how quickly or slowly the actual velocity is changing, since that affects how accurate an inferred measurement of the velocity will be. \$\endgroup\$
    – gcr
    Commented Jul 8, 2021 at 20:43
  • \$\begingroup\$ Sorry, what's a mechanical grade? \$\endgroup\$
    – Hearth
    Commented Jul 9, 2021 at 0:43
  • \$\begingroup\$ The Hall sensors you use for 6-step commutation change state every 60 electrical degrees, not 60 mechanical degrees. Otherwise you would not be able to use them for commutation. If they are accurate enough to commutate the motor, they should be accurate enough for other purposes also. You can average if needed. The electrical frequency is equal to the mechanical frequency * N where N is the number of magnetic pole pairs on your rotor. \$\endgroup\$
    – user57037
    Commented Jul 9, 2021 at 0:47
  • 1
    \$\begingroup\$ @mkeith thanks for the clarification, I just checked what you said at the AN885 from microchip and thanks to you I saw on my mistakes, my motor has 2 pole pares \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 1:13
  • 1
    \$\begingroup\$ @mkeith I must write "I saw one of my mistakes" \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:33

3 Answers 3

1
\$\begingroup\$

All you have to do in your code is note the elapsed time from one positive edge of hall sensor to the next positive edge of the same sensor. This is the PERIOD of the electrical frequency. If you have an input capture timer, then it should be very easy to get this period automatically. If you don't, you can still record the elapsed time by reading from a free-running timer every time you get a positive edge. I know you have to detect the positive edges because otherwise you would not be able to commutate the motor at all.

You do not have to try to emulate the monostable with your code. That will not help you in any way that I can see.

\$\endgroup\$
2
  • \$\begingroup\$ thanks, that is exactly what I'm doing from the beggining but like John Birckhead said, that is the average speed and not the instantaneous speed, I can do that by measuring back-emf but is not the objective of the project to use back-emf \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 13:14
  • 1
    \$\begingroup\$ thanks for your help, the problem here was exactly what you said about the hall sensors detecting changes every 60 electrical degrees, after condirer that and change only one number in my code, then the speed printing is very close to the measured with an external tachometer, I need to do only some adjustments because I'm working with floats but it its working very well right now. \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 14:40
2
\$\begingroup\$

Next time before you start any design, convert all the qualitative words into quantities in a design spec. And an acceptable, reasonable % tolerance.

"narrow enough to have a very low DC voltage" = TBD , considering SNR ratio and resolution of uC 8 bits gives a possible speed range up to 256:1 and range of duty cycles. or 4000 RPM to 32 RPM in each direction.

If you have a max RPM of 4000 RPM you could make full scale 4800 RPM = 80 Hz or 125 ms/cycle for the one-shot. Then with a bit of algebra or a lookup table you can compute the RPM from any pulse off time with a frequency counter.

You can also integrate down from the off-time for each cycle with a counter and scale it.

"Hall sensors accurate enough" that depends on if they drop out at low speed and your lowest speed.

There are plenty of other ways with I2C tach chips and WSS chips (wheel speed sensors) from Infineon.

\$\endgroup\$
5
  • \$\begingroup\$ @mkeith yes, as you signales before I was mistaken about the 60 mechanical degrees, thanks again for allow me see that \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 1:28
  • \$\begingroup\$ @Tony Stewart EE75 thanks for your answer, the time intervals are being measured at a very good accuracy (about 99,9%). The part in what I have the problem is the part where I calculate the numerically undertandable for human beans (I didn't explain that before but I will edit the question to mention that), this last part wil be sent to a screen to be shown in a future graphical interface for the project \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 1:40
  • \$\begingroup\$ @Tony Stewart EE75 I don't know what TBD means (english is not may natural language), about the speed range you mentioned, that is preciselly the problem; based in your calculation then I'll be unable to measure anything bellow 32 rpm, I know that for a 4000 rpm motor, 32 rpm may seems like nothing or too slow but I'd like to see if showing speeds lower than 32 rpm (based in your calculation) its possible although thinking again, car tachometers normally doesn't show any speed bellow 20 Km/h, that is a good point. \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 1:52
  • \$\begingroup\$ @Tony Stewart EE75 About the "Hall sensors accurate enough" again I used bad grammar, what I meant to saw was iif there is a method accurate enough or better than simply divide the quantity of revolutions made by the motor and the time transcurred to make that quantity of revolutions or the method where ST people use the monostable circuit by using the HALL sensors of the motor. The problem with the lookup table is that I don't have a velocity curve for the motor comming from the manufacturer, only the basics of the motor. \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:02
  • \$\begingroup\$ To Be Determined TBD ( resolution... by you). A design problem is choosing ripple rejection of filter from Tach and PWM with the tradeoff of time lag from low pass filters . \$\endgroup\$
    – D.A.S.
    Commented Jul 9, 2021 at 2:09
1
\$\begingroup\$

Since your rotor is moving 60 mechanical degrees between hall events, a two-pole motor is implied. So at 4000 rpm, the time between hall events is 2.5 mSec. However, the ST device you have referenced performs its speed sensing from a single hall device, so its input sample time occurs once per revolution, or every 15 milliseconds.

During the 15 milliseconds (disregarding all of the protection circuitry), the controller provides a PWM signal. The PWM circuit turns "on" until the current sense reaches a reference, then turns "off" for a fixed time. This reference threshold value does not change until the completion of the revolution.

This is where your PID comes in. You will measure the amount of time required to get the one revolution, and your PID algorithm will adjust the current threshold with the PID loop. The PID constants have to be selected based upon the expected frequency of torque changes and the inertia of the load, but, in any case, your loop doesn't make any adjustments until the next sample, 15 milliseconds later (or longer if running more slowly). If you choose your constants properly, the loop will do a fair job of predicting when the next sample will hit, and make only small adjustments. If not, your motor will slow down or stall when loaded and overshoot when unloaded, or may even "hunt." You need only measure the currents and can do everything else in software, but you can't adjust the motor drive more than once per revolution, and it may take more than one revolution for your loop to "catch up" to an abrupt change. If your concern is that your speed may vary during a single revolution of the motor, you could run your PID from each transition of all three halls and get down to one-sixth of a revolution between PID corrections, but I think you will likely find that the motor inertia will make this unnecessary.

Good luck!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ @mkeith I allways knew that my motor has 4 poles but I had a conceptual error about the physical position of the sensors, thanks to you now I don't have that conceptual error \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:15
  • \$\begingroup\$ @Johh Birckhead thanks for all your comments, I need to clarify something, the document from ST could be used like follows, as I have 3 Hall sensors then I fisically connected them to change notification interrupt capable inputs, then at the change notification interrupt handler I detect a position change by considering all the Hall sensors outputs (this works perfectly) fine and by code then I could the monostable behavior \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:22
  • \$\begingroup\$ @Johh Birckhead having made the clarification then I go to the next step, the PIPD controller, right now I have calculated the P, I and D coefficients and I also wrote the code for the PIPD controller but I didn't implemented yet because I want the speed printing well made first, to me is important as a way to see that the time input that I'm inserting in the PIPD function is correct, that will reduce unknown factor to avoid windup in the system, thats why I want to recalculate the controller output on every position change instead of making it on each completed revolution \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:32
  • \$\begingroup\$ are you saying that is possible that the system could need more than one revolution calculate the correct velocity? \$\endgroup\$
    – vram
    Commented Jul 9, 2021 at 2:37
  • \$\begingroup\$ Yes I am. Think about the motor when it is spinning up. Its speed is greater at sample(N+1) than it is at sample(N), but if you measure only the time between samples, the answer you get is the average speed during this period, not the instantaneous speed. To detect that the motor is accelerating, you must compare the average speed with your speed calculated from previous samples. This is what the differential term does. It helps to compensate the lagging error you would get by using only the average speed by predicting the acceleration and adding it. \$\endgroup\$ Commented Jul 9, 2021 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.