PLC – ADC Readings

One of my concerns on 600V design is how to make ADC readings in the 600V area.

I need 3 x Current sensors, 1 x DC Voltage Sensor and 1(2) x Temperature sensors in addition to support for up to 3 resolver sensors as well as an external motor temperature sensor. That sums up to 10 ADC readings coming from or through 600V area. I was investigating ADC to SPI solutions, but specially current readings will happen 25,000 times per second and needs to happen at exact timing. I did find component that do specialized current or ADC readings with isolated ADC output, but those ADC signals will be measured on the far end of a PWM card and needs to be transported to the MCU. The solution I decided to try out is a 2-barrier system. I use an isolated sensor capable of handling xx Voltage ESD andthen a 2nd barier with an Isolated OpAmp on the Controller.board.

I am no expert on this so it will need to test. Calculating cost I am looking at 6.- USD per analogue channel assuming Digikey prices at 10 x. I think the first test is to make a small board testing a single channel to see if this works and what delays and reading quality I get, As for temperatur and accuracy the current sensors will have the same error and drift from temperature so the angle should still be intact + PID + Filter will regulate that regardless.

I will add a MOSFET set on the test so I can load a single channel and verify if my heat calculations work, but I am not that worried as we talk about only 10A on the first board, I did calculate ca 12Watt loss using decent MOSFET’s from Infineon with 105mOhm RDS.

STM32H503RB

This MCU started to interest me because it is a low price alternative with a lot of contents. ST’s price is 1.7 USD, but that is 3++ USD through Digikey in low volume. It is a 128Kb Flash version, but it has a promissing build-in Bootloader that I want to experiment with. If you build a CANopen bootloader you easely need 64Kb for the bootloader alone unless you want to spend a lot of time in size optimization. You can get a bootloader down to 8Kb, but the cost in time is usually to huge so I just use a MCU with more Flash. This one looks like I might keep 128K Flash to applications making it a very interesting low-cost option.

  • 32 bit w/FPU at 250Mhz.
  • M33 Core with lots of extras.
  • 128Kb Flash, 32Kb SRAM.
  • 1 x FD-CAN
  • USB
  • I2C, SPI, UART in 2-3 x.
  • One decent Motor Timer.

And some extras that I basically don’t know what is yet.

I have ordered a Nucleo board and 10 chips as I want to consider this for several projects.

Java programmers hit again

I am used to problems with STM32CubeIDE – this one popped up as I wanted to open the ioc file of a STM32H503RB – it is a well know error from Eclipse based tools – or more correctly Java based tools. You can always recognize Java since the code is slow as a slug and then you get these ones in your face!

C# suffer from many of the same issues as Java – one of them is the exception mechanism. I have made my arguments before why I consider that a notorious unsecure mechanism in any language. Myself I avoid raising exceptions, but I do catch them and ensure the code can continue. A crach like this is unacceptable! And lets talk about performance …

The rest of the IDE is ok the times it works, but the ST’inherited Cube is sloooooooow – I spend a lot of time looking at the dialogue above. And Java is actually not that slow, you just need to know what you are doing. And finally after struggling to close Eclipse we can start over again and after a loooong, slooooow opening sequence we are rewarded with crap that works on a good day.

Eclipse and specially Atolic Studio that we know as STM32CubeIDE is actually decently great to work with – and the CubeMX additions are also a great assistance in figuring out how to wire a MCU and generating HAL’s as well as including libraries. But it is slow and as seen above – still have bugs.

PLC – Motor Controller 2

Most of you have already seen my main PLC Core board with 3 x CAN ports and 10 x Extension ports. What I plan for the MC is to extend this to 4 ports wide, keep one CAN port and add a 24V power port, replace the MCU with a smaller Rx (64 pin) version, add a TTL UART  and motor logic electronics, The 10x UART ports will be replaced with one. This can then be the single extension if you want to add 4 x CAN ports.

If I have available TTL UART ports I will add them if I have space, but the Motor Controller will be packed – which reminds me that I need to actually build the board above as well. Give me two weeks and I will have one made. I reduced the scope in the drawing below because I wanted a clean Motor Controller. The single TTL port can link to a PLC Core that includes as many add-on’s as you want, but the MC should not be the PLC Core. It is also an issue about how much I can get on the controller board as it needs to hold a lot of extra electronics.

MCU – I will drop down to STM32G474/G491 or even G431. I could also consider the new STM32H503RB due to cost.

GateDriver’s are selected as ST have some vith full isolation and 1200V tolerance to a decent cost.

Current Readings the same – I found some very nice 600V tolerant earlier, but these will be on the driver board.

Temperature Sensors – I have to find a solution.

Resolver Input is 3 x ADC’s and I have to find a solution.

CAN, UART, SPI Flash, SPI FRAM, SWD can be copied from the board above.

MOSFET – I need to find some nice 600V with ca 20A and a low cost/low RDS and low sitching times. I will find some that work well from 48V to 400V.

 

PLC – Motor Controller

