02-12-2013 02:57 AM - edited 02-12-2013 02:59 AM
Hello!
This might be so easy to implement but not for me, at least not at the moment. I would like to create a CAD counter that I need to simulate for testing a subsystem I created, for demonstration purpose. The need is to be able to count from -360 to 360 with a resolution of 0.1 ( preferable if it can be adjusted as the need comes) periodically. i.e Once one full cycle is counted [-360,3609], then the count is supposed to start over.
Has anyone implemented this before? I very much appreciate the help I get.
As always thanks for all the helpful guys up here!
Solved! Go to Solution.
02-12-2013 03:52 AM
Hi Henok,
sounds like you need a comparison function. Quotient&Remainder might help too...
Counting up to a limit and starting over again is a common task. Some pseudo code to get the idea:
ctr := ctr + 1 IF ctr >= upper_limit THEN ctr := lower_limit
02-12-2013 06:36 AM
Could you be more elaborate please? Like an example?
02-12-2013 06:45 AM
2011 compatible vi please
02-12-2013 07:05 AM
Hi Ranjeet,
Here is the 2011 version of what I tried to do 🙂
02-12-2013 09:00 AM
02-13-2013 12:11 AM
Hi Henok,
I am attaching one VI. Enter 'resolution' & 'Delay between two count in ms' & run the program.
Try resolution as 1 & Delay between two count in ms as 100 & see.
Hope this is what you are looking for. Let me know if you need any explanation.
Thanks
02-13-2013 04:05 AM
Thanks Ranjeet!
Its very impressive! I just could not know why it doesnt work for different resolution ( I tried 0.1 as it was my target). I tried to tweak the values and see if it works, but once it starts 360 with the current count, it kept counting up instead of starting over from -360. Any idea why?
02-13-2013 04:10 AM
Please try this & let me know.
Kudos are always welcome.
02-13-2013 04:10 AM - edited 02-13-2013 04:12 AM
Hi Henok,
the problem arises from using the "equal?" comparison on floating pouint numbers.
Ranjeet forgot the inaccuracy of such numbers as was explained a lot of times before in the forum...
Conclusion: NEVER compare floating point numbers for equality!!!
That's the reason why I was using integers for the "counting" part in my example followed by a simple scaling to your desired range...