Category Archives: Motor Controllers

Current Sensor Math

I currently plan using INA194 that have a 50x gain. As our max voltage in is 3.3V this means the max voltage over the shunt need to be 3.3/50= 66mV. Given a max current of 2.5A that gives a Shunt resistor R = V/A = 0.066/2.5 = 0,0264 R or 25mOhm.

Now – 2.5A over 25mOhm is 0,156W which is fine since the 1206 resistor is 250mW.

If I use 50mA that gives 0,00125V (1,25mV) into INA194. And with a gain of 50x that is 62,5mV into the MCU. This is where we get into trouble because INA194 starts being inaccurate below 50mV in. I am not at all sure I actually can measure these low currents, but I do have one SW trick to help me.

We are NOT measuring a constant current, we are measuring a PWM pulse current, and the current we will see is 2.5A for 1mS and 0A for 999mS (just an example) due to the nature of the PWM. In software that becomes 2,5A / 1000 = 0,0025mA in average over a sec. So, if I take advantage of the 2,5Msps capability on the STM32 M4 I should be more than ok. I just need to make sure my sample frequency is at least 2 x the PWM frequency, but the higher sample frequency the better in this case.

Yet another trick is that I know then the Pulse is On/Off, and since we have raw data (no electronic filtering) I can eliminate noise then the pulse is off – as I simply know there should not be anything there. This is more difficult to do than I write here, but I will dig into it.

I used 2.5A as an example, but pulse current is V/R and can be higher that the rated max. This is why some MOSFET’s are rated to 160A with a pulse current to 400A etc. If we have motors with low inductive R we reduce PWM duty to maintain 2.5A in average, so I might actually need to cut down even further on the Shunt to avoid clipping on pulse currents, but I will not worry about that for now. I want to experiment with actual values because you can only cover so much in theory. Noise etc also add to the picture and is not easy to predict or model accurately.

The irony is that I removed passive filter components because of lack of space, and those filters would have prevented us to see the pulse currents. Now – since I have raw noise in I can actually use SW and see far more accurately than I would have done with analogue electronics. This is an excellent example where you need a good interaction between a HW and SW engineer.

3-Phase/Stepper Routing

Left side of the 3-Phase/Stepper/PWM Hat done. This is the hardest bit, but it went much easier this time because the previous attempts gave some hints and lessons learned. I am far from finished, but it is not hopeless. My main concern is the ground-plane getting to fragmented and unable to support the currents – but, I am not out of tricks yet.

This picture show the back-side and the ground input is actually the “2” in the left, bottom corner while DRV8313 are on the inside of that thick 36V power lane. While Ground is connected you can see that it is thin on some places due to the density on the left side. it will be equally dense on the right side, so what I am considering is to add a bridge on top lane (illustrated in light blue) to ensure that I have a direct path that will support the currents I need.

I must admit that doing PCB routing is a bit like a puzle. You need to like these mind games if your going to be good at this. I know many electronic engineers who seldom do PCB routing – only schematics.

I have suffered “Crash O’ Mighty” on this Board a lot. I use a free version of a Target 3001 EDA based on Java and well – it does crash a lot. I am also more and more feeling the pain and limitation of 2-layer designs, but I will need some time to get started with KiKad.

What worries me a little is the signal integrity of the current sensor signals. But, it is nothing I can do about that. The issue is that the ADC signals need to pass strong PWM signals, so that current on one PWM might give a false signature on a 2nd PWM’s current sensor. I do however have the option to filter and compensate for this in software, so lets see. I do expect noise on these signals regardless.

New 3-Phase/Stepper/PWM Hat

I am returning to this board to make a new attempt because it is a very attractive board to make + I just received another bunch of DR8313 chips and Connectors that I need to use for something. What stalled me on the last attempt was several issues:

  • 12 x current sensors are a bit hard to route and I basically forgot that I needed wide power lanes, so I need to make space for them.
  • DRV8313 is rated to 2.5A in peak, meaning that I can’t get 2A out per channel as that would be 6A per chip.
  • Space in general.

The 2.5A limit is worst for PWM stand-alone signals, but the actual target is 1A and I can always combine output’s to achieve 2A. I need a bit of testing, but I think that will work just fine. 2.5A is just fine for 3-Phase and Steppers. The one drawback with steppers are that we need to do a bit more logic in code, but we have the MCU capable to do that and I want a stepper with current sensors.

The one thing I need to test is the current sensor. INA194 have a very attractive footprint and voltage range, but I am a bit concerned about it’s datasheet. It basically need 50mV input before it become ca 1% accurate and with a gain of 50x we basically run out of 3V range at 60mV input. I also use 0.25W shunts to get 1206 footprint (size) so it’s not straight forward to decrease gain and increase shunt resistance as I start using to much effect.

I also need to test currents through DRV8313 and I have a small 3-phase that I can use for that purpose. This is a simple test to run constant current and use a finger to test temperature to see what I can get away with without a heat-sink. But, heat-sink is actually straight forward because DRV8313 use a pad connecting to ground so we went out on the back-side and can add a heat-sink directly to the PCB.

