8 x DC Motor Hat

This is the updated 8 x DC Motor Hat w/16 x Sensor IO’s. I have 3 Hat’s that I will order with PCB stencils this time. This Hat was basically made for a robot arm I have build by DC Motors. It’s a bit of fun to see if I can control the arm automated as DC motors don’t have any positioning.

Changing the blog

I don’t have the answer to this riddle yet, but I am searching for a more structured way of doing this blog that don’t involve myself digging into web development. I simply don’t have the time (or skills), so I am depending on either someone else assisting or finding a plug & play solution.

At present I use WordPress that is very capable, so I will look into different templates. What I want is to continue the blog as the main page, but I need articles to go on separate project pages to allow more continuity. I also want to re-open the comments field and add Forum as I move forward. I actually own both BasicIP.Org, BasicIP.Net and BasicIP.Com, so I might put them to use as well.

I guess what I am saying is that you might see a lot of experimental changes the next days/weeks before things settle. For now I will try changing Categories to be projects and see how that works out.

Unipolar Stepper Example

The logic for driving these stepper motors are straight forward as you apply 4 or 8 steps. The 4 step logic is faster and you rotate in a circle CW or CCW:

  • Step 1: 0 + 1
  • Step 2: 1 + 2
  • Step 3: 2 + 3
  • Step 4: 3 + 0

This will create a movement in one direction as you only move one step at the time, meaning you have position Control and speed Control by how fast you apply steps.

The 8 step logic is similar, but only uses half the speed.

  • Step 1: 0
  • Step 2: 0 + 1
  • Step 3: 1
  • Step 4: 1+ 2
  • Step 5: 2
  • Step 6: 2 + 3
  • Step 7: 3
  • Step 8: 3 + 0

To decrease the stepper logic even further we need to get a bit smarter because direct 0 and 1 logic cannot help us more. We can control speed and direction. Maximum speed us set by the minimum time we can have a coil on before it moves. I found that to be ca 3ms on 5V, but this will vary depending on the Stepper Motor. If you use 12V on a 5V Motor (which is a bit naughty) you might find that you can do this faster.

A stepper can’t increase speed much further due to cogging torque that is very strong on a stepper. On a 3-phase motor this will be weaker so we can increase speed though acceleration. This is not impossible, but it is not what a Stepper is created for. We can however decrease the steps further for a more accurate positioning system.

You have to be aware that as you decrease below full steps you also decrease the holding torque and your chances of a miss-step increases.

To decrease further we need to apply an analogue value on the steps. If we as an example allow a step to be 2.5V and 5V this would allows us to create a 16-step algorithm. But, how can we create an analogue output value using only PWM?

The answer is that a PWM with 100% duty is the same as 5V, while the same pulse with only 50% Duty is 2.5V. To drive a step we need output voltage on for a minimum of time. If we stop we will be “holding” that signal, so what we do is to build a PWM signal from a higher frequency where we can manipulate PWM duty and hence create a different analogue output value.

The picture above illustrate the two pulses. The 5V pulse is always on giving 5V out, while the 2.5V pulse is 50% on/off creating 2.5V output value. This will now allow use to create 16 steps. In fact using a sinusoidal curve we can now create as many micro-steps as we want.

The last trick is how you apply the 2.5V output value, because step 1 with 2.5V and 5V is still the same position. To use these mid positions you will always need 2 coils. Full steps are then one coil is on and the other off. This gives 2 position only. But, as we now can apply 2.5V we can evolve the logic as follows:

  • Step 1c: 0=5V (full step)
  • Step 2a: 0=5V, 1=2.5V
  • Step 2b: 0=2.5V, 1=5V
  • Step 2c: 1=5V (full step)

If you complete this table you will have 16 steps. And by adding 25% duty steps you have 32 steps etc. But, remember that cogging torque that hold your position will be weaker, so these micro-steps do come at a cost.

Programmable Function/Audio Generator

