QVADRANS v1.0 (fka Lepton 3.0)

yes, it would be great))

1 Like

Ok, will do :slight_smile: I’m heading to the post office now
Update: it’s in the mail, 8 business days garaunteed was the fastest they had.

I probably should have verified current sense was working ok first but it’s probably good, I shall try to do that now.

update fuck, the current sensing is fucked.

The current sensors are connected to the wrong pins. They are not the op amp pins. Also the op amp outputs have to be connected to an adc pin. Fuck. I should have checked obviously.

I can’t re-wire anything probably because it’s too small. I will try with enamelled wire or something.

I’ll also have to figure out how to set the op amp gains in arduino.

Opamp2 out is pa6 to so I have to put the uart on different pins.

These are hall sensors, they only need to be connected to ADC pins. Op amps are for shunt resistors.

Here’s the datasheet Cross chip CC6903SO-30A Datasheet

Mostly in Chinese, but you can see the output is centered at 1.65V and this 30A version is 44mV/A positive or negative from there. The first application circuit on page 5 is the one we’re using.

And since these are inline sensors, I don’t think you even need any special timing to read them. But do write your own ADC code, because analogRead is hopelessly slow.

no, because you only get 0.044 volts per amp. That’s not enough for the adc to give a useful signal that allows you to discern between currents to a degree that is enough for sensorless drive, really. We need both high sensitivity at low speeds for various reasons and also the ability to sense higher levels. This could be done by adjusting the op amp gain when needed in the program.

1 Like

Glad to hear the revisions work! If you’ve still got a board around to send out or are looking for someone to send to in the next batch I’d like to take a look at one. Im just starting to run working tests of my order of rev 0 boards and it would be interesting to see how they compare. So far I still haven’t run into any issues, but I also haven’t done much to load them yet.

2 Likes

Sorry, I don’t really know what I’m talking about since I’ve never actually used current sense. I’ve been working on a design using these same sensors, so I’ll make sure they’re connected to the OPAMPx_VINP pins. Thanks for bringing it to my attention before I finished the routing!

1 Like

I don’t think there is any problem with the current sense. According to my calculations you get a resolution of 18mA. If you want more, you can use the hardware oversampling feature if the ADC. Another option would be to change the chip to a 10A current sensor instead of a 30A one.

1 Like

Pete: DM me your address and I’ll send you one, I have 2 left to send out, I’ll keep one.

My thinking on the current sense is that it’s 44 millivolts per amp. The issue as usual isn’t the ADC resolution, which is 12 bits across 3.3 volts. That would be 3.3/2^12 = 0.0008056640625 volts per bit, which would be about 18 milliamps, yeah. But clearly you are not going to be able to reliably distinguish between voltages that are 0.8 millivolts with an ADC. There is way too much noise. You could take many samples and average them out, that’s not a bad idea.

It’s a matter of signal to noise ratio more than anything. And to be fair the op amp can’t actually help with that, but there is noise in the ADC and there is noise from other sources. The op amp would also add noise I guess.

I should have chosen the 10 amp version of the hall sensor, for sensorless stuff, and connected the op amps suitably. Well this still is giving us information we needed to know, it’s an experiment, but I should have looked more closely at the voltage. IMO the best thing would be to make the current sensing non-linear or something, or maybe use 2 pins, one for the most significant bits and the other for the least significant bits, to communicate the info (still as voltages though as that is quite handy although you do get noise). SPI interface would be good but the responsiveness could be an issue for HFI and other things. Parallel would take too many pins…

I’m sure some current sensors have programmable gains to solve this dilemma of needing good resolution at low currents but also the ability to measure high currents. I guess HFI would not be practical while high currents are passing, the combo of high resolution, accuracy and range is a tall order.

I will try to get in there with some very fine wire and connect one of the op amps and see what kind of signal I can get.

Does anyone know how to enable the op amps and set their gain? My experience with trying to set the uart pin was it was ridiculously complicated according to most sources but actually turned out to be easy.

Does simpleFOC make it easy somehow to do this?

1 Like

It might be a good idea to connect it to both the op amps and also, with the RC filter, to an adc pin, that way you could get more info at high and low ranges. Also don’t forget you have to block the DC component somehow, or compensate for it at the op amp input. The output of the hall sensor is half of VCC when no current is flowing, not zero. So if you have it mid range, the gain of the amplifier is useless because it would immediately raise the output of the op amp to VCC if the gain was more than 2.

Hey that’s actually kind of clever, you could do HFI even at high currents probably. You get info about near term, small fluctuations while at the same time get info about the long term lower frequency components.

