Uncategorized

motor torque control

Motor torque control with PWM : how to measure current?

Ask Question

Asked yesterday

Active yesterday

Viewed 66 times

4

For my caving robot project, I have 8 motors for which I need torque control (they will mainly be stalled or nearly stalled.)

Each motor is driven by a DRV8801PWPR H-bridge (commanded by one digital and one PWM signal from a STM32F723.)

In order to get the torque, I was planning to measure the current.

The DRV8801 provides a VPROPI pin, which gives a voltage proportional to the current in the sense resistor.

Which kind of current measure is the most accurate to estimate torque:

  1. The average current (ie adding a low pass filter to VPROPI.)
  2. The current at some well chosen moment of the PWM cycle (probably choosing the most “stable” moment of the PWM high.)
  3. The same as 2, but multiplied by the duty cycle of the PWM (can easily be done, as it’s the same micro-controller generating the PWM and measuring)
  4. Something else?

PS: I started my PCB design with solution 1, but @bobflux’s answer in my question about cross-talk made me rethink about what I really need to measure.

pwmcurrent-measurementcontroltorque

ShareCite

EditFollowFlag

edited yesterday

JRE

54.8k88 gold badges8484 silver badges146146 bronze badges

asked yesterday

Sandro

1,76611 silver badge1414 bronze badges

  • Your driver and many others have an external “current sense resistor” (some have internal sensors) , why not use them? – tlfong01 yesterday  
  • @tlfong01 : the DRV8801 supports external sense resistor (and I’m using one). Even beter, it has the “VPROPI” pin acting as amplifier, in order to be able to use a small resistor while getting decent voltage (specially usefull in a battery powered project like mine, where I don’t want to loose 1V out of 12 in a sense resistor) – Sandro yesterday
  • (1) My apologies for not reading your question carefully and giving you a silly answer. I read your question again and found that you presented your situation very well. (2) I am curious about your cave exploration robot project. It would be nice if your can show us the robot’s user requirement or spec. (3) I guess you are using DC motors in your project. I happen to be playing with a robot car project, an 4WD/8WD with TMC2160 stepping motor (can also do DC motor) driver (big current > 10A). If I know your motor requirement better, I might suggest BLDC or stepping motors. – tlfong01 20 hours ago   
  • 1@tlfong01 : I have ni idea how to give a complete “description” of my robot on this site without being out of topic (If you have, it might be usefull to refer to it as most of my questions relate to this robot). Or if you are just currious, we could do a skype. For short, it’s a robot to explore vertical narrow cracks, by driving blocked between the 2 opposit walls. Basicaly, the robot is made of 8 arms (2 horrizental “X”) with a wheel at the end of each arm. Each wheel is pushed agains the wall (to avoid the robot slipping down) by a motor (those I’m asking about) pulling some elastic band. – Sandro 16 hours ago
  • 1The motors are very small geared DC motors (<1A, weigting less than 20g). The weight is a very important factor for this robot, as the force needed for the arms (ie motor torque) is proportionnal to the weight of the robot. The goal of torque control is to ensure constant force against the walls (ie “constant torque” changing a bit depending on the position of the arms) – Sandro 16 hours ago
  • (4) Are you using small DC motors such as N20 (see Ref below). Perhaps you can give me the link to your motor. (5) You following spec is good: “a robot to explore vertical narrow cracks, by driving blocked between the 2 opposite walls. (6) Is there are reason using drv8801, and not the possibly improved version drv8833/8871 (also see refs below). (7) The tmc2160/2209 has some advanced features on torque/current (using microstepping/pwm constant current) which might give you some brainstorming ideas. (8) You might also to consider BTN7971B, whose current sensing comparing with drv88xx. – tlfong01 6 hours ago  
  • Let us continue this discussion in chat. – tlfong01 6 hours ago  
  • 1Brushless motors, and stepper motors, can be held still with adjustable torque, normal DC motors tend to spin! – linuxfan says Reinstate Monica 3 hours ago
  • @linuxfan says Reinstate Monica, Ah, that is very important tip for #Sandro, who needs “holding still”, and for step motor, it does not need any power (no voltage, no current)! In other words, the stepper motor guy, can go to sleep and the motor holds on without falling down, and without using any power! PS, as I remember, BLDC and stepper motors have similar architecture. – tlfong01 3 hours ago   
  • Not exactly, @tlfong01: stepper and brushless motors need current to generate torque. Without current, steppers are a little “stiffy”, i.e. they tend to oppose movements, but quite weakly – brushless ones spin easily instead. – linuxfan says Reinstate Monica 2 hours ago
  • @Sandro, I hope you will update us all about your findings, I (and others, I think) are very interested. – linuxfan says Reinstate Monica 2 hours ago
  • @linuxfan says Reinstate Monica, Ha, on second thought, I knew I make a careless mistake. 12 mins ago – tlfong01 2 hours ago  
  • @linuxfan says Reinstate Monica, Ha, on second thought, I knew I made a careless mistake. As you said, stepper and BLDC motors need power to hold. I struggled between apologizing or let someone pointing out my mistake. To me, let someone pointing out my mistake or actually anybody’s mistake is a good way to monitor if this forum or discussion if healthy or democratic, otherwise the newbies would always wrongly think the so called “elites” are always right. – tlfong01 2 hours ago  

