Returning to Plain

A blog is excellent for sharing ideas down and returning to evolve them later. It’s been a while since I wrote about Plain. I basically stopped because I had other things I wanted to work on, but I think it is time to review/consolidate the specification and move on.

Is it worth it? Will it make a difference?

I work on PLC alike technology as a profession, and I am stunned by how much work that goes into even simple system changes. What I want to achieve is (1) plug in a new sensor or actuator, (2) automatically detect this as an unallocated resource, (3)  put it into a system diagram with a few clicks.

We will get there…

3D CAD – Autodesk Fusion 360

I have been in the marked for a CAD program for some time and finally realized that Autodesk Fusion 360 is free for non-commercial and minor commercial usage. It also have loads of training videos to get you started. I have only been using it for a day, but it seems to do the job.

ESP32 – GPIO 34-39

#4 on the picture above is Servo channels. I discovered that only 8 of there are working as expected. The 4 last ones have GPIO 34-39 that failed in testing – and reading small notes in the datasheet I realize that I have missed out a “input only” note on these pins.

And guess 3 times which pins I used for the single H-Bridge on the little one. I am going to need a special adapter for these so I can program them anyway.

I actually need 12 servos on the Utility Driver, so I will need to grab 4 channels from H-bridges or PWM. I probably need to re-think the Utility Driver(s) a bit.

ESP32 – PlatformIO

I have tried PlatformIO twice. Once for STM32 and now for ESP32. PlatformIO promote itself as open source, but it looks more like a commercial solution with version No 0.14. It can be added to Visual Studio Code. It imports existing Arduino Projects etc.

But, well – two attempts and it is still sorted under “crap that don’t work well” – waste of time and money!

ESP32 with Visual Studio Code & Arduino

Having used Arduino IDE to develope the ESP32 Utility Driver code I must admit that while I in general like Arduino I also miss a proper code editor. Sticking to Arduino (for now) I decided top try out Visual Studio Code.

Visual Studio Code is basically a free and liteweight version of Visual Studio. In this case I just opened the folder and voila. This gives me the option to edit code here and use Arduino IDE to compile and upload.

I am fully aware that more advanced options exist, but I intend to stick to Arduino libs on this project because they are straight forward to use. I actually have the full toolchain & ESP-IDF etc installed. This would probably be my own preferred ways of working, but I need something that every hobbyist can work with – no fuzz – with as little fuzz as possible.

It’s other coder alternatives than Visual Studio Code. Friends of mine stick to Emacs etc. I learned years ago that you don’t mess with developers personal choises unless you want them frustrated and less productive. So whatever works for you is fine.

A note on Arduino 1.8.5 is that it will not detect changes made by a different editor, so changes will be reverted if you save from Arduino after having changed a file from another editor.

ESP32, Arduino & FreeRTOS

One of the things that I am not happy with is the FreeRTOS implementation on the Arduino ESP32 library. I try to reserve core 1 for bit-banging and I have a nice average 4uS accuracy. But, I also have 110uS long iterations ca once per second as I activate WiFi. Also, I fail to activate WiFi from anywhere but “loop()” (core 1). Any attempt on doing this from a thread causes FreeRTOS to “panic” and result in a core dump.

I suspect that it either is a FreeRTOS thread or interrupt that uses core 1 and not core 0. 110uS means 10% accuracy on a Servo Pulse. But, more important is that FreeRTOS get’s in my way. This is a classic conflict between hard real-time and threading OS designs.

Threading means that a OS uses a system interrupt to switch jobs. This interrupt can run 1000 or maybe 10,000 times a sec. At 10,000 times a sec I would expect 5-10% CPU load on ESP32 for this alone. The reason I do a round robin loop on core 1 is because I get higher accuracy. But, as Core 1 obviously have other things that slow it down I will need to look into that.

It is not critical for my 12 Servo channels because I also have 16 Led PWM channels available. Simply said I don’t need to bitbang the 12 Servo channels on the ESP32 Utility Driver and H-Bridge and PWM is less sensitive.

