lamboom Posted March 2, 2017 Report Posted March 2, 2017 (edited) Hi... This is kinda simple.. but.. methinks I may have a problem using the wrong Data Type with the REPEAT, UNTIL, END_REPEATE function: I'm trying to create a ramping function at the start of a position stream. The idea is to start the first point at zero and take 3 seconds to ramp up tp a preset "Percentage" of full amplitude of a changing position curve... Here's the curve in blue: Normally, at first start of this curve, there is a rapid rise from zero ... which is too almost too fast.. I would like to bring the curve into operation, slowly... from zero .. Like a Volume Control .. Here, I'm trying to use the REPEAT..UNTIL ...END_REPEAT ... The plan was to start at zero.. then, each CPU cycle add .0001 to "Num" ... and keep doing that until Num is greater than 3. During this time, Num/3.0 is being used to multiply the position signal. I'm expecting Num to go from 0.0 to 3.0 in 3000 CPU cycles .. But... It doesn't .. instead it instantly (or, perhaps takes just a few CPU cycles) jumps to 3.0 : Anyone out there know of a better way ro ramp a signal from zero to full in a set time? Thanks much... Regards, Michael Edited March 2, 2017 by lamboom
Michael Walsh Posted March 2, 2017 Report Posted March 2, 2017 Don't use the repeat function. It is a loop and will do it all in one scan. Just use an if then statement like this: This will add 0.0001 to Num each primary period. If it is too fast, make 0.0001 smaller. If it is too slow, make 0.0001 larger. You could also not have this execute every scan and use a timer to trigger when it adds the amount if you wish for the step to be 0.0001, but need it to go slower. When ready to have this execute again, simply move a Real#0.0 into NUM.
lamboom Posted March 2, 2017 Author Report Posted March 2, 2017 (edited) Michael ... Ya know, I really don't want to thank you with just words... On "Game of Thrones" John Snow's Wildling girlfriend always said "Words are wind" ... There must be a way to show my appreciation ? Regards, Michael PS.. Wow.. I didn't know loops do it all in one scan .. that explains a lot! Edited March 2, 2017 by lamboom
lamboom Posted March 2, 2017 Author Report Posted March 2, 2017 (edited) Michael .. You're a wonderful person. Thanks! (words .... sigh) Edited March 3, 2017 by lamboom Wrong picture
Berti Baker Posted March 3, 2017 Report Posted March 3, 2017 Hi Michael is bang on about the loop executing in one scan. You should also take a look at the Instuction Reference for CTU Count Up instruction. This is a good way to count between cycles, even just trigger on every scan. There is also the TON instruction which counts time up to a certain maximum and has the current Elapsed Time as an output. However the output is Time format and imagine you prefer the number from CTU which you can use in formulas, Sin etc Regards BB
lamboom Posted March 3, 2017 Author Report Posted March 3, 2017 Berti -Thanks for the reply. That picture was placed by mistake.. it showed the same thing that was at the top of this thread, plus the math for generating the sine summation in the large picture of the IF-THEN working to help "ramp" the start-up ... The math was created by innoaloe, on another thread.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now