BSA – Text Alignment

This show a classic label and an associated edit field. Notice that the text “label” and “Text” are not aligned. In my case I force the controls to align to the grid and in this case I get the side effect that these two texts do not align. One solution would be to switch off the grid, adjust the label and switch the grid back on – thay would work, but it would also require us to do this on every label and checkbox etc. So what I am about to do is to add a property called “Text Alignment” and make sure that these align to the same with the grid switched on. All Windows controls contains a property called “VerticalAlignment”, but it don’t work in a consistent way between controls.

This is one of the reasons I use a grid – to make it easy to align controls in size and position and it needs to work straight out of the box so we don’t use extra time on these details. My challenge is however that I will need to force  all Windows components I use. The picture below demonstrate why.

Notice that label and checkbox text are aligned on top, while edit field and combobox text are aligned center. This just look unprofessional and is a detail that will annoy everyone if it is not fixed. This is also a common issue in some GUI designers as it is not the first time I observe the need to sit and adjust this manually. My challenge is that I will need to fix this in my own HMI designer, but also in every target platform SDK.

The easy solution is to just offset label 3 points from top to compensate for the fact that grid space is 20 and font size is less. I would expect VerticalAlignment to do this, but the ressults using that property vary from control to control.

The adjusted result can be seen above – the actual top adjustment needs to be calculated based on font size used. In the final code generated we just add Y + YOffset and the result should be fine. This is basically an adjustment I have been doing manually in every GUI tool I have used – it is usually “solved” with a smalle grid, but using a 10 point grid means things align easy in position and in this case I automate the adjustment that I otherwise would be sitting doing manually.

BSA – Mini Text Editor

I just copied text from an earlier blog into my mini text editor for demonstration –  and this works out very nicely. The capability to edit text is usually a dinosourus in these apps, so I am very happy to see that this one actually works out well and are very functional. I need to code up tools to get rich text and images, but I could actually do with this alone. This one is a big win, so I am considering ditching the full view editor – not needed,

Engineering is a lot of try and fail, so it is very nice that some ideas actually work out as planned because I have plenty of those who don’t.

BSA – HMI Controls

Many of the HMI controls use actual Windows Controls as base. In the example above I draw a simulated design form as a symbol and use various build-in controls to get the result as real as possible. The challenge is that these controls are designed to be in control – not be controlled by a designer – so getting them styled correctly and to behave inside the designer actually is a bit of work.

At the end of the day I probably will need to create a SDK with my own controls for each platform I support. I will look more into that as I start generating source code from BSA.

Looking at the edit fields you also see that the corners are not drawn as a complete line – this is the control and a detail I seem to lack control over.

Another issue is the color of the check box – I can control text color, but not the check box itself etc. This is very classic Windows Build In Controls – that said – I did discover styling capabilities capable of changing more than I believed I could, so might be  afew tricks I need to learn – but, I still think a lot of custom controls will be needed to add features.

BSA – HMI Border Colors

Just to prove my point with borders being to dark I encreased them from 0x32,0x32,0x32 to 0x64 and it makes a big difference as you now actually can see the outline of the control. Keep in mind that these border lines are design help, not actual borders on the real Form. In design mode we are more interested in design parameters than exact look & feel – that said it is nice if it is close.

BSA – HMI Designer

The HMI Designer part is progressing, but I must admit that it is a large project and I don’t always have time to work on it. Finally started to wrap up the Property Editor and styling up HMI controls that still have light style. The example form above got a bit dark and close to the background so I need to visualize the borders a little more.

Upgraded the project to Visual Studio 2022 and intend to make a test port to Avalonia later. Avalonia is WPF for Windows, Linux and Mac with iOS and Android coming. This is open source with MIT license and contain a few components that interest me.

I have complained about QML making design over-complicated in the past, but I must admit WPF also has it’s tweaks. That said I have never regretted moving from QML to WPF – C# integration into Visual Studio makes it worth it and I am exited to learn about what Avalonia can do – later.

This first version will be able to design HMI with a datasource and read/write data from/to that, but it will not be able to do much intelligent processing before we add PLD and the rest. It will however generate code we can continue on. My first datasources will be Modbus, CANbus and some database – I will probably wrap up a SQLite module, and maybe MySQL – lets see.

