Measure Back EMF

Has anyone come up with any way to create a poor man’s back EMF measurement using the current sense of a VNH2SP30? I want to provide some feedback to the microcontroller to let it know if the motor is actually moving at all. I don’t need to measure RPM, just a move/no-move sense. For purposes of the design, no direct measurement of motor RPM can be made externally.

If I allow the controller to coast briefly will the current sense output give me a usable pulsed feedback indicating motor movement? Any ideas welcome.

Hello russmc,

We tested how the current sense works in the VNH2SP30 today and found that it is possible to use the current sense as a back EMF measurement with some limitations. When you make the PWM input low, the high-side MOSFET specified by your INa and INb pins stays on (i.e. only the low-side MOSFET gets PWMed). This means that the motor can keep coasting in the direction it was being powered, but it will be braked if you try to spin it the other way. It is in this braked mode that the current sense gives a useful value.

For example, suppose making INa high and INb low makes your motor run clockwise. If you just make PWM low, the current sense pin will output zero if the motor turns clockwise, and it will give a positive output if the motor turns counterclockwise.

Therefore, if you want to see if the motor is turning in the direction you are trying to drive it, you can turn off PWM and briefly switch the polarity of INa and INb, and then measure the current sense pin. If you just generally want to know if the motor is spinning, you can turn off PWM and measure the current sense pin with INa low and INb high and then measure again with INa high and INb low. If either measurement is non-zero, the motor is spinning.

- Ryan

That is exactly what I need but didn’t know enough to figure it out! I will start writing up the code to implement this behavior. I’ll also post some info on the project I have underway. The controller really works well! Thanks!

Great. Would you be willing to post the code you come up to help people who want to do the same thing?

- Ryan

I will post it up when I get it working. If I didn’t need to finish up another project this week I would be working on it now!

The project I have is a radio remote control for large scale trains (G-Scale). I will be working on the back EMF for a new receiver next week. I thought I would post a link to videos showing operation of the current system. I’m no Spielberg so don’t abuse me too much:

Install into diesel locomotive:
You can see the Pololu motor controller attached as a daughter card.

Demo of 3 locomotives simultaneously controlled (warning, painfully long):

When I make a new video to show back EMF it will probably be a ugly looking prototype board with a lot of wires and a half disassembled locomotive but it should be using back EMF to really run the locomotive SLOW… putt, putt, putt…

I’m impressed by the engineering design work that you’ve put into this Cab Command system. The end result is quite slick. Are you thinking of selling this system other G-Scale train hobbyists?

- Ryan

I’m not sure how I will proceed. I posted up info on some of the large scale train boards and drew the immediate attention and ire of some of the remote control manufacturers. With the improvements I am planning the system would be more capable than most commercial offerings.

Set up a circuit this morning and I am able to detect that the motor is turning. This is a big step. Thanks Ryan for your help. I’ll post up more information when I have something more.

Woohoo! I have it working quite well now. I can’t wait to make a new board that will fit inside the locomotive!

Right now the feedback loop will guarantee that the locomotive will move. If I hold back the wheels, it detects this and applies more power. When wheels move again it drops power slightly until either the desired set speed is reached again or wheels stop in which case it applies more power again and the loop goes on.

I may try to make a video but it is difficult to show the movement. I want to clean up and document the code a little before I post it.

Thanks again Ryan!

Glad to hear you got it working!

- Ryan

Took a video of the development board I’m trying BEMF with. You can see in the video when additional power is being applied to keep the train moving, the LED lights. I’ll get some clean code up here soon to show what I did. Right now it’s buried in the radio and speed tables in the receiver software.

This Thursday I’ll have the PCBs so I can put everything inside the engine. Of course there won’t be a cool feedback LED anymore. :slight_smile:

I finally got BEMF to really run the locomotive slowly. Here is a video:

What do you mean by “got BEMF to really run the locomotive slowly?” What do the current sense readings have to do with the train moving slowly? Were you having trouble getting current sense readings while moving slowly because you had to brake in the direction of travel to get the reading?

- Ryan

Interesting enough, the current sense in one direction at no movement state is different than the other. Also, because I’m moving so slowly, the 10 bit AtoD converter I use is unable to pick up differences in the current sense line at its most extreme low points.

To remedy this I needed to turn off the motor more frequently to force it to a lower speed, this let my feedback routine pulse the power on using BEMF and therefore make it move. It took a while to balance this.

On Thursday I will find out what settings need to become variables based on the locomotive/motor.

I only wanted to perform the original speed tests but was challenged by a friend to make it operate more slowly. I was able to achieve a ~10 fold reduction in speed using the power off/BEMF feedback operation.

Here is a quick video showing low speed.

It actually goes at its slowest, 1/3 of that speed now.

Nice! How did you get the current sense measurement to work at lower speeds?

- Ryan

Sorry it took me so long to reply.

To achieve that low speed I had to turn power to the motor off briefly. I proportionately turn the motor off longer periods at the lowest speed setting and reduce the off time as I go higher until just running normal PWM power to the motor. This has the effect of making the feedback reading more meaningful at lower speeds.

It’s not a real PID loop but it works. It will spin the wheels if the engine is stopped at that low speed. Since the original intent was just to insure slow motor movement I met that goal. Implementing real PID was a bit too much to fit into the controller and still have room for all the other features.

To confirm it was really working and not just pulsed power making the wheels turn, I plugged in a non feedback motor controller which I could make run better at lower speeds but it would not make the wheels spin at low speed. Just for fun I programmed LEDs to flash when it was reacting to feedback and the difference was quite obvious.