Shop OBEX P1 Docs P2 Docs Learn Events
This question is for JonnyMac or any one else — Parallax Forums

This question is for JonnyMac or any one else

sam_sam_samsam_sam_sam Posts: 2,286
edited 2010-12-30 08:25 in General Discussion
Here is the question let say that your using an ADC chip and you have voltage result
mVolts like let say 1,2 volts

And you what to see if that value stay the same for let say 2 minutes then exit the routine how would write or the value start going then you want it to stay in that routine

some thing like for inputs that you wrote a while back for me

cntr_S = cntr_S + 1 * Chg_S
IF (cntr_S = 6 ) THEN GOSUB resetData

or am I asking for the impossible and it can not be done that way

any thought on how I could do something along the same idea that would work


I know that I could do something like

GOSUB Get_Time
DEBUG HOME, HEX2 mins, ":", HEX2 secs
IF mVolts >120 and < 125 THEN EXIT
IF mins = $03 AND secs = $15 THEN EXIT

I have not try this but I have the feel that may this may not work the that I want it to work
LOOP

Comments

  • Mike GMike G Posts: 2,702
    edited 2010-12-30 06:29
    I don't have time this morning to write the code but it should be very simple if I understand what your asking.

    Place the current value in a currentValue global variable.
    Get the currentTime or set a time counter
    Start timer loop
    Get the next reading and put it into newValue
    compare currentValue to newValue
    [ if the values are equal keep looping - update any time counters if needed]
    [ if the values are not equal place the new value in current value and exist the loop. ]
    Has time expired? if so exit, else continue
  • David BDavid B Posts: 592
    edited 2010-12-30 08:25
    It's normal for an ADC to show some fluctuation, especially if the voltage is near the bit transition level.

    I don't know Basic, but if you can make an array, you could make a histogram.

    Make an integer array the size of your ADC value, initialize it to zeroes, then for a few minutes, increment the array contents where ADC values equal the indexes:

    repeat i from 1 to 1000
    array[adc_value]++

    Then display the array. You should see a peak at your expected value, with maybe a scatterring of entries on either side of your value.
Sign In or Register to comment.