Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mathcad WHILE loop inside an IF statement 1

Status
Not open for further replies.

lgunseor

Electrical
Feb 28, 2013
10
Having an problem with a Mathcad WHILE loop (using Mathcad 15). I'm reading data in from a file, the data is from an accelerometer. I want to set up an IF statement to set a variable to 1 when the rising edge of the signal is greater than 5 g's but I don't want to reset the variable back to 0 until the signal drops to below 2 g's. If I do just the IF statement it work fine but switches the variable to 1 on the rising edge of the pulse at 5 g's and sets it back to 0 on the falling edge at 5 g's. I want the variable to be reset back to 0 at 2 g's on the falling edge. Attached is my attempt of a WHILE loop inside a IF statement, I'm having issues trying to determine how to structure the WHILE loop. Any help with this would be appreciated. Attached is a PDF of the waveform and my attempt at the Mathcad programming.
 
Replies continue below

Recommended for you

what do you want it to do in between 2 and 5? If you want it to be the value from the data you could write it like if(F[i>5,1,if(F[i<2,0,F[i)), so just an if statement within another if statement. depends how you want to treat the internal values.
 
StructSU10, When the value is between 5 and 2 I want to output a 1 to a graph and when it's not between 5 and 2 I want to output a 0 to a graph. The issue is on the pulse I am triggering this off of I don't want to trigger the output to a 1 until the rising edge reaches 5 and don't want to trigger the output to a 0 until the falling edge reaches 2 (see attached JPG). Would the equation you had listed do this.
 
 http://files.engineering.com/getfile.aspx?folder=fcf095fe-a997-4c8d-94dd-df4276ea8e45&file=pulse_triggers.jpg
You need to create a state machine with two states. The state and the input is what determines the next state. This should be familiar from any EE logic class

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
StructSU10,

I'm looking for a 1's and 0's graph (see attached). I can get this with the single if statement shown above the graphs but it is switching to a 1 at 5 (rising edge of pulse) and a 0 at 5 (falling edge of pulse). What I'm trying to do is switch to a 1 at 5 (rising edge of pulse) and switch to a 0 at 2 (falling edge of pulse). Graph would be 1's and 0's as shown. As I move the value down on the falling edge of the signal this will increase the width of the digital pulses i.e. the amount of time that it stays at a 1.
 
 http://files.engineering.com/getfile.aspx?folder=688f0440-9e8f-40af-92e8-9ddf2d42b9f9&file=graph_of_if_statement__.pdf
IRstuff,

Understand state machines and doing this in standard software programming is straight forward, I'm trying to understand how this needs to be structured in Mathcad 15 so Mathcad understands the equation and can process it. If you have any suggestions on how to do this in Mathcad 15 I would be interested.
 
Occupant,

Thank you very much this is exactly what I was trying to do. Plotted out the 1 and 0 states against the waveform and you can see that it is triggering on 5 on the rising edge and 2 on the falling edge (see attached plot). Thanks again.
 
 http://files.engineering.com/getfile.aspx?folder=70fcd647-811a-4390-82f2-12787ed89a32&file=wave_flag_plot.pdf
Status
Not open for further replies.

Part and Inventory Search

Sponsor