easyIPC Stack

easyIPC is the protocol and collection libraries I use to communicate cross various networks. easyIPC is not bound to a special technology as it provides universal device to device access through a variety of technologies including Ethernet/Wife, RS485, CAN, and SPI and in time others.

UDP, SPI, UART and CAN are examples of technologies I use and they all require a different lower protocol to take advantage of the underlying bus architecture. This is dealt with in AL (Abstraction Layer). UDP (as an example) will have a generic UDP interface, but the one I am interested in here is easyUDP and accordingly easySPI, easySerial and easyCAN. These layers are specially adapted to the easyIPC concept and each module has an identical interface so we don’t need to care about the underlying bus/stack complexity.

The concept is simple – we connect, send and receive messages as if everything is local using a common addressing scheme. Only the sender and receiver need to understand the messages. Message sequences are dealt with in easyIPC or user modules. Lets briefly discuss the technologies and why they are on this list.

easySPI We use a control system composed of Raspberry PI and multiple STM32F405 MCU using high speed Half Duplex SPI as the backbone bus. This gives a speed of 30-42Mbps which in reality makes it very comparable to a 100Mbps Ethernet.
easyI2C This is the same as easySPI using I2C bus. This is currently not supported.
easySerial Using RS485 or RS232 as bus. RS485 implement the TDM bus. Specially RS485 is well suited for distributed control systems as it covers up to 1km wired and as such allows a none-wireless interface to fixed locations.
easyCAN Using CAN as bus.
easyUDP Allows Ethernet and Wifi using the UDP protocol as carrier.
easyBluetooth Allows IPC over Bluetooth.
easyLoRa Allows IPC over LoRa Technologies. Long Range radio allowing up to 12km coverage.
easyNBIoT Allows IPC over NB IoT Technologies. This is basically a low cost phone line allowing you to communicate in all areas With GSM,3G,4G, 5G etc.
easyShockburst Allows 2.4Ghz Shockburst as IPC. Max range is 100 meters, but it is an awesome Wireless protocol With bandwidth up to 2Mbps.

 

 

RS485 Hub 3D draft

First 3D draft of the RS485 Hub. I have moved all connectors to left and top because it will be attractive to use this together with RPI 3B+ that have Ethernet/USB at right. As mentioned I could have used XPortHub for this, but I often need exactly RS485/Ethernet in higher density because RS485 is very attractive connecting to small, remote sensors/actuators. The drawback With what I do here is lack of galvanic isolation, but I will add a separate Hat for that purpose later. In an ideal world we would add galvanic isolation everywhere, but it comes at a huge size and performance cost (slower Serials), so it makes more sense to add isolation between nodes or then connecting to long wires or special Equipment.

  1. CAN Port 1
  2. CAN Port 2
  3. RS485 port 1
  4. RS485 port 2
  5. RS485 port 3
  6. SWD port
  7. RS485 port 4
  8. RS485 port 5
  9. RS485 port 6
  10. USB port
  11. Power Connector 5 external Power.
  12. 3.3V PSU
  13. Status Led’s – I admit I went a bit over the top here With 1 status for each RS485 and CAN. 
  14. 8 or 16Mhz Murata x-tal with capacitors.
  15. Serial Flash. I just added this because I had a spare SPI port.
  16. MCU
  17. RPI Connector. I basically use 5V and SPI pins on this Connector.
  18. Terminator jumper

The actual board will probably change a bit. I like doing these mock-up’s placing connectors and components, but as I start routing I also end up changing things to adapt. Schematics is done, so it will take me a few mornings to get routing done. I find PCB routing to be a relaxing mind game – so yes – this is my form for relaxing.

You probably feel the site have slowed down a bit, and yes it has. To much happening Real Life at the moment so it will be a bit like this for a while. It is also a consequence of me digging deeper into SW as I have an large backlog of things I need to code up.

RS485 Hub

XPortHub is great if you need a combination of ports, but I often need a high density of one port type so I made RS485Hub with 6 x RS485 ports, 2 x CAN ports and 1 x USB.


This is basically a simple Hat where I take advantage of the high number of RS485 ports on F405. The 2xCAN is added because they are available.

AL – Abstraction Layer

The main objective with an Abstraction Layer is to protect user modules from changes between platforms. Code on user level should be portable and plug & play after you done a 10 minute task of soft-wiring. I decided on the name “Abtraction Layer” because HAL (Hardware Abstraction Layer) is missued to much and was not a good fit.

