Add zero speed timers to optoscript

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.

nRotationLoopIndex = 0 to 3 step 1

pRotation = ptRotation[nRotationLoopIndex];

StartTimer(dtRPM);

if(GetPeriodMeasurementCompleteStatus(*pRotation))then

 itRotationPeriods[nRotationLoopIndex] = 60/(GetRestartPeriod(*pRotation));

elseif(HasDownTimerExpired(dtRPM))then

     itRotationPeriods[nRotationLoopIndex] = 0;

endif
next

Is this on SNAP PAC or EPIC (or RIO)?

What module part number?

I am using the epic groov controller with the idc-24 module.

Reason for me asking is I remembered this issue, but I doubt you are configuring the module via MMP.

https://opto22.com/support/resources-tools/knowledgebase/kb90748

That said, it would be worth looking at the module firmware version as your issue, and the KB description, seem to be a solid match.

@philip any thoughts on this?

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
2 Likes