NMEA2000/USB Adapter

I am lagging a bit behind on my projects these days, but good news is that another embedded engineer now will join + I am finally moving on the P&P machine because assembling these for hand is a bit limiting. The adapter below has only minor changes on the N2K power side from what you have seen before.

NMEA2000 is 12V and this design can handle 12V from the M12-5 side as an option. The regulator can handle up to 16V, but it is a SO23 package and a linear regulator more suited for 5V – it will get warm if feeded 12V I think –  it also lack isolation on the 12V side so it is not really intended to be connected on 12V – it was just an option I added. The more important feature is the added USB because that enables it to be connected to a Rasberry PI or x86 based PC. I did see someone offering a NMEA2000 computer costing closer to 2000.- USD consisting of a small i3 PC + a NMEA2000/USB adapter – that is a lot considering that these industrial PC’s only cost ca 300.- USD + the cost on the module above is < 30.- USD.

Using a PC/Raspberry PI as a NMEA2000 signal Hub + display controller is a great idea assuming you have SW for it. You need to watch out for several bottlenecks:

  • How is the PC/RPI Powered? The issue here is that you will mount the PC inside a boat hidden in wall, rooth, floor or maybe behind a screen on the dashboard. Power feed must be galvanic isolated and handle at lease 5A in peaks, maybe more. It is no way I can do that through the connector above. Also you want the option to switch the PC on/off and that requires a remote on/off switch that can be mounted on the dash-board on a boat. I will get back to that one later.
  • What SW is you using? A PC/RPI is fine, but what SW will you use for the dashboard displays and NMEA2000 GW? Do you want one display or several displays? Do you want only NMEA2000 motor gadgets or do you want map system, sonar or even radar integrated? If your a boat owner you are probably aware that many solutions here can cost 50,000.- USD or more. My investigation into existing SW is that it is either DIY or very expensive.
  • How will your PC interface with the USB in this case? NMEA2000 do not cover this part thought there are som de-facto standards that can be used.

Returning to the 2000.- USD PC it was not 100% water-/air-tight and only included some simple demo SW available as open source C#. A friend looking into buying that would have been very disapointed! And water-/air- tight is an absolute must unless you plan to replace the system with ca 2 years intervals. Humid sea-air is a killer for any electronics.

Moving on a bit I have started to use Linux as a desktop and HMI platform – Ubuntu (for now) on a PC and obviously Rasbian on RPI5. I added a M.2 Hat to a RPI5 and is very happy with this one on a 4K scree, but it was a bit slow on 2 x 4K screens.  Adding M.2 SSD and removing the SD card really changes the RPI experience. That said some of the industrial PC’s I find on Aliexpress are probably a better choise and they don’t cost more if you include SSD. Also a i3 or i5 is x86 based while RPI is ARM based – you will find that a lot of SW is not available for ARM yet. But, RPI is a great choice for a Display Controller if you want multiple screens – in this case you connect RPI to Ethernet and use that as network to your NMEA2000, Radar, GPS/Map, Sonar etc. And this is basically what I want to do.

I attempted to use a 10.1 inch screen from a Chinese vendor and that was an absolute disaster – paying 100.- USD for a screen that was dead and a seller that just wasted my time. This is one of the few times I have been let down buying something through Aliexpress – been declined to send it back or getting a refund and left with a screen that don’t work. I spent almost a week working on this myself and following config advices from their site before I gave up – it is not worth my time. So I still have a job to do to find screens from small 7″ to larger 27″ versions that can be used. The idea is to box in a display controller on each screen connected to a wired Ethernet network. I will not prevent people from using Wifi, but I am not recomending radio usage on control systems because they can drop out in noisy situations and a few Ethernet cables and a Switch is plug & play, safe and low cost to cable up.

As for HMI software I will make my own package based on RPI as a display controller. I have not decided what to use as SDK, but I have a few options:

  • Qt/QML is an option. It is on my skillset since I worked with it for years.
  • Qt/Python is another option.
  • Lazaruz (Pascal) is an option – I have coded in this as well and it was very straight forward.
  • I am ruling out C# on RPI – to slow I think. I can give it a test, but that will be AvaloniaUI so lets see.
  • wxWidgets is an option.
  • A new C++ SDK based on Vulkan will be considered.

