Since you have an INPUT that indicates the start of the item that your are scannong and a second INPUT that goes active at the end of the item, the problem is pretty simple:
- On the rising edge of the StartScan INPUT reset your minimum detector
- On the rising edge of the EndScan INPUT display the minimum value
- In between the StartScan and the EndScan events, periodically call a CF to measure the object and keep track of the minimum analog value
I've attached a the ladder logic to solve the problem.
There are 3 CF (custom functions) used. One to reset the minimum detector, one to sample the ADC(1) value and the last to display the minimum value.
' RstMinDetector - CF to reset the minimum detector
'
SetLCD 0,1, "\01" ' clear LCD screen
MinValue = 4095 ' reset to the max ADC ouput value
[/font][/color]
*******************************************************
' Measure - CF to take an ADC measurement and keep track of the smallest value
'
CurrentValue = ADC(1) ' take the measurement
SetLCD 1,1, "ADC(1): " + str$(CurrentValue) + " "
' Minimum detector
'
if CurrentValue < MinValue
MinValue = CurrentVAlue
endif
[/font][/color]
*******************************************************
' DispMin - CF called to display the minimum value on the LCD display
'
SetLCD 2,1, "Min: " + str$(MinValue)
[/font][/color]
*******************************************************
Oh I am a big fan of using the Define Variable names.
The variable "CurrentValue" is defined as DM32[1]
and the variable "MinValue is defined as DM32[2].
Best of luck
Gary D*ickinson