timeevent with iterative process

Moderators: Frank, paul, Hiwot, Chris, peter

Post Reply
Posts: 49
Joined: Thu Mar 07, 2013 10:10 am

timeevent with iterative process

Post by bendesarts » Tue Oct 07, 2014 11:19 pm


In a model, I programmed a little algorithm (gradient algorithm). This algorithm is not complex but it works with discrete time in a continuous simulation. So, I would like to use the timeevent function each 2s (for example) in my model and for this time, I would like to calculte my algorithm.
For the moment, as i didn't manage to do this, I repeat several times the timeevent function but I can not do it 30 times... :?
Consequently, I try to use the frequencyevent function (like explained in the discretevent model). I have used this code :

Code: Select all

output = frequencyevent (periodTime, offsetTime);
	if output==1 then
	next (total) = total + output*sampletime;
	sortie = total + initial;     
The problem of this code is that the sampling leads the program an error in my simulation. The error underlines me that the issue is linked to derivative functions associated to discrete time.

Consequently, I would like to use only the fonction timeevent but without having a sampling (visible with the discrete tab).


Do you have some ideas to use the timeevent function each T second but without having sampling ?

Thanks a lot for your help.

I hope my post will be clear enough.

Posts: 152
Joined: Mon Sep 19, 2005 2:00 pm
Location: Controllab Products B.V.

Re: timeevent with iterative process

Post by paul » Wed Oct 08, 2014 11:01 am

Thanks for your question.

First of all: 20-sim does not crash! In fact it gives you a nice error message that tells you that your model is wrong, and why it is wrong.

Now if you really would like to emulate a discrete time part in a continuous time model, you can make this yourself with frequencyevent or timeevent functions, together with the code and the major keywords.

This is however not needed at all, since 20-sim also supports discrete time parts directly!
Please use the sample and hold functions for this, like:

Code: Select all

    real a, v, x;
    real vk, xk;
    // continuous time part
    a = time;
    v = int (a);

    // going to discrete time
    vk = sample (v);
    next (xk) = xk + vk * sampletime;

    // and going back to continuous time
    x = hold (xk);
Now you have in the Run settings of the Simulator a discrete system tab, where you can specify the sample rate of your discrete time part (that calculates vk and xk). Do plot v, x, vk and xk to get the idea.

Please have a look in the 20-sim help, this might save you a lot of time!
Here is a link to the topic on this: http://www.20sim.com/webhelp/editor_usi ... models.php

member 20-sim development team

Post Reply