My favorite choise would be to wrap up a clean C++ Vulkan SDK and go from there – I have already put some testing into that, but Qt/QML is probably less work and this is still “kind-off” C++. The drawback with Qt is that I either have to work with a GPL license or pay 5000.- USD a year in license cost. But, Qt is a great start for a control system HMI if you don’t want to jump into making your own C++ SDK. That said – QT don’t have many ready made HMI gadgets so it is still a bit work, but I have a large library myself I can brush the dust off – lets see. I think I want to do a demo test with Vulkan and see how fast ChatGPT can assist me on the basics like drawing high performance precentation graphics etc – and then decide from there. I will be back on this.

ECU – ECUMain 1.1

Version 1.1 of ECUMain updated with CAN + Power + better galvanic isolation.

I have not even assembled version 1.0 yet because I am using the DSUB9 version for development and M12 is a bit clumsy for office usage. I have mounted CAN v 1.0, but want to move on with the modules below CAN 1.1, RS485 1.0 and Ethernet 1.0. M12 connectors on these can be Male or Female as they use the same footprint.

I have AI and DO modules as well, but I am a bit behind on assembling and testing them – lets see if we can pick up some speed 🙂

Galvanic Isolation – Routing challenge

Continuing on the last entry I am in the process of routing ECUMain so that it have CAN + Power on the same M12-5 connector. PSU Schematics is shown below. It is nothing special about this – D4 protect against wrong polarity, U9 measure the current usage and since this connect to the MCU it needs to be galvanic issolated. This is not the best current sensor, but is suficcient and have isolation on the chip. FL1 is a choke trafo protecting against EMI pulses and PS1 is a 24 to 5V 2A module with isolation. U6 is the 3.3V regulator for the local board. This isolation is important because the 5V also feeds up to 10 IO boards. PS1 can be replaced with a 4A version if needed.

This means I have two issolation barriers to route so far – PS1 and U9 -and CAN interface add 3 more chips on the barrier. CAN tranceiver isolation is 5000V, while PSU isolation is ca 1500V + some extra help from the choke on pulses. If I was to increase PS1 isolation I probably would need a lot of extra cost – these modules are expensive.

TMC1101A3 is Hall Sensor based. They work, but they are inaccurate and drift a bit with temperature, so I will in general not recommend these current sensors for everything, but in this situation they are usefully to save space and I only want a shortcut detection on the modules and a capability to measure module current profiles.

Routing itself this is easy , but making space for proper galvanic issolation space is an issue. The picture below illustrate the PCB and the yellow areas are the galvanic isolation components. An old handrule is that you need ca 5mm space between the sides.

Looking above at left the lower chip is ca 3mm and this is the DC/DC for the CAN isolated at ca 1500V, so the actual isolation is 1500V on PSU, but trancient protection is usually much higher. A common mistake is to not respect the space and as you can see I lack space to put this in so I will have to reorganize a lot to get a proper galvanic isolation on the PSU connector. I bring this up because I recently looked at a CAN Tranceiver from an European company and was shocked to see how they placed the components – the issue is that a EMI spike can be thousands of volts and jump from lane to lane if they are to close – and if that happens with anything connected to the MCU it will risk being dead afterwards. On CE/FCC testing we will be pulsing the lines with 2KV spikes for test and SW need to run during the test.

The actual result can be seen above. I diveded ground into three areas – the larger is 3.3V/MCU, the small bottom/left is Ethernet and the PSU is thetop-left. This should work well – thought I will look for replacements for C33 and C34.

ECU – NMEA2000 Adaption

Happy New Year 2026 to everyone!

I accientally used NMEA2000 standard on M12-5 pinout, so I am adapting my power connector to be a M12-5 with Power and CAN.

NMEA2000 has a Power/CAN pinout as standard that I want to adapt to my ECU designs with the difference that I allow 8-36V rather than only 12V. The later gives me the option to use 12V or 24V, while the PSU tollerate 8-36V input. You also need some tollerance even on 12V since “12V” can be anything from 10V to 14 coming from a battery. What to watch out for is that we cannot mix 12V/24V components, so if we use other NMEA2000 devices we must be strict about 12V.

The 2nd change is bitrate. NMEA2000 bitrate is strict while I allow bitrates up to 12Mbps and CAN-FD as selected by user. In SW we have a NMEA2000 Compability Mode to use if this is NMEA2000. Otherwise we are more free to use what our design wants. I should warn that higher bitrates makes distance and multiple devices more of a challenge.

  • Pin 1 : Shield
  • Pin 3 : Power Input –
  • S1 : Shield

