Why is the timing not synchronized between Simulink 6.5 and ModelSim 2.1 when performing cosimulation?

1 view (last 30 days)
When trying to perform co-simulation with ModelSim repeatably, the timing is not synchronized between Simulink and ModelSim. There seems to be no difference whether the TIMESCALES in Simulink are set to 'relative' or 'absolute' timing mode.
For example, I would like to use a sample frequency of 3Hz in Simulink, which corresponds to a non-integer time period. How should I set the timing resolution in ModelSim and the Timescale settings in Simulink to be able to perform the co-simulation?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The key idea here is that the user must always be able to relate a Simulink time with an HDL "tick". The HDL tick is the finest time slice the HDL simulator will recognize; for ModelSim, the default tick is 1ns, but it can be made as precise as 1 fs.
However, 3Hz is actually 333.33333333333... ms, which is not a valid tick period for the HDL simulator. The HDL simulator will truncate such numbers. But Simulink does not make the same decision and so for cosimulation where the user is trying to keep two independent simulators in synchronization, it seems unwise to assume anything. So, instead the user has to decide whether it is convenient to truncate or round the number.
Therefore, the solution is to "snap" either the Simulink sample time or the HDL sample time (via the timescale) to valid numbers. There are infinite possibilities, but here are three possible workarounds:
1. Change Simulink sample times from 1/3 sec to 0.33333 sec 1 second in Simulink = 1 second in the HDL simulator If you are specifying a clock in the Cosim block "Clocks" tab, its period should be 0.33333 sec.
2. Keep Simulink sample times at 1/3 sec. 1 second in Simulink = 6 ticks in the HDL simulator If you are specifying a clock in the cosim block "Clocks" tab, its period should be 1/3.
Briefly, this means, "No matter what the HDL time resolution is, make each Simulink sample time correspond to every (1/3*6) = 2 ticks." If you keep the default ModelSim resolution of 1 ns, that means your HDL sample times are every 2 ns. This will work in a way that for every Simulink sample time there is a corresponding HDL sample time, but as you can see, Simulink thinks in terms of 1/3 sec periods and the HDL in terms of 2 ns periods. This could prove confusing during debug. If you want this to match the "real" period (let's say to 5 places, i.e. 333.33ms), you can follow the option 3 below.
3. Keep Simulink sample times at 1/3 sec. 1 second in Simulink = 0.99999e9 ticks in the HDL simulator. If you are specifying a clock in the Cosim block "Clocks" tab, its period should be 1/3.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!