I have done a few smaller motor controllers in the past, but as I currently work a bit with PLC’s and use larger 400V motors I must admit I am considering making my own PLC/Motor controller. I use the terminology PLC for my own embedded, modular system and having a motor controller that fit into this scheme will be nice – more correcttly a motor controller that can use my PLC as add-on modules. In this way you will get a small, cost-effective and water-proof PLC/Motor Controller in one unit. A BLDC type Motor Controller can easely run any type of 3-phase motor – it is just a matter of selecting the correct algorithm in SW.

This is a quick scetch of the two boards. The controller board will use 4 x PLC Module width (10cm x 7cm) while the driver can be as big as it need to. The two should connect with internal cables. Below is a possible boxing illustration seen from the side. The smallest MC would be 10cm x 4cm x 14cm and can easely be extended with PLC modules to form a compact unit.

As for code I preffer CAN/CANopen or J1939 etc, but I have code for Profinet as well – for now I will think about it for a while as I search for components and compute BOM Cost, This would also be an excellent addition to BSA, but lets get BSA released first.

BSA – Hello World

I created a simple Hello World diagram (below), saved it, Imported it to itself and made a copy/paste – so below I have 2 x Module 1, 2 x Diagram 1 and 3 x Hello World. This is just an integrity check on the drawing engine as the engine uses an unique reference and not the names. So from a free drawing perspective this is fine – you can do this in a text editor while a proper editor will tag Module 1 and Hello World as duplicated – meaning you can draw what you want, but the compiler will stop you from generating code since you from a programming perspective have errors.

In this firsr version we focus on design and the capability to make drawings and illustrations (modelling) – a typical usage is that we discuss two or three alternative implementation or just want some drawing freedom as part of the design process – meaning the tool should not limit us. BSA is a very fast drawing tool on these specialized diagrams and we can easely combine drawings with notes and free text where we do not want to be stopped by programming language rules. So – in short we need to allow this because design and documentation is an important bonus we get free from BSA.

The question is how do we precent this in Dictionary and digrams? What we have above is “Hello World”, but assume you do this by accident with hundreds of objects – we need a way for the user to be able to do this deliberately while it also must be obvious that this is an illegal diagram. I plan to run the compiler as a background task so the integrity check will always pop up a almost instantly.

We also have a similar need as we code – we need to make new versions of code and be able to comment out code as we test etc – and using a text editor this is simple, so we should be able to de exactly the same here. From a coding perspective this is straight forward as we could mark illegal situations clearly and force the user to correct situations or comment the out. But, we need something that work for free design as well.

I will experiment with flags in the dictionary and the adding a “Comment” or “Design” tag in the left-top corner to comment out entire diagrams – we seriously need that option and a system to maintain multiple versions of diagrams anyway. It is also a question if we should add a legend option similar to those in other CAD tools. These can easily be added in fixed positions on top of the digrams and be included/removed from printing/clipboard at the users option. Myself I would preffer to see a tag if I look at an older version of a diagram.

BSA – Import, Cut/Copy/Paste

I have started to add four functions “Import, Cut, Copy and Paste”, The example below import a copy of the existing module into the repository. The main challenge to maintain integrity is straight forward as integrity is based on a unique, internal reference that needs to be updated. Names are only a precentation on this level. The more interesting issue is precentation of objects like Module 1, Diagram 1 and Class88 that now are duplicated as we in this example end up wih two of each. I only need to change the 2nd Module name as the full name of Class88 is “Module1.Diagram 1.Class88” etc, but I hesitate to start using the full, formal names everythere.

Cut, Copy and Paste is simlar to Import with the exception that you can operate within a module and as such you need to change names of ojects. If you copy a object between modules we need to make a physical copy, but if the copy a class inside a module we could make a new precentation of the original or we could create a new original. All of this must be handled in the UI.

