Simulation tool cannot recognize if pulse width smaller than delay cell in verilog - version-control

I am using VCS tool to verify for 1 AND logic cell.
I set the 2 inputs = 1 (pulse signal) with pulse width is 25ps.
Delay cell define in verilog model of cell AND is 26ps.
Because pulse width = 25ps < delay cell = 26ps so output is always 0 even that 2 input equal 1 during 25ps.
I want to ask in the real chip, Whether we can detect this pulse or not ?
Anybody can help me.
output should equal 1 for about 25ps.

VCS (and other simulators) have switches to control how they handle these situations.
Look at +pulse_e, +pulse_r, as well as things like +transport_int_delays, +transport_path_delays, +pulse_on_event, +pulse_on_detect, and +delay_mode_*, etc.
You can have the simulator propagate that short pulse (25 < 26). You can have it propagate 1'bx, or you can have it swallow it and propagate nothing.

Related

Updating value in Simulink

I am currently working on a spacecraft body with actuator, and given the equation below:
J·w_dot = -w^x·J·w + u (1)
where w^x is actually a notation of 3x3 matrix
[ 0 -w3 w2
w3 0 -w1
-w2 w1 0]
By rearranging (1), I got w_dot = (-w^x·J·w + u)/J. And here I face the problem, I need to update value constantly for w_dot but I have no idea how. I have tried the Memory block but it only update every 0.2 seconds which is not appropriate for the system.
This is my current setting:
I was thinking the integrator block could be the one to be updated every single cycle as initial condition could be set.
Yes, your solution seems about right; the integrator block will cause the system to be continuous-time, rather than discrete-time. This will output results as accurately as Simulink can accomplish.
You can set initial values for the integrator by double-clicking on the integrator block, setting the "Initial condition source" to "external", then connecting another input or constant block, output, or whatever else you want providing the initial value.
By the way, is J is the inertia tensor? In that case, you can't simply "divide" by it; you should multiply by its inverse (setting "Matrix" as the "Multiplication" option in the Divide block's options)

Hold constant signal

I have the model of a dynamic system in Simulink (I cannot change the programming framework). It can be described as an oscillator subject to periodic oscillations. I am trying to control its motion, in particular, to maximize it (for energy generation).
With latching control (a popular control strategy), the idea is to 'latch', i.e. lock in place, the device when its velocity is 0 for a predefined time, and then release it until its velocity reaches 0 again.
So, what I need to do in Simulink is to output a signal 1 once the velocity signal reaches (or is close to) 0, hold it constant for a time period (at 1), then release it (the signal becomes 0), and repeat the process once the velocity reaches 0 again.
I have found a good blog on holding signals constant in Simulink:
http://blogs.mathworks.com/simulink/2014/08/06/how-do-you-hold-the-value-of-a-signal/
However, in my case, I have two conditions for determining the signal: the magnitude of the velocity and the time within the time period. Now, the problem is that as soon as the period is finished, and the device is released (signal = 0), the velocity is still very small, which could result in an incorrect signal of 1 if an if-loop is used.
I think using an S-function may be the best solution, but then I will have to use a fixed time-step. Are there any Simulink-native solutions for this problem?
I ended up using a Matlab function as a temporary solution, and it is very effective. I have taken inspiration from https://uk.mathworks.com/matlabcentral/answers/11323-hold-true-value-for-finite-length-of-time
u is the velocity signal.
function y = fcn(u,nlatch)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function is used to determine the latching signal.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Using persistent memory:
persistent tick started sign;
% Initialize variables:
if isempty(tick)
tick = 0;
started = 0;
sign = (u>0);
end
U=0; % no latching
s=(u>0);
if s~=sign
started = 1;
end
if started
if tick<nlatch
tick=tick+1;
U = 1;
else
tick = 0;
started = 0;
sign = s;
end
end
y = U;
end
However, as I mentioned, I have to use a fixed step solver, which is no big deal to me, but it can create problems to other users.
If anyone has a more "Simulink-native" solution, please let me know!
Edit
I have now modified the function: the latching is now applied when there is a change in sign in the velocity signal rather than looking at a small magnitude as earlier on (abs(u)<0.005), which was too case-specific.
A colleague of mine has also found a Simulink-native solution:
However, the Matlab function is faster (less computing intensive) when the same time step is employed. Maybe the least computing-intensive solution is a C S-function.

MATLAB / Simulink: Simulation of a motor control valve

