- Index
- » Programming
- » Modelica Language
- » problem in decoder
problem in decoder
problem in decoder
I try to write a Block decoder, which a part of ADC is. The Input and output are digital vector, which consist of logic '1' or '0'. the input vector is 1023bits (1023=2^10-1) lang and the output vector is 10 bits lang, when the ADC 10 bits has.
the ideal of the decoder is: First, i get the number of '1' in input vector. Than I use the function div() and mod() to change the numeber in decimal system to binary system. For the Rest of Digitaloutput i give all bits '0'.
But the compiler said that " The given system is mixed-determined. [index > 3] Please checkout the option "--maxMixedDeterminedIndex". "
Than I deleted the initial algorithm and put it in algorithm. But the Output don't have beginvalue and 'Chattering detected around time 0..9.22009327831e-011 (100 state events in a row with a total time delta less than the step size 0.002). This can be a performance bottleneck. Use -lv LOG_EVENTS for more information. The zero-crossing was: div(decoder1.a, 2, 2)'
```
block decoder
parameter Integer Res(min = 1, start = 10, fixed = true);
parameter Integer Step(min = 1, start = 1023, fixed = true);
//Resolution
Modelica.Electrical.Digital.Interfaces.DigitalInput result[Step] annotation(
Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Digital.Interfaces.DigitalOutput Binary[Res] annotation(
Placement(visible = true, transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Integer a;
Integer b;
import L = Modelica.Electrical.Digital.Interfaces.Logic;
Modelica.Electrical.Digital.Interfaces.DigitalInput De_clk annotation(
Placement(visible = true, transformation(origin = {-6, 98}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-6, 98}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial algorithm
for i in 1:Res loop
Binary[i] := L.'0';
end for;
algorithm
a := 0;
b := 0;
if De_clk == L.'1' or De_clk == L.'H' then
for i in 1:Step loop
if result[i] == L.'1' then
a := a + 1;
end if;
end for;
while div(a, 2) <> 0 loop
when mod(a, 2) == 1 then
Binary[Res - b] := L.'1';
end when;
when mod(a, 2) == 0 then
Binary[Res - b] := L.'0';
end when;
a := div(a, 2);
b := b + 1;
end while;
Binary[Res - b] := L.'1';
end if;
if Res - b - 1 > 0 then
for i in 1:Res - b - 1 loop
Binary[i] := L.'0';
end for;
end if;
equation
end decoder;
```
I don't have a ideal to fixed. Should i write the initial algorithmus or not?
Re: problem in decoder
The initial algorithm or equation are used to improve convergence. Here there is no convergence problem, so I do not think that any initialization is needed.
You are declaring: parameter Integer Res(min = 1, start = 10, fixed = true); the normal way of declaring parameters is just: parameter Integer Res=10; The use of start is normally for giving a warning that you are using a default value.
You explain that the input and output are boolean values (0 or 1). Why do you use an array of DigitalSignal, that is an enumeration, so integers, and not an array of Modelica.Blocks.Interfaces.BooleanInput, and Output?
You can't use when in the way you do. The when statement is used for changing tha value only when a condition is met, otherwise it remains in the same value, and it can't be used inside loops or if statement, as OpenModelica is telling in the message browser. Change it for if statements.
- Index
- » Programming
- » Modelica Language
- » problem in decoder