The figure above illustrate what I want to achieve. The interface on AL should be identical, while we know that each AL module will need to be specially adapted to the technology in usage. In this case I will point out that easyIPC’s version of SPI is not a generic SPI interface. The easyIPC version is a TDM protocol that needs to be tightly integrated with hardware.

Free Electricity – Windmill

I decided to try out a windmill costing ca 180.- USD that will arrive any day soon. It is quite windy here I live, so I should get a decent 500-1000W out of this and with a decent battery bank I should be able to drive a lot of out-door electricity – not connected to the grid. This is actually part of a larger project because I want to monitor the effect I get from this small windmill. It is 130cm in diameter, and I can hide quite a few of these in my garden if they give the expected effect.

We are offered contracts in this area meaning that you can sell electricity back to the power company. In my case I would save 120 ore (ca 0,20 USD) per KWH – so assuming this windmill generate between 500-1000W in average that is 8760 KWH per year. The actual rating is 1500W, but I hope for 500W in average which is 4380 KWH/year – so I could save from 500.- to 1000.- USD a year from an investment costing me 180.- USD. My yearly consumption is ca 20KWH, so that is 25% of my electricity bill. Basically with a few of these I could be selling electricity to the power company – what is not to like?

It is two numbers that I need – one is the average effect I get out of this windmill and two is the noise-levels. The windmill is stated to be noiseless, so lets see – or more correctly hear! The later is important because I can get away with a noiseless windmill, but if this generate noise the project is dead. To put up several of these I will need to get permission.

Yet Another 3D Printer

I feel bad about my 300.- USD 3D Printer collecting dust in my lab, so I want to do something about it. This was a Prusa i3 Gen 1 clone and it ha loads of issues that came with Gen 1 printers – that said, it actually work and do a decent job for what it is.

The control system is Atmega2560 based (Arduino) and does it’s job. The advantage of this is the wealth of open source alternatives running G-Code. The drawback is that the control system is “all in one board”, meaning it is hard to expand and experiment with, so I want to replace this with a modular and more capable one.

The block diagram above illustrate a possible system. The core here is that I use my RPI modules to create a modular control system.

Current slicer SW mostly operate through Serial USB and XPortHub is excellent as G-Code Server – it has USB, Flash/SD-Card, HMI port and can drive the rest of the CNC machinery.

I could have done G-Code from raspberry PI as well, but suggest that RPI is optional for Wifi/Ethernet and print spooling.

To control stepper motors I use 2 of my 12xPWM cards that can drive 4 steppers each. The 2nd card drives 2 steppers and PWM channels for heat. Each channel support 2A, but keep in mind that I can combine channels and add a 3rd board if I need to.

The last board is a 32xIO Hat to connect to analogue sensors and digital sensors.

But, what do I want to achieve? I am obviously interested in building this as a test-case for my control system, but I also have some objectives.

  • Rebuild the mechanics into a more robust printer.
  • Insert mechanical end-stops and use current sensors to detect them to avoid a lot of wires and failing detectors.
  • Add Z-sensor to automatically detect plate tilting.
  • Add a 2nd extruder for support material.

 

 

3KW 3-Phase Motor Controller Rev 1.2

It’s been a while since I designed this 3KW 3-Phase Motor Controller without doing anything with it so I decided to give it an upgrade. The size of this is 100x25mm. It is very smal for it’s capacity and Perfect for larger drones.

  • Removed 3rd current sensor.
  • Remove the output holes at right and take the output directly from between the MOSFET’s.
  • Added 2 temperature sensor.
  • Modify power input so one wire comes at top and one at bottom. This enables me to easier mount the capacitor directly on the wires.
  • Strengthen power paths to support 50A++. The MOSFET is capable of 160A and 400A phase currents, so it is all about heat dissipation and current paths.
  • Removed some electronic filters replacing them with SW.

This design is very different to the 4 channel version due to it’s DRV8301 that contains DC/DC, Gate Drivers and current amplifiers. From a functional perspective it is less capable, but it is also much smaller size.

It is also perfect for running the outrunner above. I really liked this motor (power, size, cost), so I might buy a few more to create a drone.

Raster Graphics Integer Errors

A common problem with plotting lines in raster graphics is visualization errors as we display the graphics. Most times we can just ignore these, but as I am drawing scrolling real-time plots I also receive the side effect of an integer error.

This show a line that due to integer rounding is a straight line in the left plot, cover two pixel rows in the second before it is straight again in the third. As you move this over the screen it don’t look good or smooth at all.