I recently bought myself a 14″ Asus VivoBook – great laptop for the price. I only have the standard laptop mouse and a single screen on this – which is a reminder that I will need to adapt the user interface for a more – keyboard only – option later. The current interface is dpending on mouse and 3rd mouse wheel which is not that available on a laptop only. Myself I prefer a desktop with 2 screens as a minimum then I work, but the laptop enable me to work more from my living room.

Looking at the example above I typically have five events I need to process:

  • Starting the dialog
  • Updating the dialog  with data from a datasource
  • Three button events.

In reality there will be more, but lets keep it simple – the challenge with a HMI only designer is how do I process those events? I have two options (1) I can generate code where the user add the missing part, or (2) I can add in a minimum of UML State Diagrams, meaning that a HMI only design will have little purpose except for being a milestone. I need to think about this one a little. I do however have a secret agenda because I work on QML from time to time and Qt’s HMI design tend to crash + I want to autogenerate a lot of the code to speed development up. This is why Qt/QML is on my target list.

Don’t take me wrong on QML – WPF/QML is the only two technologies I have found worth working with. QML is very capable and some parts are better than WPF, but I stick to WPF because it is much faster and more productive to work with – that said – my next system will be made in BSA.

ESP-M1 Model Train Control System – Part 1

ESP8285 is a smaller version of ESP8266 and comes in three different beakout modules – ESP-M1, ESP-M2 and ESP-M3. The attractive part of this is the size of only 12.3 x 15mm. This being a Wifi module with several IO options it is ideal for my old Model Train Control System.

This picture is of a ESP-M1 which is the smallest module measuring only 12.3 x 15 mm. I selected the M1 because of it’s IPEX antenna and total cost with antenna is ca 3.- USD.

In the earlier prototypes I struggled with size as well as lack of positioning system. The four things I want are Wifi, H-Bridge, a positioning system and an expansion port. With some help of some friends that are big on modelling trains I actually got an idea on a positioning system that is low cost, small and most likely will work – I will return to that later.

ESP-M1 needs an external adapter to be programmed, but luckily those can be purchased in two versions – one that I can use for testing modules and another one I can use for programming the module while mounted on the final system. So, how to program this is already solved by the community. lets have a look at M1:

The content on a ESP-M1 is basically the same as the largest ESP8266 modules – ESP12 have more pins, but those extra pins are already used. The picture above do not show all the capabilities, but it gives an idea:

  • 1Mb Flash, 80Kb RAM
  • Tensilica L106, 80Mhz & 160Mhz, 32 bit MCU
  • Ultra small 12.3 x 15 mm
  • Wifi
  • Build in TCP/IP protocol stack
  • Uses ca 85mA with radio on.
  • Large range of IO – GPIO, ADC, HSPI, UART, I2C, I2S, IR, PWM
  • Support for 802.11 b / g / n / e / i
  • Support Station, SoftAP, SoftAP + STA mode
  • Support Wi-Fi Direct (P2P)
  • Support CCMP (CBC-MAC, counter mode), TKIP (MIC, RC4), WAPI (SMS4), WEP (RC4), CRC hardware acceleration
  • P2PDiscovery, P2P GO mode / GC P2P mode and Power Management
  • WPA / PA2 PSKAnd WPS
  • 802.11 iSafety features: pre-certification and TSN
  • 802.1h / RFC1042Frame encapsulation
  • Seamless roaming support
  • AT Support remote upgrade and cloud OTA upgrade
  • Support Smart Config function (including Android and iOS devices)

I have only used the Arduino toolchain yet, but I will set up the proper toolchain later and dig deeper into the modules capabilities.

The block diagram above illustrates the new system.

PSU My earlier design was limited to 16V and 500mA. I have this time changed a few components and can manage 36V @ 2A. Most modern H0 trains use around 300mA, but some older ones can be above that. The PSU is classic – a rectifier so we can take any polarity and even AC. a supercap to keep MCU alive and a Current Sensor to measure motor current/torque. Increasing the capacity means I also can use this as a small Wifi power switch or PWM driver.

MCU/Radio is the ESP-M1 module itself. This is Wifi, but it also have some extra features I want to dig into. I have only started playing with this.

Supercap I managed to find a smaller SuperCap that is 4.8 mm in diameter and with a current usage of ca 85mA that should be sufficient to keep the MCU alive 1-2 seconds, but I need to test this one.

 

New Motor Controller