There would be some distortion caused by the capacitor at lower frequencies which I don’t have a solution for… A more clever way of isolating the AC component is needed, maybe the op amp can work in a differential mode, then use a resistive divider to provide vcc/2 to one side of the amplifier.

That would not allow you to detect small amounts of current ripple by setting the gain really high but IDK how useful that even is…Better to know exactly what info is needed with what signal to noise ratio before hand, which I don’t :P. However the b-g431-esc1 board was able to get reasonable current info out of some low side sense resistors that were able to handle 30 amps. So similar volts/amp. Hm. So there may be hope

However the signal to noise ratio of the b-g431-esc1 board for current was pretty crummy at low currents. Definitely I need to swap in the 10 amp version of the hall sensor to help this situation out…

Andrew: do you know how to get the hardware oversampling going? Sounds like that would be useful one way or another for me and for others, to improve signal to noise ratio. Suggested code snippet?

I’ve been reading up on the opamps in reference manual rm0440 and the STM32 Arduino source code, and configuring them is confusing, but not terrible. I think you configure the GPIO to analog mode and then the OPAMPx_CSR register VP_SEL field determines which pin will be read. Similarly, the VM_SEL field determines which pin will be read for the inverting input, or you can set it to OPAMP_PGA_MODE to use an internal resistor. But I think you’re right that we’ll need to use a resistive divider to put vcc/2 on the OPAMPx_VINM pins due to the DC offset.

Around line 200 of \packages\STMicroelectronics\hardware\stm32\2.3.0\system\Driver\STM32G4xx_HAL_Driver\Inc\stm32g4xx_hal_opamp.h read the comments after the #defines like OPAMP_NONINVERTINGINPUT_IO0 to see which pin will be read when each opamp is set to that value.

And just for reference, the values of those #defines come from \packages\STMicroelectronics\hardware\stm32\2.3.0\system\Driver\CMSIS\Device\ST\STM32G4xx\Include\stm32g431xx.h

EDIT: It looks like there are certain ADC channel numbers reserved for the opamps, so you just set the bit OPAINTOEN (internal output enable) in the OPAMPx_CSR registers to direct output to ADC and then read from those channels. ADC1 channel 13 for opamp1, ADC2 channel 16 for opamp2, and ADC2 channel 18 for opamp3. The HAL has special defines ADC_CHANNEL_VOPAMP1 and so on for the internal channels, but I think they’re just for error checking. Hardware-wise there’s no difference than reading regular channels.

Please do test whether it actually improves the signal quality, though. The second current sensor is connected to PA1, so you can configure opamp 1 to read that, and construct a voltage divider and connect it to PA3. If using the HAL library, I think it would be something like

OPAMP_HandleTypeDef handle = {0};
handle.Instance = OPAMP1; // Register base address
handle.Init.mode = OPAMP_PGA_MODE;
handle.Init.PgaConnect = OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS;
handle.Init.PgaGain = OPAMP_PGA_GAIN_4_OR_MINUS_3; // Or whatever other gain you want
handle.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_IO0; // PA1 is VINP
handle.Init.InvertingInput = OPAMP_INVERTINGINPUT_IO0; // PA3 is VINM
handle.Init.InternalOutput = ENABLE;
HAL_OPAMP_Init(&handle);
HAL_OPAMP_Start(&handle);

And then read ADC_CHANNEL_VOPAMP1

EDIT2: There’s some opamp code in Arduino-FOC\src\current_sense\hardware_specific\stm32\b_g431\b_g431_mcu.cpp for better reference on how to set it up. But rather than routing internally to ADC, it has them configured to output to pins, and then the ADC channels of those pins are used to read the output.

It’s easy to use. Just an enable bit and two fields in the ADCCFGR2 register. One is how many samples to take (2,4,8,etc.) and the other is how many bits to shift down after adding them all together to avoid overflowing the result register.

1 Like

No. OpAmps are totally out of scope for SimpleFOC, this is a very hardware specific question. Perhaps at some point in the future we’ll have a hardware-specific driver for STM32 or something, but at the moment you’re on your own…

There’s the OpAmp library from MaxGerhard for UNO R4: GitHub - maxgerhardt/uno-r4-opamp: Demonstrates simple OPAMP Usage of the Renesas chip on the Uno R4 WiFi.
But I’m not aware of an Arduino lib for the STM32 OpAmps so far. Pointers welcome if anyone has knowledge of such :slight_smile:

Our B-G431-ESC1 driver code has an example setting up OpAmps, and is also an example of the kind of changes you’d have to make to configure them in the current sensing.
Because unfortunately SimpleFOC not only doesn’t support configuring the OpAmps, but also the default code for STM32 current sensing has to be adapted to support them.

