Qt/C#/QML Dark Theme

This demo is made in Qt using 2D raster graphics and works very well, but performance drops as I start adding animation effects into the screen. 

Performance was the reason I wanted to try out C#/.NET 4.6.2 and newer which also is much easier to work with than Qt. Performance is different in the later as it starts using all cores on a CPU. What trouble me with both solutions is however the effort it takes to make dark themes. I ended up using a minimum of time to write a drawing engine and a lot of time fiddling with user controls.

QML is not better as you basically need to do the same job, but as I learn QML I also see that it get easier. On QML I might actually struggle with what was easy in Qt/C# – the drawing engine, but let’s see. One step at the time.

Qt/QML as HMI

I did an attempt of using the 2D raster engine in Qt and while the graphical result was stunning I had to face the fact that performance was not. I moved back to C#/.NET because performance there was better after .NET 4.6.2. With C# I can do 10 x line plots at 40ich frames per sec containing ca 10000 points each.

But, as I recently had to work with and learn QML I also see a different path forward. The latest versions of Qt have started introducing high dpi support as well as dark themes. Working with QML is not straight forward as you get far too little out of the box and doc on how to make things right are difficult to find. But, what I observe is that it performs well on high density graphics using a combination of GPU and CPU. It seems to be worth the hazle of learning it well.

These bars are just an example. The component is called Gauge and looks differently out of the box, but was rather easy to customize. I have done far more fancy things in Qt and C#, but Qt/QML looks very promising.

One very important feature is that a lot of animation and effects are done in GPU, meaning that your CPU is not overrun. And maybe the most important of all – QML promise a path from Desktop to Web, Tablet’s – Smart Phones. I have yet to test the later and QML is not as quick to get started with as others. I will also state that I don’t know QML sufficiently to review it properly yet, but stay tuned – this looks promising so far.

Modular Control System

One of the key features on the boards are that they assemble to a larger control system by just clicking them together. I have around 12 different boards by now and will start adding new boards and variants as I convert all my electronics from Target 3001 to KiCAD. These two board have 5V, Device Bus and CAN on the backbone. Device Bus is designed for higher speed data transfer and communication with Raspberry PI, while CAN is the primary control system.

My preference for CAN is due to its arbitration allowing a no-config device to device communication that in theory can stretch over several kilometers. My CAN loops are high speed and very short. CAN is also excellent for automotive vehicles like the one I am working on now.

One of the returning discussion I have is that these boards was designed as Raspberry PI Hat’s and use that form factor and pin layout on the backbone bus. The fact is that I so far had little usage for Raspberry PI. This is more a statement of how capable these MCU’s are + what they can achieve together.

Also, looking at the new STM32G.. series as well as STM32H.. series I might upgrade MCU as we move forwards.  These MCU’s support CAN FD with much higher data transfer than CAN HS. STH32F405RG was chosen because of it’s high capability on IO, but STM32H753 is much better thought the smallest MCU is 100 pin. The G4 series is interesting because ST have started to improve IO capacity. The MCU’s are slightly faster version of the Cotex M4 and contains up to 3 CAN FD channels.

 

Automotive Control System

The wheels above are cool, specially since they can carry a lot of weight. But, the motors are 2 x 2.5KW and the belt driven design is very open making it easy to be contaminated. The powerfully motors are more designed for speed than for driving slowly, but I will optimize that later. Position system is straight forward, but expensive. I need 2 x ZED-F9P modules with 1cm satelite accuracy – the trouble is that these cost up to 200ich USD each. I have modules with lower accuracy that I will start working with as I also want to work on a non-satelite based position systems.

The diagram above is a schetch of the control system. I will be using an XportHub + Raspberry PI + LoRa board for main controller. It will be a modified version of XPortHub with 2 Galvanic issolated CANbus networks. The actuator network will use galvanic issolated drivers based on ISO1042 or similar – High Speed CAN. The sensor network will be isolated at the main controller, but not at the sensors. I have not illustraded power here, but actuators will have 18V supply while sensors have 5V. Three motor controllers as actuators – one for each wheel and one for the cutter. I will use a high speed propeller engine for the later.

So far this has just been a straight forward design based on available components. I just want to get the drive mechanism up running so I can start working on the position system. Building a lawn mower is just the start here – I have to admit that once I started this I was thinking “just for fun”, but the interest for what I do here + the wealth of ideas of what we can use this for is overwealming.

I still have to work a bit on my motor controllers before I start on the 3D sensor – the first objective is to just run this as a ROV outside so I can start on position reference as I test out infrastructure components.

Using old solder paste