This is a Dev kit from ST that is a complete Motor Controller in ESC format with 3 current sensors, 3 BEMF, 3 discrete Gate Drivers, Hall sensors, temperature sensors and 28V@120A Solution. The MOSFETS are rated at 120A with 480A pulse, but heat dissipation causes them to be limited to max 40A with hard fan cooling. The kit cost around 20.- USD so I bought 2 of them for testing.

Using ST’s Motor Profiler I got motor data that I imported into their motor workbench, generated a project for STM32CubeIDE, Compiled it and was running the large drone motor in an evening. The generated code include a serial protocol that match their Motor Pilot application and voila – the motor span up.

The Motor Pilot application is shown above running. In this case I have only connected the USB that act as a serial port and I have not switched on the driver power, so the motor driver report and undervoltage alarm as it should.

You receive 90% of the source code. The remaining 10% is in a library that ST preffer to avoid sending out since it contains patented algorithmes, but questioning ST I got an answer that they could send me the code if I signed a NDA with them – so all code is available free of charge.

What impressed me was that I had the large 1,2KW drone motor spinning and controlled without writing a single line of code and still had all required code I needed to work on it myself. I have friends that have tried and not been successfuly in using this kit, and I had problems myself as well. As mentioned before – you need to be willing to try & fail a bit with source code from ST as they have an improving, but far from perfect SW quality. ST is however improving a lot. I have had far less issues with STM32CubeIDE and drivers lately than earlier.

The autogenerated settings worked, but I did not like the ramp-up logic. I managed to tune it so the motor started ok, but I suspect they use a Trapzoidal algorithm to spin the motor up in speed and then take over with FOC as current readings are safe. As they switch the motor over compensated and span forth and back before speed regulation was correct. I managed to fix that without any coding by changing their PID regulator.

The MCU on the kit is STM32G431CB that runs at 170Mhz, 128Kb Flash and 32Kb SRAM. I only use ca 40Kb Flash in the code, so plenty left to play with. G431 have analogue components on-board that makes current sensing easy and fast. Programmable Op Amps allow you to adapt analogue signals to the motor you use etc.

I mentioned this was an ESC, but it also comes with 5Mbps CAN-FD Tranceiver and the total size of the kit is 17 x 41mm – half a finger in size. It has a ST-Link 2.1 attached that you can break off. ST-Link 2.1 have also comes with an UART crossed into the driver and connected to the USB, so by default ST-Link enable a UART as a Virtual Com port that is great for debugging. Another great feature is that I can connect and work on SW without powering the MOSFET drivers – using USB only.

And best of all – I have all schematics, so it is easy to adapt this kit to a more sensible form factor. The dev kit is to small for my usage – I want to change DC/DC to 60V so I can run with 48V + I also want to attach more heatsinks to get more currents out. The small PCB I got have 8 layers and is very dence. Small is not always good in this case.

The picture above show the Wotkbench that basically is a diagram over the SW logic. You click on different parts to get a screen allowing you to edit parameters and then press a button to generate a Cobe project with code.

All in all – if you wanna work on motor controllers this kit is a must in my opinion – it will get you started with full schematics and all source code in a matter of hours. Well done ST!

STM32G474Rx

St have a good series of MCU’s and I have stuck with F405 for a while. But, I just discovered G474RE, G484RE, G484CEm G491CE etc. This series is very similar to F405, but contains a lot of extras for a lower price. Also some of the MCU’s are LQFP48, but it is still a M4 ticking at 170Mhz.

Using G474RE as an example:

  • M4 w/512KbFlasg, 128Kb SRAM, 170Mhz
  • Math accelerators (Geometri and Filters)
  • 16 ch DMA
  • 5 x 12 bit ADC w/16bit oversampling.
  • 7 x 12 bit DAC
  • 7 x Analog comparators
  • 6 x Op amps
  • Loads of PWM signals.
  • 17 timers
  • 3 x FDCan
  • 4 x 1Mbit I2C
  • 6 x UART
  • 4 x SPI
  • USB
  • and much more…

G484RE holds crypto in addition, both G474 and G484 also have 48 pin versions. ST is also very good in backward compability so these MCU’s are a drop-in replacement on my F405 designs I assume. The addition of math accelerators and analogue components makes this a very good candidate for motor controllers – but, that said – these MCU’s are very fast as is without the accelerators.

