Idea to get both good sensitivity and resolution at low currents and also good at high currents for QVADRANS (fork)

Ok. here is my idea:

Connect the output of the current sensor to the +input of an op amp in the chip. The voltage is at halfway between VCC and ground when current is zero. These chips give 44 mV per amp.

Connect the - side of the op amp to a resistive divider, that divides the 3.3 supply by close to half. Because the op amp doesn’t work rail to rail probably. Suppose half plus 200 mV.

Suppose it can now detect a swing of 44 mV ok, plus or minus.

Now we program the op amp with a gain of say 13.

The op amp goes to a pin of the ADC. Each op amp goes to a different ADC peripheral, I guess, for speed, so they can all sample at once.

Ok now we get 527 mV per amp, plus or minus, with 12 bits or whatever the ADC is, of resolution, approximately.

The only issue I can see is that the op amp will be saturated of course at higher inputs, but I think that’s ok? You can do that to an op amp, generally?

But we can still access the current sense pin directly from the ADC if we want.

I think I might be able to prototype this with my existing QVADRANS board, just takes so me finicky soldering. I left the vias untented for that reason, so I could access them like solder pads, but idk if that’s going to help.

Personally, I don’t need 30 amps capability, so I would probably use a current sensor that is for 10 amps, and start with 132 mv/amp.

But you get the idea. With this, we get hopefully enough sensitivity to do high frequency injection for detection of position, and also drive more modest sized motors sensorlessly, and can still drive big motors?

Might want to adjust the values for something more optimal.

I think this is an interesting setup, although I think it would be quite hard to use/not use the op-amps on the fly. I think you’d have to commit at setup time to using them or not.

But there would still be an advantage for people using low currents only.

Another way to improve ADC results can be to use different reference voltages for the ADC. The G431 can support changing its internal voltage reference from 2.9V to 2.048V with corresponding effect on the precision for lower voltages…
Using an external programmable reference might give you even more options…

I thought about this method too, but I think the DC bias would be a problem. Some chips have a VSSA pin for independent analog ground reference, but it’s only for noise reduction, it can’t be significantly different from the digital ground voltage.

Hmmm I’m not sure I get you there, from my point of view the VREF+ can be any value within the chip’s limits, generally up to VDDA… and the VSSA is connected to GND. For bi-directional currents the current sense amp’s reference voltage would be VREF+ / 2, to keep the measurement centered in the ADCs range.

Am I missing something?

Oh, I was thinking of how to vary the ADC resolution without the opamp. If you are still using the opamp, then I don’t think there’s any point varying VREF+ since it’s basically the same thing as changing the opamp gain.

The sensor outputs voltage centered around 1.65 (half of vcc), so here’s the ideal operation:

sensor -= 1.65v
sensor *= gain
sensor += 1.65v

So we have our reading still centered around 1.65v but scaled by gain. Let’s play around with the equation:

((sensor - 1.65) * gain) + 1.65
gain*(sensor - 1.65 + 1.65/gain)
gain*(sensor - (1.65 - 1.65/gain))

I propose we use the DAC. Route it around to the VINM pins of the opamps, and set its output to (1.65 - 1.65/gain). Then you can dynamically vary the gain to keep the current within range but with high resolution.

Or you could just use a voltage divider and fixed gain, and if the amplified value gets close to saturating, switch to reading the ADC directly without the opamp.

1 Like

How would you average a current value, when the gain is all over the place (or permanently switches between low current/high current setting)?
I don’t see an advantage since the additional number crunching and probably setup-time adds up to the loop time.

The much simpler way of doing this would just be to use oversampling/averaging with inline current sensing. STM32G4 series supports hardware oversampling.

Another option is to just use a 16 bit ADC, which is available in the STM32H7 series.

The loop would look something like this:

  1. Read sensors, using direct ADC for any that are expected to be saturated when amplified, and opamps for the rest
  2. Scale the opamp results by 1/gain and subtract calibration offset
  3. Check amplitude of values and set gain for next frame, and guess which sensors will be saturated when amplified
  4. Set DAC output for new gain
  5. Everything else

I’m not 100% sure the DAC would be fast enough to stabilize the output by the next sampling time. And it would be simpler code-wise to use a fixed voltage divider, so step 4 goes away (and all the DAC setup code along with it). The offset voltage calculation from my previous post applies either way, so for example 8x fixed gain the voltage divider should output 1.65-1.65/8=1.444V. Using common resistor values, 12k and 15k gives 1.467V. The residual offset can be calibrated out.

Is it possible to permanently connect one ADC channel before and one after the opamp and perform continuous measurements on both? If the conversion is handled by DMA, as for the B-G431B-ESC1, then this might be fairly efficient. Of course, that would require a minimum of 4, better 6 ADC channels.

Good point, there’s no need to choose one or the other. The opamp output is read either via the ADC channels on the VOUT pins or special channels via internal routing, so the ADC channels on the VINP pins should be fine to read at the same time.

Only slightly on topic but the esp32 series seems to allow changing the attenuation on the fly. (I can’t verify this quite yet though.)

If switching on the fly doesn’t produce garbage data for too long, you’d be able to use the 0-750mV for low currents and step up to the 0-2.25v for higher currents,

If hot switching doesn’t work, it seems you can also set one block of ADCs to have low-range attenuation, set another to have higher attenuation, then then connect both pins to the current sensor. Pull from the pins set to low until they saturate, then switch to the high setting.

Hopefully, someone familiar with the chip can tell us if this would work or not.

This quickly got pretty sophisticated which is awesome, but I was thinking you only transition like once in a blue moon between operating approaches. Like when the motor is going slowly or you use a small motor, you use one approach, then switch to another for higher powered operation.

The DAC is a good idea to offset the DC voltage, I didn’t think of that.

This rapid switching I have to admit I am not really following but of course can’t fairly object on that grounds… sounds cool.

We should keep thinking about the hardware that is shared by the most promising approaches and decide on a next-round design for the board, which I can pay for again and mail out to people.

Perhaps it’s a good idea to have jumpers or something so we can try it in a few different configurations without ordering new boards for the purpose. I think that would be a good prototyping method, no matter how promising it is on paper some flexibility is important, indeed I left the vias untented so I could solder to them which might save me yet, allowing me to try different things with this board, but that’s pretty limited.