In terms of figuring out the HAL code for configuring OpAmps, as usual STM32CubeIDE is your friend, you can configure ADC and OPAMPs there and then adapt the generated code into your sketch.

Normally all OPAMP pins will also be ADC pins, and you can configure the chip to use either or even both functions on the same pin. So it should not normally be necessary to sacrifice a second ADC pin for this.

2 Likes

[OT] I’m following this forum for more than a year now and the STM32 family seems to be thee MCU to go for.
I know the goal is to keep it arduino compatible, but I’d like to see a more STM friendly branch of sFOC in the future

ST-Micro certainly make some very nice chips. But for many of our users Espressif chips are also very attractive options. And in terms of performance, the NXP chips (Teensy) are probably the fastest chips we support, although less commonly used with SimpleFOC.
And while I personally don’t much like the Raspberry Pico, many people are crazy about it, and as a ā€œfirst entryā€ to the MCU market it’s pretty strong. So I think the next generation of Pico could be something to watch for too.

But from what I recall Runger, you are behind the stm32 choice for motor drive, no? The features with the floating point, timers and other stuff are quite valuable?

I think even within a class like stm32, it would be a huge amount of work to support even a fairly broad number, with a thorough feature set. Also code snippets like the one above are totally ok, but we do need that because it takes hours sometimes to get a snippet like that working (haven’t been able to test them yet btw :().

Starting by supporting one mcu, on one board, thoroughly, and then branching off from there can give more results for more people faster, making it imo more interesting and worthwhile in many ways. If you read up about the GNU project, they also in the early days tried to do a really really thorough and broad job, but it took so so long it wasn’t the right approach. I do that too, indeed I did just recently with the small fan…spending a ton of time working my way to a supposedly superb result, but it took so long I had to bail anyway, delivering nothing much good to anyone.

But there is still the big fan on the horizon, for which I do very much need this board, so I will come back to it.

We like to dream and that’s part of what brings people to projects like this, but it’s also very rewarding to see something tangible relatively soon…

Pete: I need your address remember if I am to send a board. You may wish to wait to see if I can mod it to connect the op amps and set their gain, or wait till the next version which has this built in, but if it works for you the way it is I’ll send you one and you can do whatever and prove out the other aspects in the process. Not as efficient, but in some ways faster.

1 Like

What do you mean by ā€œmore STM friendlyā€ ?

Hey Valentine!

I know I’m sort of late to the party here but I’m super impressed with your work and the community here. I was thinking about getting some of these boards, probably a 10ct order from JLC for various projects but I was interested in the specs that you mentioned – mainly ā€œ30V, 30A max thermal and copper limitedā€. The MOSFETs you have on this board are rated for 60A, and because it’s thermal and copper limited, would it be possible to simply just increase JLC’s ā€œoutside copper weightā€ from 1oz to 2oz and add some active cooling?

Might be a stupid question, honestly – am not too familiar with the ins-and-outs of PCB design.

Thanks!

We all welcome you and thank you for your enthusiasm!

Yes. This is the correct way of handling this.

It might get a little costly however, please be mindful. Also you may have to increase the inner layers thickness as well as they carry the ground return current.

Please come back and post cool pics and vids of your project(s).

Cheers!
Valentine

Thanks for the help!

I did notice the hefty price increase (internal crying) but I am willing to fork over the cash for what would be effectively $20 per driver as compared to regular ā€œ60A ESCsā€ that don’t have FOC control.

Just to be clear – 2oz (instead of 1oz) external copper weight and 1oz (instead of 0.5oz) internal copper weight would be adequate for 60A use? Would I also need to increase the internal copper weight to 2oz or is that overkill and an unnecessary expense?

Let me check and do the math.

Cheers,
Valentine

Outside 2oz, inside 1oz is probably as close to the limit on that board as it gets.
You will need really good cooling, think forced air cooling mounted on a drone under the propellers.

You need to be extra careful as the current sensors were not sized for 60A !!! They are sized for 30A max. You will need 60A current sensors. The closest you have is CC6920SO-50A When you hit 50A you will start clipping the current signal.

This is really pushing it. What is the need for that high current driver, is it the size you like, or the cost or both? If that’s a hobby project, I could probably give you some helpful hints.

On current ratings, the issue is usually thermal in nature. Because of this, current rating can depend on lots of factors, like duration of pulse, duty cycle, ambient temp, cooling, etc.

If you’re only ever going to hit 60A for a few fractions of a second at a time, and then only rarely, there’s probably no meaningful change needed. If you’re gonna run some vertical lift without a gravity counterbalance, so 60A for minutes at a time, that will probably need some real effort to keep the smoke inside.