One major issue is how to identify units in a network. I used STM32F030F4 on these and I absolutely love this little MCU costing 50 cent in TSSOP20 package, but it lack the serial number that is burned into other STM32 MCU’s. This serial number is crucial as it present a factory set ID allowing me to just plug in sensors expecting them to identify themselves. STM32F042F6 solves this, but cost ca 2.- USD from the sources I use, so I am very tempted to use STM32F103C8 or CB and create a larger PCB so it becomes single sided. The later actually lower cost in production – but, lets see where we land as I update the modules.
My grandparents passed away some years ago leaving a beautifully mountain farm behind. As no-one lives up there we have to leave the farm unattended for months at the time. This is a challenge in winter time as we fear the water pipes with freeze. The farm actually got internet installed so it is possible to use internet to create a remote controlled automation system.
Using Internet for anything you need to address security. Using Windows these days is not an option, so I am happy for Raspberry PI as base units. I am no web service expert, but I believe I can communicate directly between my home and the mountain farm by using a Address Lookup Service that we need to create. Basically the HMI and PLC both connect to internet and get details of whom to communicate with through a public service. Once the address is known they create a secure tunnel for communication. I will deal with security later, for now lets just assume this works and that we can use mobile devices as HMI.
The system I want to create will consist of a range of modules:
- Redundant PLC Base with mains, battery, wired and mobile internet connection as well as connection to sensors and actuators.
- Sensors for temperature, humidity, water leaks, light, movement etc.
- Camera, speakers and microphones. Actuators swithing on/off heat, opening/locking doors etc.
I use the mountain farm as design base because it present a few challenges. And I obviously want to control this using Plain.
I just uploaded a design doc for the Universal Motor Controller on the downloads page. I used LibreOffice 5.3 since it could export to PDF, but believe me this is the last time I use that. I had so many problems importing drawings that I ended up importing everything to Word and then copy & paste as bitmap from Word to LibreOffice. LibreOffice doc’s and illustrations is not a good combination. I like LibreOffice, but I like Things that work more!
This is the front and back 3D model of the Rev 1.0 of my Universal Motor Controller. I will be leaving the non-isolated RS485 for now. I want to do some changes around the MCU layout later anyway as I actually have a lot of spare pins here, but lack space to support a com adapter. This board is 80 x 40mm and only 2-layer PCB with a lot of functionality.
Design doc is located on the Download page!
The HEXFET on my Universal Motor Controller is 30V, so I decided to change my existing DC-DC to 12V out and add a classing LM1117 for the 3.3V. The LMR14206 based DC-DC is basically so small that it is not much larger than LM1117 on PCB space. It is restricted to ca 800mA, but it will only drive the gate drivers, MCU and com etc so it should be sufficient.
I did find a few DC-DC converters with a different range on Voltage/Ampere, but they also use more PCB space. Jumper J5 and J11 allow 12V to be connected directly if your using 11.1V battery etc. The issue is that the Gate drivers need 10+ V to operate and as the DC-DC will drop 1-2V we might get a challenge using 11.1V LIPO batteries so I added the jumpers in case they are needed.
I would have loved to operate from 5V and up, but to do that I would need a very powerfully step-up DC-DC converter as we would feed the motors as well. It is doable, but it add to the size. We will be looking at optimizations later anyway.
This 2nd diagram is also part of the PSU and show the adapter connector as well as the P4SMA suppression diode from Vishay. This will break down around 27ich V and suppress any unwanted pulses. These diodes are life savers, but they take some time to react which is why you must add an adapter board with either a capacitor or battery. What will happen is that capacitors will take the edge of the pulse giving the suppression diode time to suppress the pulse. If you have a large capacitor or battery that will need tom be “filled up”, meaning that the diode will only react if the battery or capacitor is overrun.
If you recall my previous breakdown and discussion I concluded that a 24V motor can spike up into 20x (480V). The HEXFET’s will basically short those spikes and might be feeding them into the PSU part. A capacitor/battery can charge that energy, but we have a suppression diodes around to prevent that these spikes do damage. The basic adapter Board is only a specialzed vero Board to allow mounting of hole-through capacitors.
I designed this universal motor controller capable on driving DC-, Stepper-, BLDC- and even AC – motors earlier. The design parameters was 12-24V at 15A. This is quite a capable controller, but I did a mistake that limit the controller to 12-20V since I connected the Gate Drivers to the Motor PSU directly. To compensate for this I need to modify the design and implement a separate 12V PSU. As I correct this I also want to consider some additional changes.
I am considering is to replace the RS485 with an isolated RS485 due to the amount of energy involved. The 3rd change is Ethernet on a separate adapter board. Basically I want to copy the modules I use on the Universal Adapter as soon as I have tested them.
I am not sure about Ethernet. Ethernet sound nice due to the functionality, but it is a clumsy, 4-wire 1:1 solution. RS485 is slower, but it is a 2-wire network. It actually makes more sense having dual RS485 to be honest. CAN & Ethernet is easier to deal with using an adapter board- RS485 is considered a lower level of communication than CAN because CAN have protocols like CANopen, J1939 etc. The reality is that if we use RS-X that changes.
What I probably should do at some point is to create a “Ethernet” on top of RS-X by using a dual RS-X connection. But, that is fun for later…
So the modified design will be
- STM32F405RG MCU, 168Mhz, 32bit M4, 1MbFlash, 192KbSRAM
- 4 x separate half bridge drivers, 30V @15A
- Current sensors on all
- BEMF sensors
- PSU Voltage Sensor
- Separate 3.3V supercap to sustain MCU in power dips.
- 3 x hall sensors
- 2 x temperature sensors.
- 1 x resolver
- 2 x end sensors
- 1-2 x RS485
- Adapter board for battery/caps
- Adapter board for CAN/Ethernet/Wifi
- Solenoid driver
- DC Motor driver
- Stepper Motor Driver
- Brushless 3-Phase motor driver
The build in 12 bit ADC will give a resolution of 0.007V if I use it to control a 30V Lab PSU, so I was looking for something with a higher resolution. I did find something that could handle 24 bit @ 2.4Msps, but it required a NDA to see the price – I think not. A little surprised about prising on fast ADC’s.
The one over is a decent choice that is quite popular. ADS1256 from TI delivers 24 bits @ 30Ksps on 8 channels for ca 6.- USD +/-. It has been around for a while. The breakout board is ca 16.- GBP on ebay. I will play with this a little, but for now I will settle with that build in 12 bit on STM32 because they are also very fast.
I do however not need fast sampling rate, I need a very fast response in the MCU on changes. The build in ADC’s have threshold interrupts that should do that for me. Fun to come.
I do however like the ADS1256 so maybe I throw up a PLC ADC board with opto isolators. Non-isolated ones exist.
A breakout board with STM32F042F6. This can also handle STM32F030F4. Very small, cute and breadboard friendly. This little MCU is Corex M0 32 bit, 48Mhz, 32Kb Flash, 6Kb SRAM and contain a long list of IO including touch contacts. The board include x-tal (not mounted here) and a 3.3V PSU that also can act as a PSU for the rest of your design. The SWD Connector is available at top, so you can also Mount this vertical to save Space if you only need a few pins.
Hardware Abstraction Layer is a thin layer of software that “abstract” your code away from the actual electronics. Actually one of the better implementations around is the Arduino library, so it is many good reasons to copy this as much as possible. But, not all of it as Arduino was implemented on a 8 bit AVR and uses a blocking concept.
One thing we need to do different is a concept I call “Software Wiring”. As we use a HAL UART module we also need to tell the HAL module where this UART is located and what pin’s to use. ST have GPIOA, GPIOB, GPIOC etc that are physical Groups of 16 pins each, but if you access these in your code you also need to change your code if Your platform change. This reduces the portability of your source code, so I deal with this using a simple trick in the HAL GPIO module.
For each UART I create a logical HAL GPIO group that need to be wired for the HAL UART module. HAL UART will expect that Rx/TX, Send Enable, Receive Enable and Power On/Off are on selected logical pins that never will change. This Group Access physical pins through a table allowing us to re-wire in software as we initialize our platform.
The result is that I am left with a single function that needs to be re-wired to port source code from platform to platform. Obviously we also enable the physical ports 1:1 through the same mechanism.
Finally updated Revision 1.2 of the Rx breakout board.
- Minor correction ca 0.5 mm on width.
- Correct GND/3.3V tag swap.
- Added a User Led
- Added a jumper for the user led. This is connected on the PCB, but you can disconnect the Led and add a jumper if you want the led on a different pin.
- Added a Gnd connector for Oscilloscope.
- Replaced the Ceramic Murata crystal with a hole through HC49 crystal. The Murata is nice, but the hole through is easier to remove for RC crystal apps or other frequencies.
- Added X1 and X2 – VCAP capacitors to support STM32F4 – these must be replaced woth 0Ohm for F1.
- Added a pull-up on NRST.
This board should be possible to use as breakout for a large range of STM32FxxxRx boards including STM32F103, STM32F105, STM32F107 and STM32F405. I need to check datasheets on other LQPF64 MCU’s from ST.
According to the datasheet this should also work for STM32F205Rx MCU’s. I have no plans to verify this at present. Myself I only use F105 and F405 With an option to use F107 since it provide Ethernet in LQFP64 package.