FD CAN in special interest me as IPC backbone on a stack. It is fast and with higher payload than it’s HS version. FD CAN seems very similar to ordinary CAN with the exception of up to 64 byte payloads. I fail to read if max speed is increased, but I assume so. What these lacks is a bit less Flash and no Ethernet compared to F407 etc. But, I can live with that.

Ethernet on one of these MCU’s can easily be added through a Wiznet chip for normal usage. Usage of Ethernet often also requires web pages and I preffer to offload that to another MCU anyway. A fronend Linux like Raspberry PI is excellent as Web Server and gateway to real-time systems. The same goes for user interface – GUI/HMI, but that’s my preferences.

I have ordered kit’s to play with many of the new ST MCU’s. Ordering MCU’s at this time is almost impossible as it is very long manufacturing delays all-over due to the aftermath of the pandemic. I order ST kits from digikey and just add sufficient kits so I get free P&P – so far this has worked great with packages arriving after 2-3 days. Attempting to order anything from China these ways are also difficult due to prices. Hopefully the world will normalize the next 12 months – fingers crossed.

BSA – Drawing Flowcharts

BSA is moving on and is getting more advanced on the diagramming side than I actually planned for in this first version, so one option I am considering is to create a free flowcharting tool. I basically only need to wrap up some of the interfaces and add a print/preview option in addition to custom libraries and it’s done.

This screen shows the polygon tool. You click with left mouse button to add edges and with right mouse button to the remove last corner. I am very happy with how that worked out. Drawing polygons with shart or rounded edges is a must for creating custom components for HMI or diagrams. I need to add text fields connected to a property etc, but I am thinking that this is becoming a very nice semi-automated drawing/flow-charting tool on it’s own. I have often tried to find free ones and end up with some tools that are not well suited for diagrams. BSA on the other hand is designed with semi-automatic diagrams in mind.

The diagram above took me around 30 seconds to draw as is. I obviously need to adjust default property content, and yes this is SDL, but if I start creating custom symbols I can draw any diagram very fast with proper automated content.  Adding PScript I can also let users automate content. The usage would be as a free flow charting tool and BSA viewer to assist in discussions. It is worth considering at least. I need to think a bit on the total work-load, but adding customs control- and symbol- libraries add a lot of value and with PolyGon in place it is becoming an easy thing to do.

Process diagrams are also important as it would be easy to let a process engineer draw hes/her own user interface and send it to a SW engineer that links it up in the HMI with little or no extra work. This can be done with other diagrams as well. Using high level diagrams as specifications tend to increase quality, but you need specialized drawing tools or you end up spending too much time on the drawing part.

 

BSA – User Control and User Diagrams

This actual screen dump from BSA illustrate both User Control and User Diagrams. The diagram to left is a process diagram very common to a lot of industrial control systems. This diagram is the actual, main  user interface in this case. The User Gauge to right is just an illustration made by 3 polygons and a circle on how to create a 3-Way Valve symbol. I need to work on the User gauge function, but this will privide one way to create very powerfully user gauges/interfaces.

The “Function Name” will be replaced by a unique gauge name that is listed in the left toolbar together with build-in tools. As mentioned before – BSA will contain two different tool libraries – one is build into BSA and cannot be changed, the second is user libraries. The build-in tools must be static to ensure that BSA alsways remain functional.

Since we now allow user libraries I have a second issue – what if I save a project and import it to a different computer? The obvious answer is that the saved file must be stand-alone and include either a reference or a copy of the user library. A reference should cause BSA to prompt for installing the required user library and maybe replace missing library components with a “TODO” something. BSA will compile the output checking integrity, so non-functional content should result in an error.

Keep in mind that this will give one way – not the only way – to create user symbols. The usage above have it’s limitations + you can use older user symbols to create new ones etc, but you can also create user content in old, fasion code. One obvious part here is that a user symbol also need an associated property list/tree that the user must edit.

Another challenge is mixture of automated and manually located lines – with diagrams being user interface themselves I need to care about manual control (positioning) of lines.

Also notice the small dot (above). This is a link connector and is a normal symbol that allows me to connect link lines to show what lines are connected and not. It also gives me manual control of the connect location. I can create 2-Way that rotate, 3-Way that rotate and a 4-Way version of this and I have full manual control of diagrams. I can later add auto-inserion of these to make diagrams a little easier to control – if needed. This can be used on all diagrams. As with all these ideas – I have to draft them and test them in actual usage and it is not always an idea proove to be a good one, but that is engineering for you.