I bought a kit with AD8950 earlier that I consider using to create a programmable function/audio generator. AD8950 can generate waves to very decent frequencies and cost ca 10.- USD. AD8951 cost a bit more and it is straight forward to create a DDS/DAC based on these. But, I also need a driver stage where I can select output voltages in positive and negative values. The later is more important than high frequencies, but I could have 2 output’s – one 3.3V signal and one +/- with a programmable voltage selection.

The base concept is similar to creating a DC/DC PSU, but with the exception that I use AD8950/AD8951 to create the “PWM” signal. Also, since the signal is an actual waveform we need to use linear transistors like a high frequency audio amplifier. It would be nice with 1A out, but 100mA is also ok.

The more difficult stage is to be able to program the +/- output levels. One way of doing this would be to use 2 DC/DC converters in series. The first to set +/- DC levels for a Waveform amplifier. But, I will need to do some research here.

This would however be an awesome Hat and I also wonder if I could put the 2 x I2S and/or DAC channels on STM32F405 to use to generate waveforms rather than using AD8950/AD8951. I would not be able to reach the same frequencies, but I am pretty sure I still can reach decent output frequencies and we could play audio files/channels as well.

Using DAC/I2S I can probably generate waveforms up to 200Khz. Using AD8950/AD8951 I can reach 20Mhz at least.

At this stage I want to let the ideas mature a bit while I do research and talk to friends more skilled in analogue electronics than I am.

Programmable DC/DC

One of the ideas I am playing around with is to make my own programmable DC/DC PSU based on a MCU. The technique is very similar to a driver channel on a motor by generating a PWM signal. To get a DC out you add filter(s). If you have 48V and 50% PWM duty the output should be 24V etc. The advantages of doing this is that I can switch PSU’s on/off, monitor system currents and use the same module for 5V, 12V, 24V and 48V. And with some of the SO8 MOSFET’s I have used I can deliver 10-15A from a Hat size PSU. I also get the advantage that I can deliver multiple voltages from one input Source and Control how I ramp up/Down Power in a system.

I have done the experiment with the motor drivers, so I know this will work. My main concern is the space needed for capacitors and coils for 10A.

The illustration above also show a PSU line with a relay and current sensor. It is also an option to simply have 3-4 relays, current sensors and capacitance to control power delivered from external modules. The advantage of this is that I can just buy 3rd party PSU’s and plug them in, but it will require a bit more space.

It would most definitively make an interesting project as we also could add programmable output curves like a low frequency function generator.

Space is a concern because I need to take into account that I am driving motors, so we need output capacitance and protection. It might be that a Hat size format is out of the question both due to size and height requirements for the components I will need.

60V DC/DC Working

Good news is that TPS54160 is working. C5 & C4 did the trick of getting me past 35V input. I tested 50V In for now. Minor is that the values shown on R1/R2 and R5/R6 are wrong. R1/R2 can be dropped to always enable the DC/DC. R5 needs to be ca 140K for 12V, the value shown is 3.3V.

A bit more annoying was the three caps in red. This pic looks like it is sufficient space between them, but it was not. I did not have 4.7uF caps in 1206 size, so I used 10uF (yellow) that worked fine.

I am also a bit concerned about the height of those 1000uF/25V capacitors, so I might need alternatives here. Always good to get a PCB so you can deal with mechanic changes as well. I also wonder if I should add a different connector for 12VE, 5VE and 3.3VE signals to make it easier to connect them to a MCU.

A bit concerning was that the first TPS54160 only gave ca 50% output values. As I changed to a TPS54060 the output value became normal according to datasheet. Datasheet ask for very accurate resistors etc, but I don’t care as long as the output voltage is ca correct.

But, all in all this was a success. I am really happy to see TPS54x60 working as expected.

Motor Controllers

These are the 4 different motor drivers I have made so far.

The smallest (at left) is capable of 24V @2A. It uses DRV10983 and one of the smallest STM32’s. I got it working, but I had some trouble controlling the logic to behave.

The second one uses a DRV8313 that basically is 3 x Half-Bridges. This works perfectly, but I am not to happy with the Hall Sensors on it + I had some challenges with 30-60V supply. I was however very pleased with the performance of DRV8313 which is why I also use this for a Hat.