You need to watch out for the 3 pins above. Pin3 is power and signal ground and a common mistake would be to connect the two shield pins on M12-5 to this. Shield should only be grounded in one end of a cable to avoid ground loops so this must be selectable to adapt to the design. CAN is very robust so it don’t normally need shielding, but automotive standards suggest shielding due to PWM signals and other noise that can create challenges.

The CAN port is in this case is isolated to 5000V++ while PSU itself is a bit lower. Isolated to 5000V means you can connect 5000V between pin 4 & 5 for 1 minute, sufficient to survive most EMI/lightning spikes.

ECU – Connectors

I love the M12 connectors, but they are expensive and dealing with CAN or RS485 I often find myself in need of screw terminals or D-SUB 9 rather than point to point expensice M12 connectors and cables. One example is the module below which is a RS485 with M12-5. It is great for what it is, but screw terminals would be easier except for the waterproof issue.

I could provide a DSUB-9 version, but the solution I used on the 3 x CAN hub (below) is low cost and can be adapted to DSUB9, Screw terminals or even M12 with a bit of trickery. But, the M12 design is unique in the sence that it allows 8 x sub-modules to be plug & play on a waterproof design. Also – on the new ECUMain I used NMEA2000 power connector with integrated CAN. NMEA2000 is designed for boats, but theire cable design is well suited for vehicles in general that need waterproof modules. Also the point to point cabling standard is a strong argument.

The cost argument on M12’s is less important if you need an IP67 or similar standard, but it add ca 100 USD in cost on a 6 x CAN versus the alternative, so I might need to design two connector versions or find a compromise with adapters. I will correct my 100USD bill a bit – if I order M12’s from low cost Asian source they cost 5.- USD each with a total cost of 30:_ USD. If I order the same from an European distributor I end up with 25.- USD a peace giving a comparable cost of 150.- USD – that is a big difference.

M12 based cabling is not cheap either, but here I can argue that dong manual cabling cost far more and open for far more maintenance issues. Also – one of the arguments for a M12 was lower assembly cost in total – I actually can expect end users to assemble their own little mini PLC in a waterproof box with the M12 design.

One lesson I have learned from participiation in two EV projects are to address size,cost, waterproofness and shock absorbation – which the M12/MX23 design actually do. Any attempt on using more classic PLC solution on a vehicle will result in added maintenance costs later.

The solution might very well be that I need two connector designs on everything – one for desctop/cabinets and one for vehichles.

 

ECU – Software Stack – Part 2

Part 1 of this article summarized scope of work because software for an ECU basically have two core bulks – one is the core and main controller, while the second is the add-one modules and specialized IO. This second part is basically endless as we will be adding more features and more hardware, so in this summary I want to focus on the main controllers. The block diagram below outline the main components.

RTOS that I use can be FreeRTOS, ThreadX or whatever, but I always add a barebone, linear scheduler as well because that enables FW to scale better. Most of the times I just run barebone, but I can always add a thread shifter if needed. RTOS must provide a set of critical functions that all SW is allowed to use – two of them are functions like millis() and microes() to measure elapsed time. The key functionality is however an easy path to set up tasks and decide how they execute for the system to work.

HAL (Hardware Abstraction Layer) is whatever drivers you get from a vendor and that interface to hardware. The challenge with this layer is that it is not a proper abstraction layer as different vendors will have different drivers and diffenert aproack to do the same thing.

AL (Abstraction Layer) is my own C++ layer to access hardware or software that I want to re-use in an uniform way to protect code. Using HAL drivers comes at a price – overhead and specialized hardware interface + I sometimes need to deal with workarounds or simply want a simpler interface. Also I sometimes need low level drivers that are fast and C++ is well suited to have a nice interface to a tight assembly function should I need to. Ethernet as an example can be a hardware or software interface and I need an uniform way that hide this complexity. The AL is common in all my systems and RTOS is part of the AL library.

Primary CAN is the CAN port combined with the 8-30V PSU connector. I initially had a separate PSU connector, but decided that since all main boards have CAN-FD I can as well add one here using the NMEA2000 layout. This also gives me easy access to cable infrastructure. The primary CAN can be used like any other CAN port, but it is also linked to CLI giving access to all configuration.

