PLC – G491RE Template

I will be using a few MCU’s to create PLC Modules, so it makes sence to create a template – starting project for each MCU. The most obvious is STM32G491RE. This template contains MCU, CAN, RS485, Crystal, SWD, Leds, FRAM and PSU condenced as tight as possible towards one side.

The template might change, but the idea is to get a flying start on new modules. As for FRAM and RS485 – if I don’t use them it cost me nothing to not assemble them!

PLC – PWM/Motor Module

DRV8313 is an excellent driver circuit containing 3 separate half h-bridges that can be used as separate PWM drivers, a DC Motor driver or 3-phase motor driver. Delivering 3.5A max in peak and supporting upt to 60V it is excellent for 12V, 24V or 48V systems. I have made a small motor driver on this before and I only need a few passive components connected to the operational Amplifiers in STM32G491 to create low side current sensors. This will be an excelent PLC module and small motor driver.

The drawback with low-side current sensors are that it is difficult to measure individual currents simply because you will not use the low side on solenoid type connections, so high side current sensing is better, but this require additional circuits that drive cost/complexity. So what I will do is to use four current sensors – the forth measure total current on the PWM- (Ground) channels, while the three others measure motor currents. I have 4 operational amplifiers in STM32G491 so this should work fine.

A 6P 2.54 pitch connector fit exactly on the 17mm available on a 25x45mm module, and this allows me to offer 3 PWM+ and 3 PWM- (GND through shunt) connections – for 3 separate signals you use all 6 and I measure current using the 4th sensor, while for a motor you use 2 or 3 PWM’s and I measure current on low side. It is a few issues I need to consider, but this sounds like a great module that will be fun to use.

CAN (or RS485) is great here because I can make this PCB purple or even pay for multiple colors and hang them with LED strings directly on the chirstmas tree. Fun to come 🙂

PLC – Module Mechanical Design

Before I order any of the PCB’s I also need to consider adjusting the size of the modules. I have ordered several standard project boxes that I will consider using, but I lack exact mechanical dimensions on them. And I have to figure out the mounting holes on the motherboard to the project boxes. The boxes I ordered are 90 mm width – hence the 45mm width per module. But, I probably need to reduce module width to 44 mm because 90 mm was outside the box + I need 0.x mm free space between modules as I mount them. The 25mm height was initially decided based on two criterias (1) I want the minimum module as small as possible, (2) I have ordered small project boxes that are 25x25mm size for two boards to go back to back. But, height is not so critical as width.

I have not adjusted this yet because without exact drilling holes and dimensions on the boxes I will need to redo this anyway. I also expect that I will need three PCB revisions – planing for less is just nonsence IMO. So, I will just order this modul “as is” and face the required adjustments later. Ordering PCB’s will cost me ca 20.- USD so it is more important to get going on testing so I get the prototype up running.

Notice that facing left I have CAN+Power on the top header and RS485 + Power on the bottom header, and facing right this is switched around. You can mount the module in any position and it will just work. I need to wak though the start-up sequence in SW and verify that I have what I need to make this work, but I think so.

Looking at my Ethernet module you can see that it is easy to adjust 1 mm at the Width on left, but it is far more difficult to do the same on Height. I basically have to re-route the entire board Because I have 0,5mm space between the SOP8 components that I need to adjust in. And I need to use more of the backside in Width because routing and number of via’s are getting dense. The two headers, two resistors and 32Khz crystal must move in. If I need 2 mm then I can’t do it + I will struggle to get this module into 25×25 anyway because of the size of the J45.

You see the issue more clearly on the back assembly view. What I can do is to swap U3,U5 and U7 with U8,U6 and U10 and mount them tighter as well as using more of the space towards J4, but that means starting from scratch on routing :(. TBH I should have considered these mechanical issues before I routed the first module, but I did not believe I would finish it this easy + I was not sure about what I could squeze in. You sometimes get fooled by how much space that passive components and tracks take up. All in all I am very happy with my first attempt on 4-layer PCB. In this case I also have 2 x 2.54 pitch headers and I often experience that they take more space than you expect.

Routing PCB’s I have discovered that what works best for me is to just get started and see how it goes – if I fail I restart – this is far faster than sitting around considering dit and dat for ages – far more fun as well :). Routing for me is like a little mind-puzle I can work on every morning and in spare moments – it is actually relaxing since I have no time pressure.

I did consider swapping out my SWD connector with 1×5 pin or a PCB/Cable solution. That cable costed ca 70.- USD so I ditched it and the reason I use 2×5 pin hole though has to do with stability. The only challenge I have with this format is that it sometimes is hard to see what direction to mount the SWD.

Don’t worry – this is the last you will hear about this Module for a few weeks – thanks for reading!

 

PLC – Motherboard

The next module I want to make is the motherboard(s). I want to start with a 2, 4 and 8 module Motherboard. An early demo of a 4-module board is shown above. In this case I have mounted 4 x Ethernet modules – an advanced system will usually have two Ethernets for redundancy, but you can actually mount your own Switch or Router this way.

Somehow the drill holes dissapeared as I made step files of the Ethernet module, but you get the idea.

