Shop OBEX P1 Docs P2 Docs Learn Events
ADC0808 and propeller — Parallax Forums

ADC0808 and propeller

Scott LewisScott Lewis Posts: 18
edited 2008-12-11 23:11 in Propeller 1
I didn't find any programs for this chip, so I wrote my own. I am new to writing programs for propeller, so I probably did a bunch of stuff not the best way [noparse];)[/noparse].

A little about the program, it uses it's own cog to take conversions constantly. I got about a 9 kHz sample rate in the lab, which is close to the 10 kHz from the datasheet.

I would appreciate feedback about improving my program to make it faster and more efficient. I know I could have used a loop but I needed to do special stuff for input 0, and I had trouble getting it to work with a loop, grr I hate programming, I'm EE not CPE [noparse]:([/noparse]. Here is the program and the datasheet for the 0808

Comments

  • Scott LewisScott Lewis Posts: 18
    edited 2008-12-11 03:35
    bump, would like some feedback
  • TJHJTJHJ Posts: 243
    edited 2008-12-11 05:21
    I've ordered one to give it a try, but just glancing over the code, the only suggestion is to change to the data routine so that you don't have dump extra bytes into the get routine if you are not using all the channels.

    Recently I learned that routine passing sucks up stack space, and in a stack limited program, passing 8 variables plus the routine jump for 3, could be hard on it.

    My suggestions feel free to ignore.

    VAR
      byte data[noparse][[/noparse]8]
      byte cog
      long stack[noparse][[/noparse]32]        
    
    
    PUB get(Channel)
    {{Returns the data of the data channel requested.  Channels 0 - 7}}
      return data[noparse][[/noparse]channel]
    
    PRI convert
    {{makes conversions as fast as possible and stores 8 bit result in data}}
    
      dira[noparse][[/noparse]CMUXC..AMUXA]~~                      'pin I/O declarations
      dira[noparse][[/noparse]ALE]~~
      dira[noparse][[/noparse]START]~~
      dira[noparse][[/noparse]OE]~~
      dira[noparse][[/noparse]EOC]~
      outa[noparse][[/noparse]14]~                                 'Pin 14 is the peak detector clear
      dira[noparse][[/noparse]14]~
      outa[noparse][[/noparse]OE]~~                                'Data pins not used for anything else so OE can stay high
    
      ctra[noparse][[/noparse]30..26] := %00100                    'Configure Counter A to PWM
      ctra[noparse][[/noparse]8..0] := START
      frqa := 1
    
      ctrb[noparse][[/noparse]30..26] := %00100                    'Configure Counter B to PWM
      ctrb[noparse][[/noparse]8..0] := ALE
      frqb := 1
    
      repeat                                    'infinite loop
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 0               'set input to 0
          phsb := $FFFFFFB0                     'ALE go high for 1us
          phsa := $FFFFFFB0                     'START go high for 1us
          repeat until ina[noparse][[/noparse]EOC]                 'wait for EOC to go high
          data[noparse][[/noparse]0] := ina[noparse][[/noparse]D7..D0]                  'read data
          dira[noparse][[/noparse]14]~~                            'clear charge on peak detector - unique to this input
          dira[noparse][[/noparse]14]~
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 1               'repeat above for input 1
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 2               'repeat above for input 2
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 3               'repeat above for input 3
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 4               'repeat above for input 4
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 5               'repeat above for input 5
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 6               'repeat above for input 6
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data[noparse][[/noparse]6] := ina[noparse][[/noparse]D7..D0]
    
          outa[noparse][[/noparse]CMUXC..AMUXA] := 7               'repeat above for input 7
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data[noparse][[/noparse]7] := ina[noparse][[/noparse]D7..D0]
    
    
                                            
    
    



    Although it probably would be better to just have it get and return that data for that selected channel, so it can be read as needed, and doesnt suck up a cog.

    THE FOLLOWING NEEDS TOUCH UP. Just a suggestions for a code process, the downside of this is we reset the counters every time, taking up conversion time....
    Var
      byte data
      byte cog
      long stack[noparse][[/noparse]32] 
          
    Pub start : success
    
    
    {{Starts new converting process on a new cog
    
    Parameters:
      input - which analog input to take conversions of
    }}
      stop
      cog := cognew(convert,@stack) + 1
      success := cog  
    
      dira[noparse][[/noparse]CMUXC..AMUXA]~~                      'pin I/O declarations
      dira[noparse][[/noparse]ALE]~~
      dira[noparse][[/noparse]START]~~
      dira[noparse][[/noparse]OE]~~
      dira[noparse][[/noparse]EOC]~
      outa[noparse][[/noparse]14]~                                 'Pin 14 is the peak detector clear
      dira[noparse][[/noparse]14]~
      outa[noparse][[/noparse]OE]~~                                'Data pins not used for anything else so OE can stay high
    
    
    
    Pub GetChannel(Channel)
    'Valid values are 0 - 7
    
      ctra[noparse][[/noparse]30..26] := %00100                    'Configure Counter A to PWM
      ctra[noparse][[/noparse]8..0] := START
      frqa := 1
    
      ctrb[noparse][[/noparse]30..26] := %00100                    'Configure Counter B to PWM
      ctrb[noparse][[/noparse]8..0] := ALE
      frqb := 1
     
        outa[noparse][[/noparse]CMUXC..AMUXA] := channel               '
          phsb := $FFFFFFB0
          phsa := $FFFFFFB0
          repeat until ina[noparse][[/noparse]EOC]
          data:= ina[noparse][[/noparse]D7..D0]
    
    return data
    
    
    



    Also maybe an example connection diagram to the prop for the default connections.

    I don't have the chip in hand, so you'll have to check and debug these, I just reordered you code, and hope it works correctly [noparse]:)[/noparse].

    TJ

    Post Edited (TJHJ) : 12/11/2008 5:31:18 AM GMT
  • Scott LewisScott Lewis Posts: 18
    edited 2008-12-11 06:36
    wow thanks, I wasn't expecting anyone to order the chip just to test out my program, just some pointers on how to improve it. Thanks for the input on passing parameters back and forth, I might come up with something tricky to minimize that. Here is the connection diagram that I used:
  • SapiehaSapieha Posts: 2,964
    edited 2008-12-11 13:18
    Hi Scott Lewis

    In Yours diagram I can't see resistors betwen ADC and Prop.
    You must have resistors to protect Props I/O pins

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • pmrobertpmrobert Posts: 673
    edited 2008-12-11 19:29
    I ordered samples of the ADC0816 and ADC0808 parts. It doesn't look like it's too terribly difficult to extend your basic driver code to handle the 16 channel part. I think the main hardware change would be the addition of a fourth address line. Comments?
  • Scott LewisScott Lewis Posts: 18
    edited 2008-12-11 20:41
    I think to save I/O pins on the address lines, a counter can be used, so the prop only has to send pulses to the counter, which increments the address lines.

    Why do I need resistors to protect the I/O pins? It is all CMOS circuitry and no current flows.
  • TJHJTJHJ Posts: 243
    edited 2008-12-11 21:11
    If I read the data sheet correctly it states that logic high 4.5V, which is right on the damage threshold for the propeller pins. Being 3.3v inputs, the standard approach is to place a 1k resistor in line with the input pin to knock down the voltage to an acceptable level, and prevent it from damaging the input pin. Just seems to be an addopted standard pratice for interfacing anything that·runs at 5v logic levels.

    TJ
  • pmrobertpmrobert Posts: 673
    edited 2008-12-11 23:11
    For the 0816 part, wouldn't we need a DMUXD line? My apologies for being unclear on the "address line" statement in my message. If I'm missing something on the mux addressing concept, please help me understand.

    -Mike
Sign In or Register to comment.