18v22, Dual G2 High Power Motor controller current sensing

I’m trying to make heads or tails from the 10mV/amp output. Documentation states the output is only active when the H bridge is active. Is it fair to assume this is when the PWM signal is in the high state? I’ve synced my analog reads to the PWM high state but the readings do not match the current level I can read with a DC clamp meter on the system to the motor. Should I expect a difference between peak current and the average value that a clamp meter would show?

Thanks Ryan.

video of it working in the car.

Hello, Ryan.

That looks like a fun project! Thanks for sharing the video.

The CS outputs on the G2 18v22 shield should generate valid signals during the high portion of the corresponding PWM signals as long the driver is not actively current limiting (the default limit on the 18v22 is 60A). Just to confirm, were the CS readings good before you put the setup in the car? I am not sure what the feedback being output on your laptop monitor was showing.

Can you try running your driver at 100% duty cycle and monitoring the CS pin with an oscilloscope? How does that compare with what your DC clamp meter reports?

- Patrick

I fudged the math on the bench setup to get the clamp meter to match the output on the PC. I was hoping it would correlate to the higher loads and read correctly or match the clamp meter better. As for the o’scope… Don’t really have the means to do that test, and while in the car fuel pressure would run to over 100psi and might blow a hose or fitting.

The previous setup was using a SMC G2 18V25 and a teensy 3.2 sorting CAN messages and sending and receiving serial data to the motor controller. I was able to read the current from the serial data and pass a CAN message forward to the ECU. The serial data and the clamp meter always matched within 50mA. Would be nice if you all could sort a unidirectional DC motor controller that has CAN bus and some internal data to broadcast back over the bus.

If I’m reading 8ish amps from the CS pin but only 4.3 from the clamp meter at roughly 30% duty cycle, can i assume there is a difference from an instantaneous current spike and overall average current draw?

Thanks Ryan

Since you do not have an oscilloscope, can you make a simple program that just monitors the voltage on the CS pin after your low-pass filter and then post some sample outputs from that? Specifically, please post a sample output showing the CS voltage when the driver output is on (100% duty cycle) with no motor connected and another sample output showing when the driver is on (100% duty cycle again) with a motor connected. It does not need to be your fuel pump motor if that will cause problems; temporarily connecting another motor (like you did at the beginning of your video) would be fine. For whatever motor you use can you also check its current draw with your clamp for comparison?

By the way, if you can get access to an oscilloscope (maybe through a friend or a nearby makerspace), that would be a better tool for this. You can get a decent one these days for a few hundred dollars and it will save you a lot of time and give you better understanding of your systems, which enables better designs, better margins of operation, etc. Without one, you are left mostly just guessing about what might be happening, which is not a great way to operate.

- Patrick

Okay, I’ll try to come up with something to test the current output again. I have since removed the low pass circuit from the CS pin as I found some writings that this would mess up the h bridge feed back or something along those lines.

As of writing this the CS pin has a 1k ohm resistor between it and the analog input pin on the T4.1. I am reading the analog input at a 12 bit resolution. On power up the code does an analog read of the CS pin with the motor off to find the offset (that 50ish mV) and subtract that from the total read adc count.

If my math is right… 50mV is roughly 62 adc count on a 12 bit and 3.3V scale. 0.050/3.3 = 0.01515… X 4096 = 62. I’ve observed around 45ish mV so 55ish adc offset at no current flow. 1 adc count should be equal to roughly 80mA… amps = (adcA2 - offset) * 8 / 10; if adcA2 is 200 and offset is 55… 200-55 is 145… 145*8/10 is 116… or in my eyes 11.6 Amps… This matches that 145adc is (145/4096)*3.3V = 0.116V. aka 11.6 Amps at 0.010V/amp.

Forgot one question… could i setup a resistive load instead to do the current test? I have a 10ish ohm heating element I could dump current into to extend the range of testing…

I recommend reinstalling the low-pass filter to reduce the noise; I am not aware of any way that could somehow interfere with with the H-bridge. Can you let me know what resistor and capacitor values you use for the filter?

Using a resistive load like your heating element should be fine for this test.

- Patrick

Ran some tests and I think I might have a since of whats going on.

0% 47mV 0amps <== Zero current offset at first.
10% 48.3mV 0.1A
25% 52.1mV 0.422A
50% 54mV 0.530A
75% 57mV 0.798A
100% 60.6mV 1.069A

At the start of the test I got 47mV as the zero current offset. Near the end the offset would have to move upward slightly for the 60.6mV to equal 1.069A… The offset would need to be right at 50mV. This might not seem like much but with such a small change in adc values per mV and having such a narrow voltage range per amp makes any offset movement skew all the math for the final value. Is it possible for the offset to move as the current goes up? less than 1 amp its closer to 47mV and above 1 amp it starts shifting closer to 50mV?

In my code I put a small delay(5us) after the interrupt to sample analog after the PWM is fully on and not right at the rising edge. Values shown on the laptop are much smoother now. I also have the serial output showing the stored offset value at the beginning of the stream.

Thanks for your help…


More thoughts… a resistor load will not show the same current trace as a motor. I start my analog read on the rising edge which will be at the lowest point of the ripple and not the highest. On a resistor load the current should rise quickly and stop at a steady state while an inductor load will have some sort of saw tooth shape to it. I ran out of day light so more testing tomorrow after work.

We don’t expect the offset to move, but there is going to be some amount of error with both the CS pin readings and your current clamp measurements that will prevent their results from ever lining up perfectly. The results you described in your recent post seem reasonable, especially for those relatively low currents.

- Patrick