Ryan
Now, I understand what you're trying to do. However, reading the adc like this hardly gives you anything worthwhile.
Code:
ADCIN 2, voltLevBf ' sample voltage on ADC 2
PAUSEUS 12
ADCIN 4, threshHold ' get threshold from pot set up as volt. divider on ADC 4
PAUSEUS 12
ADCIN 2, voltLevAf ' sample voltage on ADC 2 again, to check for difference
PAUSEUS 12
Why? The difference between the 2 samples on ADC 2 is just around 25uS. Is this what you really want??
On reading closely, I think you need to do this
Code:
'Find the minimum value
MinAdc var word 'I'm assuming the ADC to be 10bit or more
CurrAdc var word
Threshold var word
DelayVal var word
while 1 ' loop forever
ADCIN 2, CurrAdc ' current ADC reading
ADCIN 4, Threshold ' threshold setting
ADCIN 5, DelayVal ' delay setting
if CurrAdc > MinAdc + Threshold then
High Output
pause DelayVal
Low Output
if CurrAdc <> MinAdc then ' check if the current ADC value < Min ADC
MinAdc = CurrAdc ' and correct the MinADC value
endif
endif
wend
Does this do what you want?
Jerson
Bookmarks