I just started on 2 new motor drivers for my new project and soldered DRV8301 which is a dense 58 pin crab using an old solder paste. Soldering these crabs are easy and done in minutes, but I struggled with this paste and ended up with a driver that had pins not connected causing 2 days of messing around testing and looking for bugs. So, in short – lesson learned – soldering these boards are actually very easy with a bit of training and fresh solder paste. A new cylinder cost ca 3.- USD, so what I will do is to systematically replace my solder paste to make sure I work with fresh one from now on. The difference as I changed paste was extremely noticable to be gentle!

As for my new boards – I have to remove the driver chips and re-solder them with fresh paste. 2 days wasted in testing 🙁

XPortHub – Galvanic Isolated CAN Ports

The plan is to use two separate CAN Networks on my Lawn Mover – one network for motors, and one network for everything else – both using CAN HS at 1Mbps. To do this I consider upgrading XportHub. This picture show XPortHub2 w/2 CAN Ports. ISO1042 is an isolated CAN tranceiver in a SOIC8 a bit wider than the SOP8 used above and it should be realistic to upgrade XPortHub1 or XPortHub2. As I have no experience with ISO1042 I will have to experiment a bit.

My previous experiment with “all in one” galvanic isolated tranceivers is with ADM3053 from Analogue Devices – the buck converter on this used 180Mhz and needed an extra coil to issolate frequencies on + voltage. But, it also created a bit of heat and occupied space. The buck converter on ISO1042Q1 (Aytomotive version) runs on lower frequency, so I hope to see less heat and avoid that coil. But, I will still need more space than the SOP8 packages above.

Yet another option is to ditch the serial ports and Ethernet and add a LoRa connection – that will be a new board, but it will be a dedicated automotive controller and save me from adding a separate LoRa Hat LoRa has a much longer range than WiFI which will be attractive as I might have challenges with Wifi coverage everythere.

A LoRa module cost around 8ich USD and each ISO1042 cost 4-5 USD + I would like the TF card back if I do a new board. This will not be a cheap board.

Just to remind everyone – doing this without galvanic isolation will work just fine until you have an issue with one of the motor controllers and find your entire system dead. I will be reusing this infrastructure on heavy drones, so it is worth getting critical bits isolated.

32 x IO/Servo Hat – rev 1.5

This is a new version of my 32 x IO/Servo Hat. I have always been a bit unhappy with pin-header connectors since they can be disconnected easily, so I decided to try how a surface mounted 2-pin JST worked out and voila – 32 2 pin connectors with signal and ground. This means I drop the +Voltage signal and expect that to be fed from somwhere else – this is actually good as it makes it easy to mix 5V, 12V and 24V servo solutions + these connectors are good as they will not drop out due to vibration.

This is one of my simplest, but yet most usable Hat’s and this connector solution makes a great addition and enable it to be used as part of an automobile stack without being worried about connectors falling off.

New Motor Driver – DRV8353RS

I am currently using DRV8301 from TI and is very happy with that one, but I want to add a 3rd Current Sensor so I can detect sensor errors and my eyes fell on DRV8353 and DRV8323 series. DRV8323 is 60V, while DRV8353 is 100V. I don’t mind the increase in voltage. The numbering is a bit confusing at first, but I concluded on the following:

DRV8053S or DRV8353H have Current amplifiers, but lack Buck Converter.

DRV8053R have both current and buck.

DRV8353RH have Hardware Interface

DRV8353RS have SPI Interface

I will be using DRV8353RS (I think). The SPI opens for a bit more config options and use less pins that the Hardware version. Below is an anotated block diagram of the new driver.

23 external components (MOSFET’s excluded) and a smaller 7x7mm package will be interesting. I need to study this and find reference schematics before I start. Cost of this is ca 4ich USD.

This might be on Revision 1.4 of MC3P60V50A – which actually become MC3P100V… to be accurate.

 

ISO1042 Galvanic CANbus

I recently discovered this chip (ISO1042) and wanted to share a circuit I found. This circuit is excellent, but it has two flaws:

Firstly you need a small isolation coil 10-20uH between ISO 1042 and VCC1. This act as a filter so that higher frequencies used by the buck converter in ISO1042 do not disturb the MCU. I need to check frequencies, but my previous experience indicate that a 10uH coil will do the job.

Secondly I have marked a red cross over D1 – This is a common way of protecting non-isolated CAN, but I have always been against it. Usually the tranceiver circuits can handle very hard pulses and are designed to deal with CANH and CANL beeing floating, differential signals. If you put D1 on you will be forced to include GND2 as the 3rd wire, but without D1 you only need CANH/CANL. In this case we use a galvanic isolated circuit that is far more capable that D1 and can handle pulses in KV area.

As for K1 (TLP175A) this is a nice way of making the terminator switchable through software. I have never bothered much about these, but it can be nice if you connect several devices in a network and need to select whom is switched on/off.

ISO1042 speaks for itself – it is 5 x 7mm, so this is a SOIC8, but notice that it has no external components except two standard filter caps on voltage. I am curious to test this and see how much heat it generate. I previously used chips from a different vendor and was a bit surpriced by the heat and noise from the buck converter.

