← All exercises

Batch Counter

easy

Pulse BatchReady every 5 trigger events and track the running batch count.

What it teaches

Pulse a 'batch ready' signal every 5 items, and keep track of how many batches have completed. The 'ready' pulse should be one scan wide — a heartbeat, not a hold. A common pattern in packaging and dosing systems.

Inputs and outputs

TagTypeDefaultDescription
In_TriggerBOOLItem trigger event
Out_BatchReadyBOOLBatch ready signal
Sts_BatchCountDINTTotal completed batches

Required behavior

  • Out_BatchReady pulses high for exactly one scan when 5 rising edges of In_Trigger have occurred.
  • Sts_BatchCount increments each time a batch of 5 items is completed.
  • After Out_BatchReady pulses, the next 5 rising edges of In_Trigger are needed for it to pulse again.