Propeller activity board embedded adc
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
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
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
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
It looks to be an SPI device.
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.
http://learn.parallax.com/propeller-c-simple-circuits/measure-volts
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.
I missed this post. Thanks. This is probably why the output is different than expected.
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
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
Erlend