USB is used as a serial driver to enable a PC to connect, even power a motherboard from USB and configure it using USB. We might add more sofisticated methods later, but as a start you will need to connect to the USB for (1) configuring the system and (2) downloading new firmware.

CLI (Command Line Interface) is a text based command utility that allow you to interact directly with the system, configure components, modules and load new firmware.

Bootloader is a small FW package that is executed at start-up to check if a new FW is needed. For the main controller we download FW as an image on the disk and as we restart that FW is loaded. For the modules this operation is controlled by the mainboard, so we download to mainboard that then download to the modules. The bootloader cannot be broken, but a FW upload might fail in which case we restart the download procedure. We also have the option to rollback to a previous download as we can store multiple images on Disc.

Power Management. As we have multiple IO modules drawing Power we need to monitor their power usage and switch them on/off as needed. All motherboards can switch on/off any sub-module as needed. This includes logic to blacklist non-working modules – in which case we raise a sub-system down alarm.

Dictionary is our central database partly in RAM and partly on disk. This is a list of variables, tables, modules etc – everything we use in the system. The Dictionary  list the content primarely being an index, but the actual data can be located in user modules or copied in the Dictionary + FW images will always be on disk. One module interface to another through the dictionary which makes it easy to build a distributed system as modules can be located on different nodes if required.

Disk is an extension of dictionary where selected variables are stored on SPI Flash when changed. FW images are only stored on disk. At start-up the system will read all parameters to initialize the system. After that we save parameters then changed.

Event Distribution, As variables in the dictionary change we can signal receive tasks to pick up the changes – this can be done per variable or for a set of variables. If we are on the same MCU this will mean one task change a variable and another one deals with that change within 50yS. If we are on different Nodes we can still interact within 500yS and maybe faster. Also multiple modules can interact with the same module with no extra effort. Signals within tasks are very efficient, but you can also do a check every 10ms scheme or similar. If the receiver of a signal is a communication port then the receiver will pick up data and transfer it on the bus as fast as possible.

Module IO is a generic protocol as the motherboard assumes nothing about a module. In the config we will have a list of what we expect and as we start each module we do an identification. Each module have an unique type number and id, so the motherboard can instantly see if this is what we expected or something else. If it is a new module we need to load it’s part of the dictionary so that modules using this one find data they look for. Process for staring is very fast and easy, while process for connecting new modules will require a bit more communication depending on module.

Obviously it is a lot more details to the functionality than mentioned here, but is should give you a brief idea of how it all plugs together.

ECU – Software Stack – Part 1

I have started the FW on the ECU that will take a while, but I can outline the main design principles I use:

ECU Hardware consist of a a motherboard with a M12-4 Power connector. I use the same format as NMEA2000, but allow for 8V to 30ichV PSU rather than only 12V. I do however add the CAN port so that we can re-use NMEA2000 infrastructure as well as claim NMEA2000 compability. So that gives us CAN as primary interface.

I also add an USB as a serial port because it is convenient to just plug the main board to a PC for direct, first time configuration this way. Through this we can do CLI scripting to configure the node and detect what’s on it.

My current motherboards have PCB layout for one Ethernet, but I am not sure I want to keep that. I have two Ethernet modules that are better as they have separate MCU’s offloading some of the work. So – I think the Ethernet port can be dropped in favor of other features on the motherboard.

Disk is SPI-Flash, SPI-FRAM or SPI-PSRAM. Each motherboard will as a minimum have a SPI-Flash.

The Motherboard is a powerfully MCU acting as a switch between all interfaces. I want to keep this as simple as possible, but it also have capabilities to run automation based on data from multiple modules.

What makes this design special is the add-on modules, because you take a small box and add up to 8 modules to get the IO you want. Each modul vary in IO, but they have the same interface to the motherboard. This is a star design so one module will need to send messages to another module through the motherboard – or more correctly the motherboard is configured to forward seleced messages to the modules – something you can configure.

My modules that are in progress are as follows:

  • CAN Module. Fitted with a small MCU and fully galvanic CAN interface using NMEA2000 standard we can make a CAN Hub with 8 ports easely. In fact we can link Nodes and create a CAN Hub that is as large as we want as long as we remember to do bandwidth calculations.
  • RS485 my newest board is mostly for Modbus. This old protocol is hard to avoid and is a very handy interface as many 3rd party components will support this.
  • Single Ethernet connection so we can hook up standard Ethernet and work.
  • Tripple Ethernet connection with a switch in the connection so that we have two external ports and one internal. This is needed for low level Profibus or Ethercat support, but it also allows us to daisy chain Ethernet and avoid a centralized switch.