Wise of experience I also want to wait a bit before I order more modules. Mounting a motherboard and a few Ethernet modules will most likely cause some changes to the design based on what I experience. I have a list of ca 30 modules I will like to start working on.

PLC – Ethernet Modul Finished

Fisished routing. One days work – first attempt on 4-layer design. I must admit KiCAD did most of the job.

Components top without Ethetnet modul.

Components bottom layer

All layers. I decided to use Ground and Power as the middle layers.

I don’t add ground layer on top or bottom since this will be hand-soldiered. Will use 1-2 days to check my work before I order PCB’s.

 

PLC – Ethernet Front

This prototype have a Wiznet breakout on top and a USB-C on bottom in front. The Wiznet breakout cover the M2 screw holes, so mouting these will be a little tricky, but doable. I will consider pushing the breakout a bit in-I need to alig  RJ45  and  USB-C infront  anyway and that will help.

PLC – Ethernet Module

I have finished schematics, footprints, 3D models and placed the components and this starts to look good. The pictures below are exported directly from KiCAD. The Top layer contains the Ethernet module, MCU, crystals, leds and SWD. Only the 16Mhz crystal and some caps are under the Ethernet module. The bottom contains a USB-C connector, a CAN-FD Tranceiver, a RS485 Tranceiver, SPI Flash, SPI FRAM, 2 x SSR 120Ohm Terminal switches and 2 x separate PSU’s that connect if the coil is connected – one for the Ethernet module and one for the rest.

J1 is CAN-FD while J2 is RS485 connected to the motherboard allowing modules using both CAN-FD and/or RS485 to interconnect.  I have yet to route this board and that will take me a few days, but I look forward to routing with 4 layers. As for ordering PCB’s – I get this ordered from JLCPCB and delivered in ca 10 days for ca 20.- USD – not bad. The BOM is 48 components so it is denser than it looks as it is only 25 x 45 mm. I excpect I might have to shrink the board to 24 x 44 mm, but I will return for that.

 

KiCAD 6.0.8 is great to work with containing many good improvements, but the library is in a bit of a mess loosing old footprints and 3D models. But, well – it is nice to be able to fetch components on the net and import them. STEP models can be found anywhere. For my usage KiCAD is great!

I am still using a few hole-though components because I want to use up my stock + I expect I have to do a few rounds on this. But, a bit of advice – hole through have to be assembled manually so they cost extra. The old fasioned 32Khz oscillator is okich here, but needs to be replaced – I have to think about headers. I want to replace SWD header with a PCB footprint that is excellent. But, well – that’s for later concerns.

In the early draft I considered using a TF Card, but I discovered that this MCU don’t support that. I did also reject the idea of multiple CAN ports and back to back connections and added a RS485 and a 3nd IPC alternative simply because that opens the option to use a long range of MCU’s. UART’s are available on all MCU’s.

I also added USB-C for the first time. It was only a few hours work to find a connector I could soldier and understanding what is what. The part I am most proud of is however the SW controlled 120Ohm termination on both CAN-FD and RS485. I actually fidured this out myself and got a reference design from a more experienced friend showing that I was on the right track. All in all this is actually a very dense, nice design.

PLC – Module Design

I decided to add place for bothy CAN-FD and RS485 as IPC on the module. The design seen from left is CAN at top, RS485 on bottom – switching the module to right we get the oposite. I have the extra space to do it and it allows me to build modules using UART’s only. One of the modules – like this ethernet module can act as gateway between Ether, CAN and RS485.

I have in addition added a SPI Flash 8Mb and SPI FRAM (32Kb) and if I have pins and space I will add USB and/or USART TTL. I did consider TF-Card until I realized that STM32G491 don’t have a HW IO for that. USB is great for just connecting to a PC and download FW using ST’s build in bootloader.

PLC – Ethernet Module Backside

This ends up as a prototype anyway because I lack components to optimize for production. I am using 4 layers this time because I want better isolation between signals. I can mosly route on a single layer, but I had some bad experience with signal integrity on 2 layers. This is the first time I use more than 2 layers and the cost increases quite a bit as well.

I have plenty of spare pins since I used a 64 pin MCU so I will be adding some extras on the back – I am even considering a SD card – lets see -it don’t cost anything to add PCB layout and I don’t have to mount it – this could be a very interesting module at the end.

One drawback is that the mini module cover the screw holes. This will make it difficult to fix this to the motherboard with the W5500 module soldered on, but it is doable.

 

KiCAD 6.0.8

KiCAD 6.0.8 is great. Many new improvements. But, also some issues as links to footprints and 3D images are broken. I opened XPortHub2 because I neeeded reference to a coil and found that the RJ45 is missing on the 3D View – easy to fix, but I have seen a few of these. You also see some caps and resistors missing etc. Luckily the components I was looking for is here.

Another interesting thing here is that this RJ45 and the W5500 circuit would actually fit on a 25mm x 45mm module if I put the MCU on the other side – just about.

KiCAD is great for what it is. Some of it’s user interface is getting better, but at the end of the day this is a tool you need to learn and keep using on regular basis to apreciate it. I have many friends using Altium or Cadence, but I think KiCAD keeps sneaking up on them. Well done!

As for the module above – I never got around to order the PCB’s because I use Ethernet on RPI.