What I will do is to mount INA194 on the breakout boards I made earlier and test. The reality is that I don’t need current sensors to be that accurate, but I need them to indicate levels on low currents (50mA and up). Used on a 3-phase that helps me detect rotor position so I can use vector based algorithm’s. And for a stepper it indicate torque so I can detect end-stops without an external end-stop sensor on CNC machinery.

I can easily make a separate 3-phase, stepper and PWM board, but the combined functionality of this board makes it very attractive to implement it. I can always go into 10cm width to get more space, but I want to make one more attempt on the current size format first.

The different approach I want to try is to move the connectors to the left and right and have USB/Power in the middle. I believe that will allow me to get away with less space around the MCU + I get 2 x DRV8314 on each side.

As for space – the connector account for a lot here and I could get away with a lot less if I made a specialized 3-phase or Stepper Hat as I then would use right angle Micro JST connectors. It is the need for a combined connector that made it attractive to use this footprint. But, I also notice that the smaller JST Connectors handle less mechanical stress. The connectors I use here have 2 pins per channel to handle to make them more robust.

The 10cm wider board will need different width of these connectors, but as I get more space I could also consider adding galvanic isolation between Driver and MCU. We are after all dealing with a lot of effect and coils here and I will need about 6mm to support an array of photo couplers. A quick look at the mockup below indicate that this actually might be possible.

Failure of the week

This would have been an awesome Hat, and I am “kind of” done routing the PCB, but my remaining challenge is the currents that I need to support. My PCB lanes for 36V+ is far to thin for 12-24A, so this will never work!

This version of the Hat have 12 x Current Sensors. One of the challenges is that DRV8315 have Pad’s going through all layers for venting and this act as a barrier against any routing signals. I could have managed this board with 4 layers, so I think it’s time to make that change.

The area between DRV8313 and the connectors get to dense in the first place and this is where I need to apply 36V+. The option I have is to use thick air wires, but I basically have no room for them.

The alternatives I have is (1) try to push some of the components to the back side, (3) use thick air wires, (3) use a larger PCB or (4) ditch current sensors.

This being a Hat the size is set, but I used a wider format on the 3KW motor controller so I can use the same here. One of the challenges with DRV8313 is that it has 2 VM pins separated rather than together. This is from a functional point an excellent driver, but the design require some space around the DRV8313 if you want to use it’s features.

 This is a mock-up of the wider board. I extend width from 65mm to 100mm. I need to change connectors a bit, but it is an illustration. I have not given up the original format yet, so lets see.

Connector Size

These 2.54 pitch spring terminals occupy more space than I hoped for, so I had to abandon current sensors on each DRV8313 to get room for them. The red areas are the spring connectors. The yellow is the MCU which I desperately need space around since I will be taking out close to every pin on this design.

I will add in a common current sensor. I also realized that for the current sensors to be of usage for 3-phase I need to mount it on a single PWM outputs (phase current). That array of 1206/1210 components are the capacitors. I decided to remove the larger one and replace them this an array to get the profile down.

Heat sink on this Hat is very straight forward – you mount it on the back to cool down the PCB. Notice that each DRV8313 have an array of holes connecting and venting out on the back side, so it is fully possible to mount this straight on a heat-sink.

Taking out 18 PWM signals on such a small design is maybe ambiguous, so I could drop down to 12 – 3 x 4-Phase, 3 x Steppers, 6 x DC Motors etc. If I did that I could move the MCU to right and attempt 12 (or 6) x current sensors.

The reason I keep on about current sensors is because they enable positioning on a 3-phase as well as torque calculations on both 3-phase and Steppers. With torque calculations on Stepper I could avoid end-stops on CNC machinery etc – simply detect where the end is and just put up a mechanical stop. To get more channels I can just stack up boards, so adding the sensors back is worth more than channel density + 12x 2.5A PWM channels are still a good. Hat.

Raspberry PI Hat’s

It’s been many Hat’s lately as I am focusing more and more on this as my main core for everything. I still have a load of Hat’s that I want to start on, but I won’t exactly have much spare time the coming year. This is just a summary of projects that I am working on and intend to complete.

XPortHub. Basically a communication Hub With CAN, RS485, RS232, SPI, I2C, USB + Micro SD Card, RTC, Flash etc. This Board is actually assembled and so far working well.

Wifi Hat based on ESP32 to enable a low-cost Wifi/Bluetooth With CAN, RS485 and a few IO ports. I have PCB for this Board, but have yet not assembled or tested it.
32 x IO / Servo Controller.

Not ordered.

