Shop OBEX P1 Docs P2 Docs Learn Events
Need Help with ADC code — Parallax Forums

Need Help with ADC code

SN96SN96 Posts: 318
edited 2006-02-20 15:46 in General Discussion
Hello guys,

I have developed a sound sensing circuit board that works fantastic but I am having problems getting the code to·read both channels properly. It outputs to the debug window the values of the channels·properly, however I am not able to put those values in to a variable. One variable seems to have the right value while the other variable has some other value.

Main:
  DO
    sglDif = Sgl
    FOR oddSign = 0 TO 1
      GOSUB Read_0832
      mVolts(oddSign) = adc(oddSign) */ Raw2mV
      DEBUG CRSRXY, 7, (4 + oddSign),
            DEC3 adc(oddSign), TAB,
            DEC mVolts(oddSign) DIG 3, ".", DEC3 mVolts(oddSign)
    NEXT
 
            RightEar = adc(1)
            LeftEar = adc(0)
            IF RightEar > 120 THEN
               GOSUB RightEarSub
               IF LeftEar > 120 THEN ' this has some other value different from debug window.
   
                  GOSUB LeftEarSub
               ENDIF
          ENDIF
  LOOP

Here is a screenshot of the debug output:

attachment.php?attachmentid=40529



For single ended, I want to be able to put the 3 digit value of channel 0 and channel 1 in to variables "LeftEar" and "RightEar" so I can do something like this:

IF RightEar > 120 then GOSUB MoveRightServo

IF LeftEar > 120 then GOSUB MoveLeftServo

Thanks for any help at all.







▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike



Post Edited (SN96) : 2/19/2006 10:06:15 PM GMT
661 x 406 - 26K

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-19 22:32
    You're telling it that:
    ··········· RightEar = adc(1)
    ··········· LeftEar· = adc(0)
    But you don't tell it what adc(0) or adc(1) are equal to.
    So...
    Main:
      DO
        sglDif = Sgl
        FOR oddSign = 0 TO 1
          GOSUB Read_0832
          mVolts(oddSign) = adc(oddSign) */ Raw2mV
             DEBUG CRSRXY, 7, (4 + oddSign),
                DEC3 adc(oddSign), TAB,
                DEC mVolts(oddSign) DIG 3, ".", DEC3 mVolts(oddSign)
        NEXT
     
    [color=red]            RightEar = mVolts(1)
                LeftEar  = mVolts(0)[/color]
                IF RightEar > 120 THEN
                   GOSUB RightEarSub
                   IF LeftEar > 120 THEN ' this has some other value different from debug window.
       
                      GOSUB LeftEarSub
                   ENDIF
              ENDIF
      LOOP
    
    

    Post Edited (PJ Allen) : 2/19/2006 10:37:24 PM GMT
  • SN96SN96 Posts: 318
    edited 2006-02-19 23:59
    That did not work, it just made the read values larger. I got my code to work however.

    Thanks anyway PJ.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-20 00:10
    OK, so what was the "fix"?
  • SN96SN96 Posts: 318
    edited 2006-02-20 15:46
    I used adc(0) and adc(1) but I took the values using differential mode.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
Sign In or Register to comment.