As for the rest we need some actual IO:

  • Analogue IO. I designed a fast, high precision AI board capable of recording 3 channels at 65Kbps with 24 bit resolition. This is primarely designed for vibration sensors, but it is a generic 3 – single lines, or 2 delta lines fully galvanic isolated.
  • Digital Out – An 8 port digital out capable of multiple ampers and PWM with load detection and current sensors. This can be used as a Power source or as a 3-phase motor driver, solenoid driver, stepper motor driver or DC motor driver.

I have plans for multiple boards, but the only one I actually need fast is a Power Servo Controller. I have some 150Kg Servo drivers I want to put into usage and they need multiple voltages and proper servo signals – which brings me to one more module:

I will need a PSU capable of delivering some Ampere on multiple voltages from 48V, 24V, 12V, 8V and 5V. I use 24V as base, but IO modules sometimes need a secondary source with different voltage, so the 24V is basically for control systems and remember that we talk 8-30V and not just 24V.

I have one more module coming up  – this is work in progress, but it is a motor controller targeting 12KW motors. It’s actual capacity is 48V-1200V and some 50A, but it will be designed to sustain 12KW and hence be in the smaller and lower side of motor controllers. The interesting part on this is that total size is very small and that it comes with 10 possible Add-On modules.

It has current sensors, but Resolver, Encoder, Hall Sensors and end points + extra sensors you add through an add-on module. On the left side I have space to add a break-resistor or a sinus filter – the later is needed for induction motors as this can drive all type of 3-phase motore. The design parameters are 600V/20A, but the board is capable of 2 x that.

This is designed for a standard aluminium box and MOSFET’s are underneath directly connected to heatsinks, but we talk about something like 15W in loss on 12KW. I can mount extra heat sinks if needed, but I am not sure I need to on this one.

In short – this is a motor controller where you add the PLC as modules inside the controller to reduce need of extra space and components. My calculations indicate a cost base on ca 300.- USD even for low volumes, and these controllers are usually priced between 1000 to 4000.- USD depending on content.

As this also is an ECU motherboard it will use the same FW as the ECU’s but add current sensors and motor control – I hope to mount the first prototype during x-mas. I need to finish the design and order PCB’s, because I will probably need 3 rounds on this before I am happy.

The content of this HW summary will change as we move forward, but it serve as a reminder of what we need to solve in SW – that will be described in part 2.

ECU – CAN Modul w/USB

I was focused on making a CAN Modul, but as I tested yesterday I also realized that I easely can add a USB port on this to use it as a stand-alone USB/CAN Adapter – which is very handy since it has the M12-5 connector used by NMEA2000.

This modul has been straight up so far, but the added value of having USB as an option is worth an extra round. The center pin is wrong on the 3D package above, so just ignore it for now.

In general I would have liked USB on many of the moduls, but had to abandon it due to lack of space – I was intending to make a speciel version of the CAN modul then I realized that I had the extra space here – which is great.

NMEA2000 M12-5 also has 12V enabling us to just attach this on a NMEA2000 network and convert PGN’s etc, but my primary use is as an analyzer so I can see what is sent on a network + I can still use it as an ECU module. It’s  a win-win.

ECM – CAn Module

Finished CAN Modul. This uses a M12-5 Male because the NMEA2000 T-Connectors are female and most cables are female to male, so this can be connected directly on a NMEA2000 network with no extra fuzz.

One of the nice details are the 5V DC/DC on right bottom, a SSR to switch on/off 120Ohm resistor and a 12Mbps CAN-FD that handle 5000V in 1 minute. This one has a full galvanic isolation. NMEA2000 is only 250Kbps, but I am eager to test FD capabilities as well. The only thing missing is the SPI Flash, but I won’t need that for now.

Here you see the cable attached to the modul and a T-connector – looking at my fingers you also get an idea about how small this moduls are. This is not my first CAN modul and to my knowledge so far this was an error free run, but lets get SW running before we conclude on that.

What I need to work on is a RS485 modul to match – it’s on my list of things to do.