Hi,
I am designing a fairly simple embedded system. It is probably similar to a million other embedded systems, but I'm very new to the field and am struggling with the problem of "initial conditions."
The system works like so:
1) All the inputs are predefined. Each one can be thought of as just a single floating point number. An example of an input might be the voltage measured on an A-to-D pin, or it could be something else. As far as the user is concerned, it's just a number that is magically pumped into the system and constantly changing.
2) All the outputs are also predefined. They are also represented by a single floating point number. That number might become an analog voltage on some output pin, or it might become the frequency of an output square wave, or something else entirely. Each output does something different.
3) All of the "blocks" between inputs and outputs are defined by the user. These blocks can be connected to inputs and outputs in any way that the user chooses. Each one of these blocks performs some small function, for example, an "ADDER" block has two inputs and one output and the value of the output is just (input_a + input_b).
So it's a system that allows a user to build a certain behavior, as far as how inputs are processed and eventually propagated to the outputs.
Ok, here's the catch. The system allows "loops" in the graph. So you could have the output of one block feeding back to the input of another block that is a long way "upstream" (meaning towards the inputs). In fact, this kind of feedback loop is necessary for certain kinds of processing.
These loops make it difficult (maybe impossible?) to ensure that a particular block has been safely initialized, meaning that its output can be trusted for use as input to something else. My first attempt was to make it a rule that a given block is considered uninitialized until all of its inputs had received valid data. But the loop case breaks this model, obviously.
So my next approach was to provide safe initial values for every block in the system. But that also turns out to be nearly impossible, without some human intervention from the user. For example, you can't just initialize the output of every block to zero, because the next block in the chain might be a block that performs the function (input_a / input_b), and this would cause a +INFINITY to be the output of that block. If that +INFINITY is part of one of these feedback loops, then the whole loop will probably become completely invalid. But it only reached that state because of a poor choice of initial conditions. Under normal operating conditions, that "input_b" would never be zero. But there's no way to really know that unless you have some prior knowledge about what the system does and what the "reasonable" ranges of all the inputs will be.
So how is this problem of initial conditions normally solved? It seems to me that the problem would be encountered in any sort of simulation tool that involves a connected graph like this. So any modelling systems like Simulink, or any kind of circuit design tool like PSpice, or any graphical flowcharting tool, etc... would have this same issue. Is there some standard way of dealing with this?
In case my generic description is confusing, here is a specific example of what a user might do that creates a problem.
+-----------------------------------+ | +----------+ | +-->|A MATH | |
+---------+ | BLOCK | +----------+ | | INPUT 1 |------>|B (A/B) |---->|A MATH | |
+---------+ +----------+ | BLOCK | | +--------+ +------------------->|B (A+B) |---+--->| OUTPUT |
+---------+ | +----------+ +--------+ | INPUT 2 |---+
+---------+
Thanks!
Pat