Here I have a code for you written in quick thinking.
It should work out, if not, should give you some ideas.
As Steve mentioned, there are actually two different arrays in this code but one is hidden in for loop.
Code:
'...Do the port registers, ADC settings etc. here...
A VAR BYTE 'A loop variable.
Z var byte 'Dynamic end point for loop.
Flag var byte 'The array address where we hit the out of limit.
Dumpy VAR WORD 'A dummy variable.
X con 13 'Lower limit
Y con 25 'Upper Limit
ADCData VAR WORD[31]
Serpin VAR PORTC.0
Start:
Flag = 100 'Default value.
Z = 20 'Normally, initial reading is 20 times.
FOR A = 1 TO Z 'Take Z times readings.
ADCIN 0,adcdata[A]
IF ADCDATA[A] < X OR ADCDATA[A] > Y AND Flag = 100 THEN
Z = 30
Flag = A 'Store the array variable where we hit the reading out of the limit.
ENDIF '[ why Z = 30 ? : IF we have a reading out of the limits,
PAUSE 1000 'Wait for 1 second. '...we then add 10 more locations to our array
NEXT A '...so that we can add extra 10 readings after the event.]
'Now, readings are complete.
IF Z = 30 THEN 'if Z = 30 that means we had an "out of limit" reading.
FOR A = (Flag-10) TO (Flag+10) 'Flag is the point where we hit the first out of limit reading.
'Serout your values here.
'You need to send your values starting from -10 AND +10 of array location using Flag value.
Dumpy = ADCData[A]
SEROUT Serpin,4,[Dumpy.LowByte,Dumpy.HighByte]
NEXT A
ENDIF
GOTO Start
Bookmarks