Hi I am having a difficult time getting the zero speed timers to work correctly using optoscript. I am measuring the rpms of 4 shafts. I can get the rpm measurements but if the shaft stops it just uses the last period measurement and calculates the rpm with that. This is what I currently have. I tried making a timer table but I get the same results.
Thank you for the help. I am not using MMP. I am using PAC Control Pro. Here is a screen shot of the issue im having. I cant get the zero time to work. The RPMs and the timer is running but when I stop the shaft from rotating its supposed to wait for the timer to expire if it doesnt get another period complete and then set the rpm to zero. I can get it to work with just using the blocks but I would like to see if I can incorporate it all in one script for all four shafts. Ive tried making multiple timers, tables for timers, but I dont think my logic is correct for the zero or for getting the ival value to reset. Usually I would use frequency but this setup only has 1 pulse per rev.
You want to restart your timing each time you receive a pulse measurement. You will need a separate timer (or timer table) for each shaft. The way you have your logic written in your first post, the timer will keep getting restarted, so it will never expire, and you are using one timer for all 4 shafts which will not work.
Here is with a timer table, using an up timer for better accuracy.
if(utLastPeriodUpTimer == 0.0) then
StartTimer(utLastPeriodTimer);
endif
if(utLastPeriodTimer > 0.5) then //Set for ~500ms resolution, adjust as needed
//increment timer table
fLastPeriodTimerValue = GetRestartTimer(utLastPeriodTimer);
for nRotationLoopIndex = 0 to 3 step 1
ftLastPeriodTimerTable[nRotationLoopIndex ] = ftLastPeriodTimerTable[nRotationLoopIndex ] + fLastPeriodTimerValue;
next
endif
for nRotationLoopIndex = 0 to 3 step 1
pRotation = ptRotation[nRotationLoopIndex];
if(GetPeriodMeasurementCompleteStatus(*pRotation))then
itRotationPeriods[nRotationLoopIndex] = 60/(GetRestartPeriod(*pRotation));
//Measured a pulse, reset the timer table for this shaft
ftLastPeriodTimerTable[nRotationLoopIndex] = 0.0;
elseif(ftLastPeriodTimerTable[nRotationLoopIndex] > fStoppedShaftTime)then
itRotationPeriods[nRotationLoopIndex] = 0;
endif
next