I have tried to look for some information on internet about the topologies for current sensing used with H-bridges. I did not succeed in finding any good collected information. I have been using brushed DC-motors with four quadrant control using H-bridge, and have discovered some of the issues. And I think some of the issues do also apply for low-side current sensing when you use stepper motors and three phases as with BLDC motors. So I am sorry - this have to be a long comment. In general this has a lot to do with how you make the MPU hardware timers trigger the ADC(s) to measure the current at right point in time.
I think this link was the best I could find on the issue, and I recommend to read it:
https://www.allegromicro.com/-/media/files/application-notes/an296276-current-sensing-in-motor-drives.pdf?sc_lang=en
I did also find one application note from Texas Instruments here. But I am surprised, that they do not describe the topology with one shunt in every lower leg in the H-bridge:
https://www.eeweb.com/wp-content/uploads/articles-app-notes-files-current-sensing-in-an-h-bridge.pdf
I have also seen comments in this forum describing the use of ADCs with DMA, so they sample many values and they may not be synchronized with the PWM timing. In general you will have noise on the current signals generated when the half-bridges switch voltage, and with DMA this way, you will also have the problem, that you may need to reject some of the measured values due these switching transients.
For stepper motors I think SimpleFOC apply sine and cosine currents in the two windings, and in this way you apply micro steps in the positioning of the motor angle.
In the following I describe one way to control an H-bridge and do the triggering of the ADCs. Look this set of curves:
In the top you see a hardware counter, TCNT1 in the MPU counting up and down. This value is compared to two other registers OCR1B and OCR1A. You set the values so (OCR1A + OCR1B)/2 = mean value of TCNT1. A digital signal is generated from TCNT1 >= OCR1B, and it controls the right side of the H-bridge. And similar for the left side. The motor will see a PWM frequency of double the Timers PWM frequency. This case is with a low mean voltage supplied to the winding.
Further down you see currents in the two lower legs of the H-bridge (and it includes the free wheeling diodes). It is assumed the self inductances of the windings are high, so the current do not change much (it is normally not that ideal). You do have two situations, with positive and negative power to the motor, and they are both shown.
The most important part is how you trigger the ADC or ADCs sample hold circuit to read the current value and two ways are shown. I think the first one marked “possible trigger ADC” is the normal way. Most MPUs got hardware, so you can trigger the ADC by the timer being at lowest value. However, if you use a common low side shunt, you will not measure the motor current. But it will be OK to measure the current in one leg as @zhangzq71 describe.
If you use a common shunt you need to trigger the the ADC like shown at lowest curve. The ADC is triggered when TCNT1 pass its mean value (and perhaps only half the times). It is not all MPU, that got an easy possibility to do that, but I guess newer MPU are able to do it, but it is more complicated. If the motor voltage becomes close to zero, the time window you are able to measure the current becomes narrow, and the current measured will be like undefined. I don’t like that at all, and to me it disqualify this topology for full four quadrant control of a DC motor. You need to have reliable current measurements near zero voltage to the motor.
But this is not the whole story, because you need to consider high voltage as well as you see here:
When the voltage becomes near max, you will have a very short window to measure the current when you trigger the ADC in the traditional way, and then this measured current will become unreliable. One way to solve this problem is to limit the max voltage to the motor like to +/- 90% of full voltage. Then you will likely always have sufficient time to measure the current and the method from @zhangzq71 still apply.
If you want to utilize the full voltage to the motor, you need to do two things:
- You need to have a current shunt in both lower legs of the H-bridge.
- You need to shift the timing of the trigger to the ADC at high voltage values to the second position shown. If you measure the currents individually in each leg, you need to know where to measure.
When you use a shunt in both legs, it is possible to use a sense amplifier as you see here and then only use this signal with one ADC:
With the normal timing of the ADC trigger you will then measure the sum of both currents in the shunts this way. However, with the alternative ADC trigger timing at high voltage you will only measure one current, and will need to multiply the measured signal with a factor two.
I hope all this will make sense to you 