Import is a must for several people to work on the same project and I probably need a merge option – that said I want to experiement with GIT first because two or more developers should be able to merge projects using GIT. The challenge is the references because as two users work in parallell they might be using the same references for different things – in which case GIT Merge will screw things up :(. I am also fully aware that a GIT Merge tend to screw up if two developers have worked on the same file, so it might be safer to handle Merge in BSA. I need to think about this one.

It still is a bit of work left before I am happy with the integrity and functionality of BSA:

  • I need some improvements on clipboard copy, basically to copy selections rather than full diagrams.
  • Import needs to work.
  • Copy/Paste must work.
  • Multiple Modules must work.
  • And I will need to optimize Dictionary precentation.
  • And test and fix bugs.

I also need to design an undo/redo mechanism, but I can release a beta without this. The reason I push on Import, cut, copy paste now is because they affect the core concept of how fast you can work – as in productivity. BSA is pretty fast to draw diagrams with as is, but as my test project grows I miss options to copy/paste to capitilize on things I already have done. One discussion coming up is my text editor in the Property Editor – it works, but it ends op on the right side as very small text. I also enter a lot of text that I need to precent in tables and get into documents. Documentation is important because it is something we can do a lot of automation on – the hard reality for many of us is that we make less doc than we should do because of lack of time – and doc in my case is precented to management that is stakeholders in work you do.

I was considering HMI as my next release, but it might be that I start pushing on Code Generators. To generate source code I will be re-using an old concept I developed back in 1995 – a specialized template language where you manually write the code and then modify content with a specialized markup language. This means the code that is generated is 100% controlled by yourself as it should be – the last functionality I then need is to be able to import tool kits and let the user create new tools. I will keep the build-in tools as a base, but users should be able to create their own libraries of code and tools.

One concept I am eager to push is to make more of BSA using BSA, but that is for a later day 🙂

BSA – UMS vs SDL States

SDL (Specification and Description Language) was at one point considered as a UML diagram add-on, but UML went in a different direction. I am used to SDL from Telecom and use an abstracted version (simplified) because I liked the state engine concept added to normal flow charts – so why did I bother with UML State diagrams on top of SDL? The answer is that UML State diagrams are superier on showing information flow on the higher level, while SDL is superior then dealing with executable logic on lower levels. The two methods complement each other well. In the example below I have drawn a diagram – UML State Diagram at left and SDL at right where the SDL part actually is the executable flow chart inside the UML block at left.

PLD (Plain Logic Diagram) is a Flow chart with some abstracted SDL added as well as UML State diagrams added. It is a bit of work before we can start generating code, but my previous experince with SDL is that a common user need about 5 minutes to learn reading the diagrams. We actually used these diagrams as a specification on some systems and they are great as we did not have a single dispute over functionality – the only issue at the time was that drawing these diagrams without a specialized tool is to time consuming. BSA will change that!

BSA – New UML State

Changing UML State is straight forward – just use ToolMake to add a new property and change the default settings + a few lines of code to add the header change I also added. This is a compromise on my earlier Connection Point – I decided to change the default to Free and implement Free as no CP’s shown for now. I have already changed Start and Exit symbols and that is basically most of what I need right now – the next step is to change Flow lines. This means I keep existing functionality (for now), but change default behavior only.

I keep praising ToolMaker, the utility I decided to make som time back. It is a simple table driven aproach to change properties and the generated code automatically make the usable in diagrams and set up the editor for them. This is also a lesson learned because the amount of work they have saved me is increadible due to the watse number or properties.

Another tool I really start to like is the Copy function that allows me to copy diagrams into emails and documents (below) – I still have work to do on Clipboard and Print, but I am using the Copy function daily now. In the end I decided to only convert text and background colors on a hard-coded scheme (for now).

 

BSA – UML State Diagrams

I wanted to draw some simple, high level UML State diagrams using PLD and while it worked I also used far more time than I expected. This was in many ways a big failure with regards to the objectives I have set, so I need to do some re-thinking.

In this first diagram I use Connection Points (CP) to draw lines. The issue is that links in this case only goes between CP’s and from left to right. As the CP positions are automated it becomes close to impossible to have straight, nice lines and as the diagrams grows this becomes messy and we start using more and more time on making diagrams look pretty. More important is that real diagrams is very limited if you draw only top-down or left-right + I ended up removing the automated event/method names as well. All in all I managed to draw the diagram I wanted, but I concluded that I had achieved the opposite of what I wanted – I ended up using a lot of time fiddling with lines – lesson learned!

This next diagram is the same, but here I switched to Free drawing to avoid the CP’s. In this case the diagram is cleaner, I can easily make lines straight  and notice the added lines that goes back or use other edges. A State Diagram show flow of events/info between objects and visualizing the below using CP’s that only was Top-Left or Left-Right simply did not work well,

So, how do we move forward? Some of you will recall that we started with simple lines and changed to using CP’s. The arguments was that CP’s visualized what events that was available and also visualized mandatory events etc (mandatory must be implemented) – so yes going back to pure lines will add some work as we need another method to specify events and methods.

The name labes are the easy ones – I currently let CP’s control displaying of labels (event names or method names), but I will move that to the lines itself anyway. It is also possible that I can allow user to move CP’s themselves or simple not show the CP’s once they are connected. Moving a CP is a bit difficult as current mouse click is connect, but lets see. On the other hard I also want to be able to connect to the same method on several edges without having CP positions forcing my hand. What I will miss is the functionality where you just use your mouse, click on a CP and connect to another CP as having to select the Flow tool is extra work, but now I am just being pouty 🙁

As for getting things right – we have the compiler that can pick up if flow lines are properly terminated or not, but the nice think is that we can chose to not care about thos details as we design as it is an implementation issue.

Just for the record – PLD cover UML State Diagrams, SDL (Specification and Description Language) as well as basic flow charts. PLD is a merge of those modelling techniques. Your diagrams can be what you want them to be + design is an important task of SW engineering, so having nice, precentable diagrams are a must.

Another issue I need to dig into is flow of events vs flow of data. I had a need to differ the two for illustrative purposes. And I also need an option to use a single line for multiple events on high level diagrams – this can be a special, thicker line where the user can drill down to see details. All in all – this had to be expected – adjustments as we start using the tool.