The solution is quite simple – the error comes because you calculate x/y from double or float. Depending on position the conversion to pixel xy end up different as a line moves – so you can pre-compute a x and scroll this by adding/subtracting offset. The concept is that integer errors stay constant and your line looks like is moves more smoothly – no jumping between positions.

C++ vs C# Performance – Part 1

I have so far never seen a performance test where C/C++ did not win an easy victory due to it’s nature, but I am very curious about what I see in front of me now. The failure I pointed out earlier is how .NET or Windows behave then you push it to it’s limits, but the plot above is still 10 x Oscilloscope level plots at 27 FPS on a 1980xx1080 screen. That is Heavy raster Graphics behaving with video quality update – it is amazing to watch and open some usage opportunities that interest me.

Most developers will agree that raster graphics like .NET Forms is not the way to develop heavy graphics applications these days, but it still have some good usage schenarios and I like to test boundaries for my own education. In this case I will spend a little time and do the exact same plot in Qt and C++/MFC to compare 1:1 + I have a few bits of code that I have written in C++ and converted to C# so they can be used for comparisons as well.

So will C/C++ win an easy performance victory yet again? I expect it will, but the answer is not given. C/C++ compiles into static code while languages like C# compiles into a virtual machine’s assembly code and run on top of an interpreter called a “Virtual Machine”. Java uses Java VM, while C# compiles to a format called “MSIL” and run on .NET. What you need to be aware of is that computers are not single cores anymore and these interpreters are getting smarter using various technologies. The VM’s might also have a better C/C++ library and better usage of multiple cores out of the Box and the interpreters on some of these VM’s do a JIT to native machine code.

I will state that you can always win a performance game using C/C++ if you are willing to spend the time, but the question is more and more what do you get straight out of the box? My expectations right now is that C# .NET 4.6.2 might very well outperform Qt and C++/MFC on 1:1 raster graphics, but it will still be far behind on algorithmic speed. In reality we will be comparing Qt, MFC’s and .NET’s implementations of C/C++ raster graphics libraries because guess what – .NET is still written in C/C++.

Stay tuned. 

C# HMI @ 64 FPS

I did a lot of work in C#/Forms a few years back and found it to be a bit to slow for actual usage. It was easy to get fancy UI graphics done, but you instantly started struggling with performance on the screen. I remember using ca 1 month to get the functionality done and several months to get the UI library to perform. Basically I gave up using C# on SCADA style Applications at the time for reasons I will demonstrate below. Friends of mine recently claimed that the x64 flag in C# was native compilation, so I just had to try it. I don’t know about native compiling, but the result is much, much better.

This little test consist of a small plot and a fast, real-time grid running (above) on 1920×1080 screens in full size. It is a brute force implementation where I redraw the entire screen as fast as I can and the result stare me in the face – 64 FPS (Frames Per Second) at 6% CPU load. I have tested on 3 full screens as well and the CPU load increase a bit, but I still have 64 FPS. Ok- this is not the most Advanced Graphics, but it is a very convincing proof of concept, so I decided to re-create a heavier test that failed before.

Testing with AnyCPU flag I notice that I achieve the same with 22% CPU load. I also tested with .NET 4.7.1 and performance dropped, so I am using .NET Framework 4.6.2. The .NET version I basically gave up was .NET 4.0, which is the first version that started introducing the changes that now have matured. I also do a programming trick involving updating the screen from timers.

The computer I have in front of me is an Intel Core i7-4710HQ CPU @ 2.50 Ghz. It is a 64 bit with 8 cores, an old Asus gaming computer that is ca 5 years old. The second computer I tested is a bit faster, but results was basically the same. And just to be clear – this is the CPU doing the work on classic Form programming, not the GPU. What I will do next is to invest in heavier HMI Graphics and test.

The next picture below show the heavier test. Here I have 3 plots and have populated them with random lines. This is sadly also where C#/.NET starts to fail.

The logic I use here is that I run 2 timers – one to feed data and one to send Invalidate() to the component. The three plots are updated in sync so they should have reached the same level on the x-axis, but as you can see they have not.

What happens is that as the plot get heavier the framework simply stop updating some of it’s components. In this case you can see that the top plot has fallen far behind, so have the next plot and it is only the bottom plot that get updated at this point. The CPU load is 20%ich.

So – a short question – how can you trust a framework with critical HMI if you can trust the screen being updated properly? The answer is simple – you can’t!

I admit that faster CPU’s, newer and better .NET Libraries and the x64 setting all make good performance improvements. But, at the end it only moves the threshold for this Critical error.

And yes – I know how to get around this – I can daisy-chain all components and force them to update.