Shop OBEX P1 Docs P2 Docs Learn Events
ADC MCP3204 Demo Advanced Demo.bs2 and ADC MCP3204 Demo.bs2 Question — Parallax Forums

ADC MCP3204 Demo Advanced Demo.bs2 and ADC MCP3204 Demo.bs2 Question

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-10-31 20:00 in General Discussion
·I would like to use FOR and NEXT to run through four channels one at a time and only use these·two VAR over and over
How do I set this up
Can some give me an example of how you would do this




'   File...... ADC MCP3204 demo.bs2
'   Purpose... MCP3204 Demo
'   Author.... Technical Support -- Parallax, Inc.
'   E-mail.... [url=mailto:support@parallax.com]support@parallax.com[/url]
'   Started... 8/20/09
'   Updated... N/A
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'

[color=red]' This code is only part of the hole routine this...>>> The part I need help with is how to set up the FOR  NEXT...>>> I understand       ' how to select the channel you  BUT how do you SELECT ANY order which you want to see them in and you use the SAME VAR over again using   ' this routine[/color]

[color=blue]result0          VAR     Word                       ' Conversion Result CH0
mVolts0          VAR     Word                       ' Result0 --> mVolts[/color]

  DO
  LOW CS
  SHIFTOUT DataIn, Clock, MSBFIRST, [color=black][noparse][[/noparse] [color=red]%11000\5 [/color] ][/color]     ' Select CH0, Single-Ended
  SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse] [color=red]result0\13[/color] ]     ' Read ADC
  HIGH CS                                             ' Disable ADC
  mVolts0 = result0 */ Cnts2Mv                        ' Convert To Millivolts
 
  LOW CS                                              ' Enable ADC
  SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse] [color=red]%11001\5[/color]  ]     ' Select CH1, Single-Ended
  SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse] [color=red]result1\13[/color] ]     ' Read ADC
  HIGH CS                                             ' Disable ADC
  mVolts1 = result1 */ Cnts2Mv                        ' Convert To Millivolts
 
  LOW CS                                              ' Enable ADC
  SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse][color=red] %11010\5[/color]  ]     ' Select CH2, Single-Ended
  SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse] [color=red]result2\13[/color] ]     ' Read ADC
  HIGH CS                                             ' Disable ADC
  mVolts2 = result2 */ Cnts2Mv                        ' Convert To Millivolts
 
  LOW CS                                              ' Enable ADC
  SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse] [color=red] %11011\5[/color] ]     ' Select CH3, Single-Ended
  SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse] [color=red]result3\13[/color] ]     ' Read ADC
  HIGH CS                                             ' Disable ADC
  mVolts3 = result3 */ Cnts2Mv                        ' Convert To Millivolts

I could use this routine but

I can not select the order in which the channel are shown· This is the Problem that·I want to solve

·I know how control how many channel are shown·
' =========================================================================
'
'   File...... ADC MCP3208 demo.bs2
'   Purpose... MCP3208 Demo
'   Author.... Technical Support -- Parallax, Inc.
'   E-mail.... [url=mailto:support@parallax.com]support@parallax.com[/url]
'   Started... 8/20/09
'   Updated... N/A
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'

DO
  FOR channel = 0 TO 3
    GOSUB GetADC
    GOSUB DisplayADC
    PAUSE 20
  NEXT
LOOP
 
DEBUG CLS, "ADC CH 0 : ", CR, "Volts    :", CR,
           "ADC CH 1 : ", CR, "Volts    :", CR,
           "ADC CH 2 : ", CR, "Volts    :", CR,
           "ADC CH 3 : ", CR, "Volts    :", CR

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 10/31/2009 3:21:07 PM GMT

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2009-10-31 15:54
    You should be able to just leave the For > Next loop alone and either change the variable you put the ADC value into, or change the order that you read the ADC channels.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • RDL2004RDL2004 Posts: 2,554
    edited 2009-10-31 16:32
    Unless I misunderstood and what you really want is only two variables (one result and one mVolts}. If that's the case then you'll have to put the ADC reading and DEBUG commands inside the For>Next loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-31 19:04
    Rick

    Unless I misunderstood and what you really want is only two variables (one result and one mVolts}.

    No you did not misunderstand· what I want to because that is what I want to

    I did not think of doing it that way

    Thanks for the Help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-31 20:00
    ·Dose anyone see any reason why this should not work
    ·Do I have this right

    I do not have a· ADC MCP3204 right now to test I have a MAX188 but I do not have it hook up right now
    I just want to know if I have the right idea.gif·or not

    Feed back need
     DO
    Main:
    ADC = %11000   ' start with right ADC CH 0
    ADC = ADC >> 1 ' shift ADC INPUTs to the Right [color=red]Not sure if this need << to the left or not[/color]
     
    
      DEBUG HOME, CRSRXY, 11, 0, DEC  result, CLREOL,   ' Displays voltages & digital value
                  CRSRXY, 11, 1, DEC  mVolts DIG 3,     ' for all four channels
    
    
      LOW CS
      SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse]%11000\5 ]     ' Select CH0, Single-Ended
      SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse]result\13]      ' Read ADC
      HIGH CS                                           ' Disable ADC
      mVolts = result */ Cnts2Mv                        ' Convert To Millivolts
      DEBUG CLS, "ADC CH 0 : ", CR, "Volts    :", CR
     
      LOW CS                                           ' Enable ADC
      SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse]%11001\5]     ' Select CH1, Single-Ended
      SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse]result\13]     ' Read ADC
      HIGH CS                                          ' Disable ADC
      mVolts = result */ Cnts2Mv                       ' Convert To Millivolts
      DEBUG CLS, "ADC CH 1 : ", CR, "Volts    :", CR
     
      LOW CS                                           ' Enable ADC
      SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse]%11010\5]     ' Select CH2, Single-Ended
      SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse]result\13]     ' Read ADC
      HIGH CS                                          ' Disable ADC
      mVolts = result */ Cnts2Mv                       ' Convert To Millivolts
      DEBUG CLS, "ADC CH 2 : ", CR, "Volts    :", CR
     
      LOW CS                                           ' Enable ADC
      SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse]%11011\5]     ' Select CH3, Single-Ended
      SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse]result\13]     ' Read ADC
      HIGH CS                                          ' Disable ADC
      mVolts = result */ Cnts2Mv                       ' Convert To Millivolts
      DEBUG CLS, "ADC CH 3 : ", CR, "Volts    :", CR
     
                    
      PAUSE 100
     LOOP UNTIL ( ADC = %11011) ' test for last INPUT CH 3
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 10/31/2009 8:17:20 PM GMT
Sign In or Register to comment.