Problem description:
I want to simulate a motor control valve (MCV) with Matlab / Simulink. A control-singal (red) controls the MCV, which can take every value between 0% (completely closed) and 100% (completely open):
I indicated the three different pulses of the input-signal with 1, 2 and 3. As soon as the input-signal changes from 0 to 1 (rising edge), the MCV starts to opens. After time t_Op, the MCV is completely opened. As soon as the input-signal changes from 1 to 0 (falling edge), the valve starts to close. This process is finished after t_Cl. Please note that t_Op and t_Cl do not neccesarily have to be identical.
As you can see in the diagram, the valve gets completely closed after pulse no. 1 (falling edge). However, the width between pulse no. 2 and pulse no. 3 is not long enough to completely close the valve. At the rising edge of pulse no. 3, the valve opens again until it is completely open.
Question:
I want to simulate the process described above with Matlab (prefered) or Simulink. I am not a 100% sure how to get started with that problem. I thought about extracting rising / edges from the original system and use this "triggers" to initiate some time-dependent, "sloped"-step-function. Maybe you have some hints for me?
To simulate this, you need to define:
1) Time resolution (0.1 s? 0.01s?)
2) Valve resolution (probably 1%)
3) How to quantize your control signal (If it's just 0 or 1, this is already done; if it's 0V -> 5V, you need to pick which values become off, which become neutral, and which become on
If you quantize your data to 0.1 seconds, and quantize the valve resolution to 1%, you can use something similar to the following (you should be able to fill in the %%% sections yourself
pos_initial = 0; % percent, position
t_res = 0.1; % seconds
pos_res = 1; % percent
%%% Declare t_op, t_cl. Solve for open_speed and close_speed If you have t_op and t_res, how can you solve for the open_speed (the amount of opening in a single step? Do the same for close_speed %%%
position(1) = pos_initial;
for ii = 2:length(input)
if(input == 1)
position(ii) = min(position(ii-1) + open_speed, 100); %this makes potition get bigger, but doesn't let it get bigger than 100%
else
%%% Looking at the position(ii) line above, how could you do the same for closing to make sure it doesn't go below zero?
end
end

Is there a way to enforce the simulation step to be smaller than a compile-time constant in simulink?

Question
Is there a way to enforce the simulation step to be smaller than a compile-time constant in a simulink model?
Context
I'm trying to build a PWM block on simulink. As it is now, I have to make sure that the user chooses a step size responsibly (smaller than half the period chosen by him), otherwise the block behaves abnormally. The only way I came up was to stop the simulation if the step size is not small enough, but I find that very annoying (as a user). If possible, I'd like for the user to not worry about this at all.
Here's what I would do: add the following pseudo-code to the block callback StartFcn:
T_PWM = get_param(gcb,...); % get the block parameter (period) of the current PWM block (string)
T_PWM = str2double(T_PWM);
T_solver = get_param(bdroot,'FixedStep'); % get fixed used by the solver (string)
T_solver = str2double(T_solver); % convert from string to double
if T_solver > 0.5*T_PWM
error('Solver step size must be smaller than half the PWM period')
end

Implementation of custom counter logic in SIMULINK

I am trying to implement a counter logic in SIMULINK where
in1, in2 are inputs
out1 is the output
if in2 = 0, out1 = 0;
if in2 = 1, out1 = 1 after x high edges of in1
I have tried using "Detect Rise Positive" block but failed miserably because I don't have sufficient experience of implementing a timing diagram correctly in SIMULINK. Could anyone kindly point me to the right direction?
Update
An approach I have taken since I posted this question is the "Triggered and enabled subsystem". I am trying to set it up so that:
in2 becomes the enable signal
in1 becomes the trigger
in2 becomes the intput to the subsystem
Out1 becomes the output of the subsystem
But I think that the above was rubbish. Unfortunately it is not VHDL where I could have implemented it using 4-5 lines of description of the hardware logic.
Using a Triggered and Enabled subsystem is the right approach, but your inputs (and no doubt what's inside the subsystem) needs to be modified.
Don't have any input to the subsystem (other than the trigger and enable signals).
Inside the subsystem,
set the enable block property to reset the state when disabled.
set the outport property to reset when disabled and give the initial condition as 0.
create a counter out of a constant (value=1), a summation and a unit delay block.
feed the counter into a Compare to Constant block set to the 'x' value in your question.
feed that block to the outport.
When enabled, the counter should count the required number of steps (when triggered) before the output goes high.
A counter logic can be implemented very easily in simulink. Take a switch,give the control input as int1. If int1 is 1 ur output shuld be 0 else take another switch give its control input as int2. if int2 is 1 ur output shuld be 1+ previous value given in feedback funit delay block