<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>RPM Calculator with Labview and Pi Pico (Trial Version)</title><link>/products/devtools/ni-labview/b/labview-challenge-blogs/posts/final-project-dc-motor-speed-monitoring-control-using-labview-pi-pico</link><description>Introduction:
In this blog, I will be creating a VI to calculate RPM. This VI will be a trial version. I will post a final blog later with the complete VI. I had already setup the pico board in my previous blog .

Components Used:

Raspberry Pi Pico
C</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: RPM Calculator with Labview and Pi Pico (Trial Version)</title><link>https://community.element14.com/products/devtools/ni-labview/b/labview-challenge-blogs/posts/final-project-dc-motor-speed-monitoring-control-using-labview-pi-pico</link><pubDate>Fri, 27 Oct 2023 10:51:49 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:56cd66ff-d5b9-4998-abaa-5875b7f49207</guid><dc:creator>Andrew J</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;First off, I want to be clear I&amp;rsquo;m not being critical in any way: LabVIEW is such a different approach to what you may be used to that getting this far in such a short time is a great achievement and you&amp;rsquo;ve picked an interesting project to start with. &amp;nbsp;Posting responses is always open to interpretation &amp;nbsp;versus being sat with someone so you look them straight in the eyes!&lt;/p&gt;
&lt;p&gt;I do want to ask how well this works and maybe give some pointers. &amp;nbsp;It&amp;rsquo;s hard to follow because of all the sequence structures and local variables. &amp;nbsp;I don&amp;rsquo;t understand why so many sequence structures as it breaks up the natural dataflow processing that LabVIEW uses; sometimes it has to be done because there&amp;rsquo;s no other way of controlling the dataflow mechanics needed but so many is a bit of a red flag. &amp;nbsp;Really you need to consider the mechanics of dataflow and controlling the execution that way.&lt;/p&gt;
&lt;p&gt;I thought at first that the while loop testing against a value of 3500 would never exit once it got going, but of course it never really starts, it only runs once. &amp;nbsp;The case statement is entered when the read value is less than or equal to 1000 then hits the while loop which exits when the value is less than or equal to 3500 which of course it always is. &amp;nbsp;I guess that means the code does only run when nothing is front of the sensor which is what you want. &amp;nbsp;Sort of: isn&amp;rsquo;t it only counting whenever something isn&amp;rsquo;t in front of the sensor which depending on the speed of LabVIEW execution vs speed of rotation could be multiple counts within one &amp;lsquo;gap&amp;rsquo;. &amp;nbsp;I think the whole timing of this is difficult actually and would need tuning through testing, probably involve testing for gaps and blades. &amp;nbsp;I may well have misunderstood what is happening here.&lt;/p&gt;
&lt;p&gt;Your use of local variables is almost guaranteed to cause race conditions, but it isn&amp;rsquo;t clear in every case what they are tied to. &amp;nbsp;For example you have an indicator timestamp but have created another one called time_stamp so you can have a local variable that isn&amp;rsquo;t tied to timestamp. &amp;nbsp;Look at image 8; you are updating the indicator and its local variable at the same time with the same value - it&amp;rsquo;s not necessary because they are the same thing. &amp;nbsp;You have the same thing going on in 7 with all the RPM variable updates. &amp;nbsp;Image 4 is a good example of a race condition: you are using the local variable representation of count, and all three elements in that image are the same thing. &amp;nbsp;So you read count, say value is 5, and 5 travels on the wire towards count and towards the increment (there is actually a +1 function by the way) where it changes to 6 and travels towards count. &amp;nbsp;Which gets there first and is count 5 or 6 at the end? &amp;nbsp;You can&amp;rsquo;t guarantee the order of execution because of dataflow. &amp;nbsp;I suspect you&amp;rsquo;ve been lucky and that the 5 reaches count before 6 does because it doesn&amp;rsquo;t go through the increment but it is just luck.&lt;/p&gt;
&lt;p&gt;As much as possible, you have to avoid local and global variables. &amp;nbsp;Sometimes they are needed - I&amp;rsquo;ve used them - but it&amp;rsquo;s always a potential source of race conditions in LabVIEW so you need to be really careful where they are read and updated because fundamentally LabVIEW controls the execution sequence, not you; you have to influence this by controlling the flow of data so parts of the code get executed when the data is available. &amp;nbsp;You can see how wacky this looks by running the VI with the data flow switch on (the lightbulb on the menu bar in the debug section) - it&amp;rsquo;s insightful to see which parts of the code run.&lt;/p&gt;
&lt;p&gt;Here are some pointers: take a look at Shift Registers for value updates through repetitions. &amp;nbsp;I can see you are using these for the visa session and error control/indicator on the outer loop. &amp;nbsp;These aren&amp;rsquo;t necessary actually, and I have the feeling that if an error was raised in one&amp;nbsp;of the SCPI functions it would loop forever. &amp;nbsp;I suppose it does anyway, until Stop is signalled so it isn&amp;rsquo;t important, just not doing what you think it might be. &amp;nbsp;See if you can rewrite this without local variables or the sequence structures and come back here with questions so we can help.&lt;/p&gt;
&lt;p&gt;Can you post the front panel? &amp;nbsp;Video showing it working?&lt;/p&gt;
&lt;p&gt;Just to re-iterate, I&amp;rsquo;m not being critical I think you&amp;rsquo;ve had a good go on a complex dev tool that I&amp;rsquo;m assuming is new to you. &amp;nbsp;The challenge was to learn LabVIEW which you are clearly starting to get to grips with. &amp;nbsp;Perhaps someone else will come along and tell me where I&amp;rsquo;ve misunderstood something myself as I&amp;rsquo;m new to it as well.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=27107&amp;AppID=423&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>