Combine 2 Seperate Codes in one - Page 1
Forum section: electronics / general

author: ha.azad4444
author_rank: Newbie
timestamp: October 19, 2024, 06:29:00 am
content: Hey Guys!I have two boards with separate functionality:1st one is Elevator Control board which handle input/outputs of sensors, faults, etc.2nd one is Motor Driver which handle motor control methods.Communication of these 2 boards is based one serial or i/o.Each hardware has its one state machine.I designed a new board which contain all hardware functionalities of 2 boards. Now I want to combine 2 state machines and remove redundant codes.for example once the elevator wants to move, elevator board transmit move command to motor driver board. Now it should handle in the code and no hardware implementation is needed.In this situationI need some advice and insights about how to best handle my new implementation?

author: brucehoult
author_rank: Super Contributor
timestamp: October 19, 2024, 07:23:53 am
content: How are your state machines implemented now? How many states and transitions are in each one?

author: ha.azad4444
author_rank: Newbie
timestamp: October 19, 2024, 07:56:34 am
content: Thanks for your answer.Noth much states, for example 5 each. Simple Transition is possible for example from 1st state to 2nd, unless fault occur.Also each board has its own serial state machine to capture correct data unless discard it.Code:typedef enum{NORMAL_OPERATION = 0U ,PARAMETER_MENU = 1U ,PARAMETER_SubMenu = 2U ,PARAMETER_VALUE = 3U ,SAVE_PROCESS = 4U ,FAULT_OCCURRED = 5U}System_Mode_Enum;

author: brucehoult
author_rank: Super Contributor
timestamp: October 19, 2024, 08:21:54 am
content: HOW are the state machines implemented?Electro-mechanical?Discrete electronics?7400-series?PLC?FPGA?Microcontroller?

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 19, 2024, 08:23:46 am
content: Your question doesn't make much sense, if you already developed those two separate boards then you should have a deep understanding of how they work.It's the same thing except you don't communicate with the outside, the two states can tell each other what's going on using variables.As long as you make proper state machines (Avoiding blocking code), should be damn easy.

author: ha.azad4444
author_rank: Newbie
timestamp: October 19, 2024, 08:27:42 am
content: I use STM32 microcontroller for both systems and C-programming language.

author: ha.azad4444
author_rank: Newbie
timestamp: October 19, 2024, 08:57:48 am
content: Thanks for your answer.I DO have a deep understanding of the operations.But in new board I should omit old functionalities, because they are no more needed

author: nctnico
author_rank: Super Contributor
timestamp: October 19, 2024, 09:17:43 am
content: You can turn the processing of the commands into an API layer. In the end a command has to call a function to execute the command. So instead of sending a command, you call a function which executes the command.Look at 'remote procedure calls' and how a communication layer is used to execute functions remotely. You are doing the reverse of that but the principle is the same (in reverse though).

author: brucehoult
author_rank: Super Contributor
timestamp: October 19, 2024, 09:28:17 am
content: Quote from: ha.azad4444 on October 19, 2024, 08:27:42 amSo the simplest thing is to just make each of the current programs into a thread under FreeRTOS or Zephyr, communicating by adding messages to a queue instead of using UART.

author: nctnico
author_rank: Super Contributor
timestamp: October 19, 2024, 09:49:34 am
content: I don't think throwing an OS at it makes life easier in any way. For starters each process needs RAM space for its stack and this needs to be configured. The same for time slice intervals and handling of high priority interrupts. All in all an RTOS adds up to an extra layer of complexity quickly.So whether using an RTOS is a good idea or not depends highly on how the existing code is designed. If the existing code consists of super-loops (round robin scheduler) where there are no delays inside or places where the code halts to wait for something to happen, then creating new software which now calls both super-loops is the easiest by far.OTOH if the existing code contains delay loops / waits for events, an RTOS could be a quick way out but it will need pre-emptive task switching (time slicing) which may not do precisely what you want as timing of the code becomes somewhat unpredictable. Another route would be to convert the delay loops / waiting for events into state machines which exit immediately and can be used in a super-loop construction.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 19, 2024, 11:42:10 am
content: What is the goal you want to reach by putting the parts of these two distinct functions on one PCB?For many years a modular approach has been proven to be the most cost effective. You size the motor controller to the size of motor you need, and you use the "elevator control board" that fits with the complexity of your elevator system

author: nctnico
author_rank: Super Contributor
timestamp: October 19, 2024, 01:14:16 pm
content: Well, if you always need the same sized motor and the same control board, then it makes sense to make an all-in-one product. Having less different products in stock makes life much easier from a service point of view. That also goes for motors. Using the same motor for a wide variety of low volume products helps efficient stock control even if the motor is oversized for some projects. Service engineers will be quite happy to only need 1 type of motor instead of 6 different ones in their van.What I would be more worried about is noise from the motor drive coupling into sensors and what kind of safety features are included on the motor control board which might interfere with the elevator control logic. OTOH a modern day microcontroller is much faster with better response times even when running a relatively large amount of code. And then there is safety certification. This might be easier to pass with two seperate boards. But that is just me guessing.

author: ha.azad4444
author_rank: Newbie
timestamp: October 20, 2024, 06:45:46 am
content: In fact your answer is not correct in my case! We call it an "integrated elevator motor driver" which reduce cost of production , size, wiring and maintainance.