A Servo pulse is 50Hz, but last about 2500uS max, so 110uS is between 5-10% accuracy. 10% is sufficient to get me worried that the Servo  might have a minor move – in that case it would look like nervous twiches as the Servo try to hold positions – not sure. But, as I said – I do have the Led PWM’s that comes with a much higher accuracy.

ESP32 – CLI/Simple HMI

While I am working on more permanent HMI solutions I need a CLI that communicate through USB that can initialize the ESP32 based designs. A CLI is a command line interface that act like a brute force interpreter. In theory we could implement a full Unix alike shell, but I only want a few commands that is a must. But, I also recognize that this is a good way of testing board features before the HMI is finished – so here it is;

  •  *    set wifi <ssid> <password>
  •  *        // will set the ssid and password
  •  *        // automatically used at next startup
  •  *
  •  *    reboot
  •  *        // reboot the device
  •  *
  •  *    help
  •  *        // list available commands and syntax
  •  *
  •  *    stats on|off
  •  *        // switch statistics on/off.
  •  *
  •  *    hbridge <ch> <dir> <pwm-duty>
  •  *        // set hbridge to move
  •  *
  •  *    pwm <ch> <duty>
  •  *        // set pwm to duty
  •  *
  •  *    servo <ch> <pos>
  •  *        // set servo pos

For now I will use the Serial port through Arduino IDE. We can add more commands as needed. Later I will need to add this through Wifi/Telnet so I can test Model trains as well.

Adding Wifi to DPS5005

The DPS5005 contains a USB/RS485 interface so both PSU’s can be remotely controlled. I want to use this option to create a Wifi based PSU. ESP-Wroom-32 do have 3 UART’s, so we can still keep UART0 for programming and use UART1 & 2 for each board. I do however notice on the original USB board that the vendor used photo couplers and I think that is a good idea. I would otherwise struggle with ground between the two PSU units that needs to remain isolated from each other.

The only concern here is that the opto coupler’s have limited data rates, but DPS5005 comes pre-programmed with a fixed baudrate anyway. The schematics above is just one I found and modified in Powerpoint of all things. I am not sure ESP32 is capable of driving an opto-coupler directly, so we might need transistors. I obviously also need a separate PSU as I can’t feed from any of the main ones. The signal from DPS5005 include a 5V PSU to feed that side, so we will be using 3 separate PSU’s on this board.

The long walk with HMI Designer

Working with software is often long hours with invisible progress. In this case I worked on the Edit Control. I actually tried to use a standard Windows one, but decided to make my own from scratch. In effect it is only a few things I use from Qt including their interface to OpenGL.

Edit Control – that can’t be much work right? Actually it wasn’t, but it forced some design changes to get it the way I want it. The picture above show inline editing with no borders.

Having coded C++ for years before learning C# and Java I actually want to implement some of the C#/Java techniques in C++. This is about making things simpler and more efficient to code.

One of the issues is Reflection. In C# you can assign an object to the property editor and edit it’s properties. Doing the same in C++ is much simpler than people think – you simply add a linked list declaring your member variables and voila – you can edit, save xml, read xml with a few simple commands.

Another issue is Events. I often need to call a parent class from a sub-class. Again if the sub class simply have a mapping table that I can set from the parent …

These techniques do however dig into the memory and dynamic side of C++. But, it leaves me with what I want – a HMI without C# or Java around to slow it down.

Dual 0-35V/0-5A Variable Lab PSU – Assembled

This shows the assembled PSU. Only one of the DPS5005 modules are mounted as I am still waiting on the 2nd. You can see the driver stage mounted inside. The black painted front turned out quite nice.

This is the back side with the mains connector, fuse and switch. I have to wait a few weeks for the 2nd module, but I am quite happy with this PSU. Actual max voltage out is 34.75V as input is 35.75V. Current limit is +/- 0.005A according to the build in meter.