8 x DC Motors + 16 x Sensors.
7 x 5-Wire Stepper Driver.
3KW Universal motor driver, Capable of 60V @50A on 3-Phase, DC, Stepper or Solenoids.
NB-IoT/4G Hat.
Light-weight 60V PSU. This is only a test board with the Hat format.
LoRa + GPS Hat. Shown With 12km 1W configuration.
LoRa + GPS Hat. Shown With 6.5km 0.1W configuration.
2A Motor Controller. Can run 6 x 3 Phase, 4 x Steppers, 9 x DC motors or 18 Solenoids/PWM signals. This is still work in progress.
3KW 3Phase Motor Controller. This uses DRV8301 and is designed for 60V@50A. This actually need a revision before it is ordered.
Mini stand-alone 3-Phase Controller for 2A. This is assembled and is working, but the 60V DC/DC needs a revision.
CAN – USB Adapter. Assembled in rev 1.1 and working.
ESP32 Utility Driver – 4 sensors, 8 Servo/IO, 2 H-Bridge, 7 PWM signals. This is assembled and working rev 1.1.
Model Train Cockpit Controller. This is a failure and need a revision + a support adapter. A rev 1.2 is on my list.
STM32FxxxRx Breakout Board. Assembled and tested for F105 and F405.
Breakout for STM32F031F4 or STM32F042F6. Assembled and working.
My SWD Adapter. This will need an upgrade, but it has been one of my most usefully designs. It enables me to use a small 1.27 pich footprint on my designs and deal With ST-Link 2.54 Pitch. Next Version will have Reset and Boot Connectors.
Micro sensors and actuators. I had 4 of these designs and the Temperature, Light, Proximity sensor will be upgraded. More external sensors will be added later.

And more – many of my older designs have either been ditched or evolved into more mature designs listed above. I will be focusing more and more on the new Raspberry Hat format for everything. The exception will mainly be a series of intelligent sensors evolving out of my STM32F031F4 micro designs.

 

 

2A Motor Hat – Connectors

Connectors on this board is a challenge because I want to support 3 different usages:

  • 3-Phase that require a 3 pin connector.
  • 4 wire stepper that require a 4 pin connector.
  • PWM that require 1 pin + ground for every signal.

The board above uses 2.54 pitch connectors with space to mount small screw terminals. The ones I show here is just an example with a 18 x PWM and 18 x GND connections. These screw terminals are good, but they require access from top – so an alternative is to use something like the ones below that are right angle.

These are 2.54 pitch – 2 rows with 5.08 pitch apart. A bit big for my taste, but I think I can support them. And they don’t rule out anything as 2.54 pitch is very flexible. Height is an issue because PCB separators are 13mm to fit headers – these are 11mm on the back and a bit taller on the bit that will stick out from the board – I thing they will fit well.I need to make a package and show a 3D with these on a bit later.

3-Phase-/Stepper-/PWM-Hat

I have both 3-phase motors, stepper motors and PWM Hat on my list, so I want to use DRV8313 because this delivers 3 individual Half H-Bridges that are excellent for all of these options then combined together. I am pretty sure I can get 6 of these drivers on a Hat which would give:

  • 6 x 3-Phase Motors,
  • 4 x 4-wire Steppers, 
  • 9 x DC Motors, 
  • 18 x Solenoids/PWM signals. 
  • or any combination of these.

This would actually be a very powerfully Hat.

Looking at STM32F405RG I actually have 26 Timer pin’s with PWM capacity so this looks very doable. What I want to add in addition to DRV8313 is INA193 (or INA194) to measure current on each DRV8313. Ideally I would have this on every PWM, but I am running out of space here, so lets see where we land.

Getting 6 x DRV8313 on a Hat is very doable, but I will need a 60V DC/DC and 6 current sensors as well + a DC-Rail sensor – that is 38 extra passive Components. 

An early mock-up like the one above is just a quick exercise to place the actual components on the PCB for a reality check – and this does not look like a go to me. It is not just about placing components, but all the lanes I will need between them. And it is still capacitors etc that I would like to place here.

So what can I do?

Firstly – 60V is a bit ambiguous for this board, 36V (meaning 24V) is more workable meaning I can ditch the 60V/3.3V DC/DC. That helps a lot.

The second option is the filters that I have on the current sensors – I can remove these from electronics and do them in software – that will reduce 36 components to 12 and the density of the board is suddenly far more realistic – and less complex.

The capability to remove filters from electronics because I can do them in software is something I often face, and in this case we can due to the raw capacity of the M4 MCU. This last mock-up looks far more doable. And I am happy with a 24V limit on this board because this is for small 2-3A motors that seldom needs higher voltages. Now – lets og and design this one!

MC4X60V50A as a Hat

Updated 3D Model 18.dec.2018

This is a bit more than a mockup since it is almost complete, but adding 15mm to an existing design is a lot of extra space. I turned the Hat so that the Raspberry PI Ethernet would be at right. Basically this is 35mm wider than a normal Hat, so it is still small for a 3KW Motor Controller.

Actually I now have some extra space so I can add in a few things. I ditched a RS485, but I would also like more sensors if I have pins/space available. I have a connector to connect 5V on PI to 5V from Motor. This enables MCU and Driver to have separate PSU. I can also add pins to mount extra capacitors behind on the left side. This will be perfect as they will be left of Raspberry PI or other Hat’s. I actually could remove the large 1000uF capacitors on top to save some Space, but lets see how it works out.