Add a comment

1 Answer

ActiveOldestScore

1

Motor current only flows through the sense resistor during PWM ‘on’ time. During the ‘off’ time it circulates inside the bridge and cannot be directly measured. However if the current is continuous then it will decay to the value you see when the next PWM ‘on’ period starts, so the average current during both on and off periods should be the same.

If the PWM ratio and/or frequency is low then current may decay to zero during the off period, and then you won’t know what the average current was over that time. If current decays faster then the average when off will be lower.

Here’s an idealized simulation of applying 50% PWM to a DC motor. Red trace is FET Drain current (and motor current) during the ‘on’ period ramp up. Green trace is decaying motor current during PWM ‘off’ time. Note the large spike when the FET is switched on, caused by flyback diode recovery time and parasitic capacitance. You may need to delay reading current for a few microseconds to avoid this spike.

enter image description here

And here’s what it looks like with 20% PWM. Current has become discontinuous becaue motor inductance is not quite sufficient to keep it above zero during the PWM ‘off’ period.

enter image description here

In practice the waveforms will be messier due to commutation and back-emf ripple. Best way to measure the current is with a high speed ADC. Take as many readings as practicable during the ‘on’ period, and average them over several PWM cycles to reduce noise. Assume that average current during the ‘off’ period is the same, perhaps with compensation for more rapid decay at low PWM ratios.

ShareCite

EditFollowFlag

answered yesterday

Bruce Abbott

49.9k11 gold badge4141 silver badges8181 bronze badges

  • Thanks. So you would recommand driving the motors in such way that the current is far from reaching maximum(otherwise the curve would look exponential and not linear), but still far from being nearly constant? If so, why? – Sandro yesterday
  • When you say taking as many samples as possible during on period, you mean during the ‘on’ of the PWM? If so, it’s not the easiest to do : I will have to start and stop high frequency ADC measurements for each motor at different moments (because the rising edge of PWM can be synchronized, but not the falling edges). Or I have to do permanent measurements, and somehow determine which ones actually where during on time. – Sandro yesterday
  • @Sandro can you read the ADC on a fixed time interval (cyclic interrupt) and, in the interrupt handler, see if the PWM is on (the output pin status is reflected into some register)? Doing so, you will have a “high” value and a “low” value. The low value indicates how much the current decayed while the pwm was off. – linuxfan says Reinstate Monica yesterday 
  • @Sandro beware, if using the cyclic ADC sampling, to choose an interval which will not beat (synchronize) with PWM. – linuxfan says Reinstate Monica yesterday
  • @linuxfansaysReinstateMonica : yes, it might be a solution. However, it will very CPU intensive, as it mean I have to do high frequency sampling with an interupt for every single conversion (I was hopping to use DMA, but it will no longer work with this solution). So for low PWM frequency I should be fine, but for higher frequency? Even with a 216MHz MPU, at let’s say 10kHz PWM and 10 samples/PWM period, for 8 motors, it lets only 270 instructions per measurement (supposing I do nothing else) – Sandro yesterday
  • @Sandro I think you don’t need very high frequencies. Say, 1 kHz could be good. With high frequency sampling you detect things very fast but… do you want to react so fast too? But all depends on the context, probably on how much fast the load can change. – linuxfan says Reinstate Monica yesterday
  • If synchronized ADC is too hard then just low pass filter the current sense voltage and divide by the PWM ratio to get average current. This will be slower and less accurate at low PWM ratios. – Bruce Abbott yesterday
  • @Sandro: didn’t read well you comment. But, my idea is not to read many times in a cycles. Instead, do sparse reads which, statistically, will fall everywhere in the PWM cycle. Here, “sparse” can be at 200 Hz or 1 kHz or 3, depending on the application. – linuxfan says Reinstate Monica yesterday
  • @linuxfansaysReinstateMonica : then there is no more problem in using interrupts – Sandro 23 hours ago

Add a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.