Shop OBEX P1 Docs P2 Docs Learn Events
Urgent! BS Code need.....SOS! — Parallax Forums

Urgent! BS Code need.....SOS!

sckamsckam Posts: 27
edited 2004-08-20 19:39 in BASIC Stamp
cry.gif·Dear BS fans,
I need your urgent help on this, I am running out of
time for this urgent programming requirement.

How to program the equation 1,2,3,4 and 5 into Bs2
code ?

The defination for 'Process Simulator':
This 'Process Simulator' will connect to a PID
Controller.

X=Input of 'Process Simulator' = Output from PID
Controller

X1 = (X + D)
[noparse][[/noparse]1]
X2 = (X+D) (1-exp(-t/T1)) , T1,T2,T3 are delay values
[noparse][[/noparse]2]
X3 = X2.(1-exp(-t/T2))
[noparse][[/noparse]3]
X4 = X3. Ka.(1-exp(-t/T3)), Ka rate of Change of input
gain ---[noparse][[/noparse]4]
Y= X4-0.5, Deduct 50 OR 3V
[noparse][[/noparse]5]

t =instantaneous time value, when X and D are changed,
may use AD
D= Disturbance Input
Ka=2=System Gain=Gain of rate of Change of X & D

X,D,T1,T2,T3 are set by hardware (rotation selector
switch as SW3,SW4,SW5 and SW6),

Ka and 0.5 are set by software.

Y=Output of 'Process Simulator'= Input of PID
Controller

t =instantaneous time value, when X and D are changed,
may use AD sampling time period , t = 0?.?
Thank you for the help.
Best regards.
Kam
lol.gif

Comments

  • Jim EwaldJim Ewald Posts: 733
    edited 2004-08-20 16:23
    What is this simulator supposed to simulate? It looks like the system is injecting noise with a variable time delay between the output of one controller pin and the input of another controller pin.

    How are the variables T1, T2, T3, etc. getting set in the Stamp? Are they going to be hard-coded or are they inputs that have to be detected and decoded while the simulator is running? What is the range of values you expect for these variables. I see that the time period can be 0 to infinity. That's going to be tough to simulate on a Stamp.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Jim
    Parallax IT Dept.
  • sckamsckam Posts: 27
    edited 2004-08-20 16:49
    Dear Jim,
    To answer your questions:

    What is this simulator supposed to simulate?
    It just simulate the effect of the First Order Lag by impose the time delay T1,T2 and T3.

    It looks like the system is injecting noise (D=Disturbance input = Switch SW3) with a variable time delay between the output of one controller pin and the input of another controller pin.
    Yes, you are right.

    How are the variables T1, T2, T3, etc. getting set in the Stamp? Are they going to be hard-coded or are they inputs that have to be detected and decoded while the simulator is running?
    Delay values, T1,T2, T3 are controll by a variable rotation switches(SW4,SW5,SW6) that connect to different value of resistors.(I am sending the Protel schematic for you, it was a old drawing, I already change the grounding for those resistors to +5V to provide current path.)
    Then those delay values will be take into BS2 for those formula to generate the result.

    What is the range of values you expect for these variables.
    As the input = X is vary from 4 to 20mA, (I am not yet showing the connection for this part in my schematic but I will put a 250ohm precision resistor(0.1%) at the input to convert the current input into voltage that going to a ADC0832CCN(this ADC is not showing in the diagram).

    I see that the time period can be 0 to infinity. That's going to be tough to simulate on a Stamp.
    The value for the time period is just controll by the resistor value on those switches, so it will not go beyond infinity level.

    Please do not mind to ask me if you have question again.
    Thank you.Warm regards.
    Kam

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank you.

    Warm regards.
    Kam
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-20 16:53
    Here's a thought ... does the simulation HAVE to run on the BASIC Stamp, or could the BASIC Stamp simply be used as the input device for your resistors that feeds data to a small program that runs on the PC? You formula would be very easy to implement in Visual BASIC, Java, or other PC language.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Jim EwaldJim Ewald Posts: 733
    edited 2004-08-20 18:01
    Kam,

    Jon has a good point in that the simulation would be a lot easier to code on a PC. You can take the computed values and verify them on the test bed. Let me know if that's not an option. Coding the exponential functions o a Stamp is still going to be interesting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Jim
    Parallax IT Dept.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2004-08-20 19:39
    Kam,

    As you know, the BASIC Stamp does not have exponential functions built in. It is possible to compute them directly using integer math, but it does take _time_. Is this supposed to be a real time simulator? That is, do the inputs D and X come from real world processes? I think so, from your description. What is the time scale then? Also, what are the typical magnitudes of the variables and the parameters and what resolution or accuracy do you expect in the output? When you do integer math, the techniques are ad hoc and depend on the answer to those questions.

    One easy way out would be for you to add on a floating point processor, such as one of the PAKs from Al Williams, or the one by Cam Thompson that Parallax is selling. However, those take time to, to load the registers and return the results.

    If the time scale is indeed very long, it should be possible to simulate the RC time lags using three cascaded discrete time low-pass filters in software, on first hack something like the following...

    autonomous:
    ' give X1, X2, X3 initital values
    DO
    X2 = X2 ** decayRat1
    X3 = X3 ** decayRate2
    LOOP

    driven:
    DO
    X1 = X + D
    X2 = X2 ** decayRate1 + X1
    X3 = X3 ** decayRate2 + X2
    X4 = X3 ** decayrate3 + (X3 * Ka)
    Y = X4 - half ' half is represented as a fixed point fraction
    LOOP

    Don't take my word for it. I'm not even sure that represents the system you want to simulate. The time scale factor is tightly controlled by the rate at which the Stamp executes instructions, so the scale factors have to be chosen with that in mind, and every change you make in the program is going to affect the outcome. However, if the Stamp also generates the input X and the input D in simulation, then the time scales will all be commensurate. Does that make any sense?

    Finally, this is basically an analog computer, so a few op amp blocks with RC circuits connected to your switches should do the job just fine, without a microcontoller at all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.