No 3 from left is a 24V @ 15A on 4 separate Half-Bridges. This is designed to drive a decent 3-Phase or Stepper. I tested the driver for 10A fine, but I had serious challenges with dodgy MOSFET’s from Asia on this. The only part that I have not been able to get working is INA210 current sensor, but I have 9 left. My initial thought was to abandon this design because the next one is so much more powerfully, but it is also a matter of size. I was all in all quite pleased with this design.

The last one at right is an upgrade to 60V and 50A + I use the Raspberry PI Hat format. The story of this one is yet to be told.

The designed max effects are 48W, 120W, 240W and 3KW

Wifi Hat Working

Replaced ESP32 on the failing Hat and Wifi worked. Seems like I had my first ever failing ESP32 module. The Wifi Hat is No 2 from top. This stack includes (from top):

  • 7 x Stepper Hat
  • ESP32 Based Wifi Hat
  • XPortHub
  • XPortHub
  • Raspberry PI 3A+

I have 2 USB ports connected here and both show up correctly as Serial ports in Windows. I have a practical problem here programming the STM32F405’s in the middle of the stack – and moving to that 6 pin 1.27 pitch header might not be the smartest I have done. The intention was to mount a JST 6 pin Micro Header, but I had some challenges with the one board I tried this on. I need to set up a test with a MCU I trust and see how it works out.

To program this I probably will use Visual Studio for Raspberry PI, Arduino IDE for ESP32 and Eclipse for STM32. Whatever works! My next task is actually to get SPI working, so that will be interesting. I have never tested Half-Duplex SPI before.

Unipolar Stepper Logic

This is the diagram of an Unipolar Stepper Motor with the 5-wire connector at right. The most used Unipolar stepper is the 28BYJ-48-5V pictured below and this is the target of my 7x5WStepper Hat.

This is a high quality/low cost stepper available for < 2.-USD. I purchased one for test and was quite take by its performance. It is silent and its 64 steps/turn is better than you expect due to the build in gear that also makes it strong. It is a bit slow, but all-in-all this is a really excellent stepper motor which is why I decided it needed it’s own control Hat.

Running this is dead simple as you apply 4 steps in sequence.

  1. 0+1
  2. 1+2
  3. 2+3
  4. 3+0

Reversing the sequence will run the Stepper in the opposite direction. The algorithm have some similarities to trapsoidal on a 3-phase, but the difference is that 1 step moves the motor one step due to the strong cogging in these motors.

To assist us I will create 2 C++ classes. One is hGPIO that wire up the pins, and the second is hStepper that takes the pins and steps. So with an array of 7 x hStepper I should be able to run 7 steppers simultaneously.

What is interesting with this is that one Hat control 7 steppers, 2 Hat’s 14 steppers and so on. And as the Steppers are low cost it is realistic to build some advanced robotic Experiments.

 

HAL

All MCU vendors will deliver some C code they call “HAL”, while I call that Low Level Drivers (or BSP – Board Support Package) and implement my own HAL (Hardware Abstraction Layer). A proper HAL need to abstract from hardware and secure portability of code. But, most important is that I want to write source code in C++11.

StarUML cost a few bucks, but I like it and it’s the only alternative I have found to do decent UML class diagrams. The class diagrams makes it easier to maintain overview and as such they improve quality of software architecture and documentation + they don’t take much time to draw.

I started learning C back in 1983 and coming from languages like Jovial, Fortran, Basic and Pascal it felt like heaven in comparison. Later in 1994 I learned OMT and C++ that was a good fit and I have been a C++ fan ever since. Yes I use C# and Java as well, but only if I can’t avoid it.

This blog have so far been more about electronics than source code, but I have stated a few times already that this will change. The starting point is 3 libraries that will form the basis of all we do.

The first is HAL – Hardware Abstraction Layer. A library that systematically encapsulate hardware in a functional, abstracted way.

The second library is EFC – Embedded Foundation Classes, a library of tightly written C++ targeting embedded MCU’s. This library was started years ago and have been mentioned before because as soon as I move on functionality I also need building blocks.

I will return to the 3rd library/tool later.