Shop OBEX P1 Docs P2 Docs Learn Events
Propeller activity board embedded adc — Parallax Forums

Propeller activity board embedded adc

JkaneJkane Posts: 113
edited 2014-10-12 14:43 in Propeller 1
Hello,

I am trying to use the lm34 and the embedded adc of the propeller activity board, but I was wondering if there is a adc obex for the board, I see that the adc is attached to pins 18-21 (A0-A3), and also noticed that there was an issue about the embedded adc having some issues (Jessica wrote a voltage and noise test), I thought I could use the propBOE adc, but I think is mapped to different pins, anyway, before I start chasing other possible issues, I would like to start with the correct embedded obex adc for the activity board,

I would like to use the embedded rather than an ic, (at least for now)

thanks in advance.

Jeff

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-08 19:32
    Jkane wrote: »
    Hello,

    I am trying to use the lm34 and the embedded adc of the propeller activity board, but I was wondering if there is a adc obex for the board,

    I don't think you've got your terminology straight. It's kind of hard to understand what you're asking. The OBEX is the acronym for the Object Exchange. I assume you want to use the ADC IC on the Activity board. IIRC, the ADC chip is a MCP3204 and yes there are objects for this chip in the object exchange. (Edit: I didn't remember correctly.)

    Do you want to use C or Spin?
    Jkane wrote: »
    I see that the adc is attached to pins 18-21 (A0-A3)

    In case it's not clear, the I/O pins P18 - P21 are used to interface with the ADC chip. The connections A0-A3 connect to the ADC chip's input channels. A0-A3 do not directly connect with the Propeller chip.
    Jkane wrote: »
    , and also noticed that there was an issue about the embedded adc having some issues (Jessica wrote a voltage and noise test), I thought I could use the propBOE adc, but I think is mapped to different pins

    The Activity Board's ADC uses the SPI protocol however the PropBOE's chip uses the I2C protocol, so besides using different I/O pins, the protocols used by the chips are different.
    Jkane wrote: »
    , anyway, before I start chasing other possible issues, I would like to start with the correct embedded obex adc for the activity board,

    You've lost me here. I don't know what an "embedded obex adc" is. Do you want to make sure you're using the right object for the ADC chip used on the AB? Or are you looking for a library to use the ADC chip with C?
    Jkane wrote: »
    I would like to use the embedded rather than an ic, (at least for now)

    Again, I don't know what "embedded" means as you're using it here. The AB has an IC which is used for analog to digital conversions. I've guessing you'd like to use the IC included on the AB instead of adding an additional IC. I don't see why there would be a problem using the AB's MCP3204 chip but then I don't understand how you plan to use it with the LM34.

    Edit: I just looked up what the LM34 is. I see it outputs a voltage based on the temperature. I think the AB's ADC should be able to work just fine. I don't recall if the MCP3204 is powered by 5V or 3.3V. If the ADC is powered by 3.3V, I think you'll want to use a voltage divider between the LM34 and the ADC's inputs. I'll check on this and edit this post again.

    Edit again: I was wrong about the ADC chip. Apparently it's not a MCP3204 so I'm not so sure there's a object for it in the OBEX. It does look like the chip uses 5V so you won't need a voltage divider with your LM34. If you're using C, you can just use the library for the ADC chip but if you're using Spin, you'll need to find or write an object to interface with the chip (ACD124S021).
  • JkaneJkane Posts: 113
    edited 2014-10-09 05:33
    Duane Degn wrote: »
    I don't think you've got your terminology straight. It's kind of hard to understand what you're asking. The OBEX is the acronym for the Object Exchange. I assume you want to use the ADC IC on the Activity board. IIRC, the ADC chip is a MCP3204 and yes there are objects for this chip in the object exchange. (Edit: I didn't remember correctly.)

    Do you want to use C or Spin?



    In case it's not clear, the I/O pins P18 - P21 are used to interface with the ADC chip. The connections A0-A3 connect to the ADC chip's input channels. A0-A3 do not directly connect with the Propeller chip.



    The Activity Board's ADC uses the SPI protocol however the PropBOE's chip uses the I2C protocol, so besides using different I/O pins, the protocols used by the chips are different.



    You've lost me here. I don't know what an "embedded obex adc" is. Do you want to make sure you're using the right object for the ADC chip used on the AB? Or are you looking for a library to use the ADC chip with C?



    Again, I don't know what "embedded" means as you're using it here. The AB has an IC which is used for analog to digital conversions. I've guessing you'd like to use the IC included on the AB instead of adding an additional IC. I don't see why there would be a problem using the AB's MCP3204 chip but then I don't understand how you plan to use it with the LM34.

    Edit: I just looked up what the LM34 is. I see it outputs a voltage based on the temperature. I think the AB's ADC should be able to work just fine. I don't recall if the MCP3204 is powered by 5V or 3.3V. If the ADC is powered by 3.3V, I think you'll want to use a voltage divider between the LM34 and the ADC's inputs. I'll check on this and edit this post again.

    Edit again: I was wrong about the ADC chip. Apparently it's not a MCP3204 so I'm not so sure there's a object for it in the OBEX. It does look like the chip uses 5V so you won't need a voltage divider with your LM34. If you're using C, you can just use the library for the ADC chip but if you're using Spin, you'll need to find or write an object to interface with the chip (ACD124S021).

    I apologize for the confusion, but you gave me the answer " If you're using C, you can just use the library for the ADC chip but if you're using Spin, you'll need to find or write an object to interface with the chip (ACD124S021)."

    when I was referring to "embedded" I was referring to the adc chip on the propeller activity board, (ACD124S021), and my overall question was if there was spin/asm code to interface to the onboard ACD124S021 chip.

    so C or Spin, I guess C, I haven't used C on propeller yet, but was going to do it eventually, but on an side note, C is a very close representative of assembler, as far as performance is the C version for the Propeller equal to asm.

    option B would be to use MCP3204 ,MCP3208 or ADC8031

    regards

    Jeff
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-09 06:55
    I think I'm wrong about the ADC chip ID. I do some checking. I may have been right the first time and the chip is a MCP3204. If so, there are lots of Spin/PASM options.

    I think the "ADC124S021" ID I found on the schematic is some sort of internal part number. A search for this ID didn't turn up anything useful.

    I take it you want to read the voltage from the LM34 sensor. How often?

    I'll see if I can find some example code to use with the AB's ADC in Spin. I plan to post something within an hour.
  • PublisonPublison Posts: 12,366
    edited 2014-10-09 07:05
    Duane Degn wrote: »
    I think I'm wrong about the ADC chip ID. I do some checking. I may have been right the first time and the chip is a MCP3204. If so, there are lots of Spin/PASM options.

    I think the "ADC124S021" ID I found on the schematic is some sort of internal part number. A search for this ID didn't turn up anything useful.

    I take it you want to read the voltage from the LM34 sensor. How often?

    I'll see if I can find some example code to use with the AB's ADC in Spin. I plan to post something within an hour.

    From the Bill of Materials:

    ADC124S021CIMM/NOPBCT-ND (Digikey Part Number)

    Data Sheet:

    http://www.ti.com/lit/ds/symlink/adc124s021.pdf


    I
    t looks to be an SPI device.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-09 07:09
    Jeff,

    The first couple of ADC objects I examined won't work with the AB as they are currently written. I'll either need to modify one of find a different version. I'm still working on this, it's just taking a little longer than I expected.
  • PublisonPublison Posts: 12,366
    edited 2014-10-09 07:12
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-09 08:14
    Publison wrote: »

    Thanks but I was trying to find a Spin example.

    JonnyMac's object in the OBEX share the data in and data out lines.

    It was pretty easy to modify it to separate the lines.

    I've attached the modified code.

    Here's the example output from running the code on the AB:
    
    
    0:  2784     67
    1:     8      0
    2:  1520     37
    3:  4088     99
    

    There is something strange going on though. The channel numbers don't match the number on the AB. Channel zero is displaying the value read from input #4. All the channels appear to be shifted one position.

    I don't understand why this is the case. This certainly would be an easy thing to compensate for but it's kind of puzzling.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-09 08:15
    Publison wrote: »
    From the Bill of Materials:

    ADC124S021CIMM/NOPBCT-ND (Digikey Part Number)

    Data Sheet:

    http://www.ti.com/lit/ds/symlink/adc124s021.pdf


    I
    t looks to be an SPI device.

    I missed this post. Thanks. This is probably why the output is different than expected.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-10-10 00:25
    I was wondering if there is a adc obex for the board


    Yes, and I just updated my object for project that involves the PAB.

    -- http://obex.parallax.com/object/694
  • JkaneJkane Posts: 113
    edited 2014-10-10 04:46
    JonnyMac wrote: »
    Yes, and I just updated my object for project that involves the PAB.

    -- http://obex.parallax.com/object/694

    Jon,

    Thanks, I currently went the route of the MCP3208, which is working but overkill, I will convert it back today and retest it.

    but on a side note: regarding the MCP3208 connected to a LM34 temp sensor. I used the OBEX for the MCP3208, which works but had to place a 100K OHM resister between the output of the LM34 and the ADC channel one, then I recalibrated back, Using spin code to the correct temp, but I believe this is not correct. (or not the right way to do it)


    This is the connections for the MCP3208


    Input from sensor Ch(0) | | Vdd - 3.3 volts
    | V ref - 3.3 volts
    | Agnd - Ground
    | Clk - to propeller Pin 5
    | D out - to propleller Pin 6
    | D in (tied to D out
    | CS to propeller Pin 7

    LM34 TO-92 package (looking from the bottom up, flat side on the top)
    Pin 1 - 5.0 volt
    Pin 2 - signal to propeller => thru 100K ohm resister => Ch(0) of the ADC chip
    Pin 3 - ground

    Here is the spin code
    {{
    File: MCP3208_DEMO.spin
    Author: Mike Rector, KF4IXM
    Version: 1.0
    Copyright (c) Mike Rector, KF4IXM
    See end of file for Terms of Use.
    }}
    {{
    This demo demonstrates the Microchip MCP3208 8 channel adc chip connected to the Parallax
    Propeller Demo Board. It uses the MCP3208.spin object Written by Chip Gracey and outputs the adc
    value (0-4096) of all 8 channels (labeled as 0-7) in Parallax Serial Terminal.
    The Datasheet of the MCP3208 can be found here:
    [URL]http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf[/URL]
    Connect both AGnd (pin 14) and DGnd (pin 9) of the MCP3208 to the Vss of the demo board.
    
    }}
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
    OBJ
    adc     : "MCP3208"
    pc     : "Parallax Serial Terminal"
    fmath :       "FloatMath"
    fs    :       "FloatString"
    SER  : "TFDS2"    
    CON
    dpin = 6       'both din and dout of the mcp3208 are connected to this pin on the prop demo board.
    cpin = 7       'the clock pin of the mcp3208 is connected to this pin on the prop demo board.
    spin = 5       'the chip select pin of the mcp 3208 is connected to this pin on the prop demo board.
     [B]F_ADC_1TICK1   = 5.0/3330.0   '1024                         'the voltage value of a single ADC tick =(MAX_VOLTS - MIN_VOLTS)/RANGE
     F_ADC_1TICK2   = 5.0/3650.0  '1024                         'the voltage value of a single ADC tick =(MAX_VOLTS - MIN_VOLTS)/RANGE
    [/B] F_LM34_RES    = 0.01                                  '.01 volts per degree F, resolution of the sensor
     TXS_PIN        = 3     'serial out to hp diag program
    pub go  | rawReading1, rawReading2, fSample1 , fSample2   
    pc.start(115200)   'Start the Parallax Serial Terminal object at 115200 baud
    adc.start(dpin, cpin, spin, 255)  'Start the MCP3208 object and enable all 8 channels as
                                      'single-ended inputs.
    SER.start(TXS_PIN, TXS_PIN, %0000, 57_600)                                    
    '    dpin  = pin connected to both DIN and DOUT (pin11 on MCP3208)  P7
    ''   cpin  = pin connected to CLK on MCP3208    (pin12 on MCP3208)  P6
    ''   spin  = pin connected to CS on MCP3208     (pin 9 on MCP3208)  P5
     fs.SetPrecision(2)   
    repeat
        rawReading1 := adc.In(0)                             'Read Channel 0 of the ADC
        fSample1 := fmath.FFloat(rawReading1)                 'Convert the reading into IEEE 754 single precision floating point notation
        fSample1 := fmath.FMul(fSample1, F_ADC_1TICK1)         'Do a floating point multiply (adc reading * the voltage value of a single ADC tick)
        fSample1 := fmath.FDiv(fSample1, F_LM34_RES)          'Do a floating point divide (the voltage supplied by the sensor / the resolution per degree)
        rawReading2 := adc.In(1)                             'Read Channel 1 of the ADC
        fSample2 := fmath.FFloat(rawReading2)                 'Convert the reading into IEEE 754 single precision floating point notation
        fSample2 := fmath.FMul(fSample2, F_ADC_1TICK2)         'Do a floating point multiply (adc reading * the voltage value of a single ADC tick)
        fSample2 := fmath.FDiv(fSample2, F_LM34_RES)          'Do a floating point divide (the voltage supplied by the sensor / the resolution
        '================= Print the calculated data to the serial terminal ==================
      
        pc.Home
        pc.Str(string("=== LM34 Temperature Sensor Test 1 ==="))
        pc.NewLine
        pc.NewLine
        pc.Str(string("Raw ADC Reading: Sensor 1 "))
        pc.Dec(rawReading1)
        pc.Chars(" ", 5)
        pc.NewLine
        pc.Str(string("Raw ADC Reading: Sensor 2 "))
        pc.Dec(rawReading2)
        pc.Chars(" ", 5)
        pc.NewLine
        pc.Str(string("Calculated Temperature: Sensor 1 "))
        pc.Str(fs.FloatToString(fSample1))                   'Since a floating point number is not represented the same as a decimal number,
                                                                'we have to convert it to a string to be displayed.
        pc.Char(" ")
        pc.Char("F")                                        'Add the Fahrenheit unit notation.
        pc.Chars(" ", 5)
        pc.NewLine
        pc.Str(string("Calculated Temperature: Sensor 2 "))
        pc.Str(fs.FloatToString(fSample2))                   'Since a floating point number is not represented the same as a decimal number,
        pc.Char(" ")
        pc.Char("F")                                        'Add the Fahrenheit unit notation.
        pc.Chars(" ", 5)
        pc.NewLine
        
        ser.str(string("Sen:1 F: "))
        ser.Str(fs.FloatToString(fSample1))
        ser.tx(10)
        ser.str(string("Sen:2 F: "))
        ser.Str(fs.FloatToString(fSample2))
        ser.tx(10)
        
        waitcnt(cnt + clkfreq*1)   
    
    

    anyway, I think I'm going to go back to the onboard ADC chip of the activity board to recheck.

    regards

    Jeff
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-10-10 08:46
    FWIW, you may be unnecesarrily complicating things with the floating point library. With a 12-bit (0..4095) you can used fixed point math without problems. Here's an update to my ADC demo for the PAB that prints the voltage on channels to 0.01v resolution.
    t := cnt
      repeat
        repeat ch from 0 to 3                                       ' loop through channels
          counts := adc.read(ch)                                    ' read adc    
          volts := 5_00 * counts / 4095                             ' convert to volts * 100
    
          term.tx(term#GOTOXY)                                      ' position cursor for channel
          term.tx(0)
          term.tx(ch + 2)
          term.tx(ch + "0")                                         ' display channel
          term.str(string(" : "))                                   ' spacer
          term.rjdec(counts, 4, " ")                                ' channel counts
          term.rjdec(volts/100, 4, " ")                             ' volts 1.0s
          term.tx(".")                                              ' dpoint
          term.rjdec(volts//100, 2, "0")                            ' volts 0.01s                              
           
        waitcnt(t += constant(100 * MS_001))                        ' update every 100ms
    


    If you use a 3.3v reference (e.g., with the MCP3208) you could change millivolts resolution with:
    volts := 3_300 * counts / 4095
    
  • ErlendErlend Posts: 612
    edited 2014-10-12 13:56
    The LM34 gives 0-5V output, but maximum input to the MCP - if you run it at 3.3V - is 3.3V. So, you have to run the signal from the LM34 through a voltage divider to make sure the voltage is reduced down to maximum 3.3V. What a voltage divider in this instance is, is simply two resistors, R1 and R2, the first (R1) in series with the signal as you have done, the second (R2) then connecting the signal to ground. If R1+R2=5k, and R2=3k3, the division would be perfect (do you recognise the ratio: 5:3.3?), and would mean R1 have to be (5-3.3=) 1k7. It can be a bit difficult to find a perfect set of standard resistor values, but say in this example you choose R1= 1k8 ( standard) the division would still be almost perfect. It would work as well with 33k and 18k, but I think if you go up as high as 100k you could get some strange effects.

    Erlend
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-10-12 14:43
    The Activity Board's ADC is powered with 5V and has an input range between 0V and 5V.
Sign In or Register to comment.