Working

⚙️ Overview: What does this function block do?

FB_ProductBuffer_NoArray_TCK is a FIFO-style product buffer for a PLC, that:

All of this happens without arrays, using STRUCTs with fixed entries like _0, _1, … _9.


🧠 Inputs and Outputs

Name Type Description
SensorInput BOOL Digital input from the product detection sensor
TimeDelay TIME The wait time required per product before triggering movement
SystemTime TIME The current PLC runtime time (from TIME_TCK)
TriggerFeedback BOOL External signal indicating the current movement is complete
TriggerMovement BOOL Output signal to start a movement
ProductCount INT The number of currently buffered products waiting to be processed

🧱 Internal Variables (What they're used for)

Variable Purpose
StartTimes._x Timestamp of when a product was added to buffer slot _x
Actives._x Flag indicating whether slot _x is active (has a product)
InsertIndex Index of where the next product should be added (0–9, wraps around)
PrevSensor Stores the previous sensor value for edge detection
MovementActive TRUE when a movement is in progress
Elapsed Time difference (in ms) between SystemTime and product StartTime

🔄 Step-by-step Logic

1. Rising edge detection from sensor

F SensorInput AND NOT PrevSensor THEN