Another feature on ISO1042 is that it is CAN FD (5Mbps) capable.

Motor Algorithm – Part 4 – PWM Output

My previous entry show how to pre-calculate a Sinus table so we avoid doing this full speed because the next step is to convert this into a PWM pulse. A PWM pulse is measured in time – length – so we need to know the max length of a pulse. That is decided by the frequency we use. 4000Hz is really a minimum, thought if you drive a slow motor you can get away with a slower algorithm. This is the frequency of the timer interrupt we will use to re-calculate PWM output, so a pulse of 1 is 1/4000 in length.

The second is that we need to apply torque where “1” will be 100% torque, 0.5 will be 50% torque etc.

The third element is to scale to a length number matching the timer we use. To sum this up I pre-calculate a pwmFactor as follows:

pwmFactor = 1/4000*timerScale*torqueFactor;

I only need to update this if I change torque. This now gives me a factor I can multiply with the vector to calculate the length of the PWM pulse for each phase.

aPWM = vector[x].a * pwmFactor;
bPWM = vector[x].b * pwmFactor;
cPWM = vector[x].c * pwmFactor;

The final step is to output this pulse by switching pins on/off. Assuming I did not have a Hardware timer I might need to create a much faster interrupt that only switched pins on/off, but luckily the motor timers on MCU’s like STM32F405 will do this for us – I will be using Timer 1 that is a specialized motor timer that will do a lot of the work that otherwise would be hard to achieve – hard, not impossible. We run motors using slow AVR’s and PIC’s, but using a modern MCU with a motor timer is just so much easier.

As I am driving blind-folded with no knowledge of my current rotor position I just do exactly the same as in my Trapezoidal example and iterate through the table. The speed I iterate  (change sinus entry) is now the motor speed. Assuming you use 4000 Hertz and have a motor with only 3 coils you can routhly acieve 10 rotations per sec without skipping vector entryies. This is ca 600 RPM, so if you use a faster motor you really should increase freuency, but increased frequency means more CPU used for math and more loss in the MOSFET’s. You also have an upper limit of what driver, MOSFET and motor will support. A common range is 4000 to 20,000 Hertz.

At this point I don’t know the current rotor position so I just use the vector table knowing that as I iterate the motor will be moving most efficient on a 90 degree vector as illustrated below:

If I had known the current rotor position I would have looked up the vector table 90 degrees before or after the current rotor position. But, to do so I need to use BEMF, Hall or current sensors to calculate my position. In theory we could calculate this every time we create a PWM output, but we face two challenges (1) CPU hungry math and (2) inaccurate input.

Phase currents can in theory be measured calculated for every PWM output, but you usually have so much noise that you end up filtering – meaning you will not have ADC measured currents as often as you output PWM. Hall have a lower accuracy. So the real algorithm usually use a trick where we use sensors to correct rotor position.

By adding rotor vector calculations I basically are doing FOC (Field Oriented Control). I will be using both Current- and Hall sensors. My cutter motor have no Hall and it will be driving fast so this is excellent for current sensors. The wheel drivers do however have Hall sensors and will be driving slow – I do not expect any valid input from current sensors on the wheels, but we will see – so I will be driving based on Hall only.

One advice – before starting putting on PWM on a motor you need to activate temperature- and current- damage thresholds. I have four temperature sensors and two of them are located in between MOSFET’s. If the temperature raise fast or we ever achieve a selected threshold we simply cut the motor to avoid that electronics get damaged.

I also need to do this on phase currents – the MOSFET I use have a maximum of 100A, so if we ever reach – lets say 75A – we cut the motor. Maximum pulse is 400A. This is MOSFET specific data and I have used a wide SOP8 with padding underneath – a package used by several MOSFET’s so I can adapt MOSFET to application – I have 60V MOSFET’s, but I am using IRFP5300 since I had a bunch of them – this have a RDS=1.1mOhm, 30V, 100A etc – excellent for my current applications since I will be using 18V batteries from a local DIY shop.

Two numbers on a MOSFET are very important – (1) RDS that needs to be as low as possible and (2) switching time that needs to be as fast (short) as possible. As we switch we move into an area where the MOSFET will consume more heat – a low frequence is good as we switch more seldom, but a low frequency is no good for faster motors – this is a tradeoff you need to make knowing that higher freuencies will increasingly heat up your MOSFETs. For a SOP8 style package I assume max 1W dissipation without heatsink – meaning that if we burn more than 1W on the MOSFET temperature starts to raise fast. This imporves with heatsink that I have on each driver – but we are now into the discussions about my boards limitations – my target was 50A, but at some point I will destroy boards to learn these numbers.

I just tested PWM outputs on my board and is happy to see they work, so I only need to get temperature- and current- sensors working and I will be spinning the larger motors.