Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

12-Bit ADC Measurement using MCP320X chips and SPI


  • Please log in to reply
8 replies to this topic

#1 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 27 November 2010 - 12:07 PM

The Microchip MCP3202, MCP3204 and MCP3208 can provide 12-bit ADC readings to your Netduino using the SPI communication pins (3), plus a fourth digital output for a chip select line. The attached project file demonstrates the use of these chips to take temperature readings from a couple LM34 temperature sensors on channel 0 and 7 of a MCP3208.

Basic usage of the MCP320X class is as follows:


    // 8 channels. Uses default clock rate & CS pin. Other constructors are provided as well.
    MCP320X myChip = new MCP320X(8);  
    // Read the ADC measurement for channel 0
    ushort myReading = myChip.ReadADC(0);

[edit]The ZIP file was replaced 2010-11-28 to accomodate the MCP3202 chip. The command structure is slightly different, and the example class should handled 3202, 3204 and 3208 chips now.[/edit]

Attached Files



#2 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 27 November 2010 - 02:19 PM

Thanks for this, I have been playing with an MCP3204 -- i was wondering the "proper" way to combine the two bytes into the reading.. bitwise operators have always been mysterious to me. I got it working but my solution does not look nearly as smart as yours...

I have been having a ton of problems getting decent, stable readings, though. Do you have any sample circuits and pictures you could post?

Here are some premade boards i've been thinking about:
http://www.mikroe.co.../easyadc-board/
http://www.mikroe.co...dc-proto-board/

Posted Image

#3 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 28 November 2010 - 12:03 PM

Getting stable 12 bit readings is definitely a trick, and I am no signal conditioning expert. I know the MCP320X datasheets have a number of example circuits in them, but I haven't spent alot of time analyzing and trying them out - I would likely go with a commercial solution myself, to be honest. To somewhat compensate for this, you'll notice I have a couple of optional paramters in the ReadADC method, one of them being number of samples. This is an admittedly poor way to somewhat stablize the readings by taking more than 1 and averaging them together. In my day job I deal alot with statistics, so this is how I typically and practically compensate for variation on a daily basis... But I'm sure there are plenty of good hardware methods of doing the same. Best regards!

#4 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 28 November 2010 - 01:58 PM

I just read the datasheet for the MCP3202. Looks like the bit streams are different than the 3204/8, so I'll have to do a little testing and post a revised class that works for the 3202.

#5 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 28 November 2010 - 02:33 PM

If you don't mind me asking, what kind of project are you working on?

#6 GDSever

GDSever

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts
  • LocationNewark, DE

Posted 28 November 2010 - 04:57 PM

If you don't mind me asking, what kind of project are you working on?


My projects typically center around needless technological add-ons to my homebrewing gear (beer). I have tons of pressure and temperature sensors as well as switches, and I'm moving away from my previous embedded development platform to the Netduino, so that means re-developing alot of the libraries I had already in C# (and hopefully VB, once the Netduino supports it).

My current focus is replacing my hard-wired grant with a wireless (Xbee) solution using the Xbee API - something that is very easy to do on the Netduino but would have been near impossible on the previous platform.

Check out my blog if you are interested - link should be in my user profile.

Oh - I also replaced the ZIP file in the first post with a newer version that also supports the MCP3202, if you are interested. Best regards,

#7 marcelvdk

marcelvdk

    New Member

  • Members
  • Pip
  • 2 posts

Posted 04 February 2011 - 08:51 AM

Him I've read this post with interest. At this momement i'm testing a 16 bit ADC (ADS8320 from TI). I am trying to figure out your code to adapt it for this ADC. Can you give me some input about what parts to adapt so that i get a good 16 bit readout? I'm new to programming in C#. I've tested it on an arduino and a Mbed and it seems to work oke. The samplerate will be 20Kz in the project i'm doing. Is that a problem for the Netduino? with kind regards, Marcel

#8 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 04 February 2011 - 01:01 PM

The samplerate will be 20Kz in the project i'm doing. Is that a problem for the Netduino?

20k Hz might be a bit much for netmf. You'd most likely have to implement a native driver at least. (I'm sampling at 25k Hz in native code though.)

#9 marcelvdk

marcelvdk

    New Member

  • Members
  • Pip
  • 2 posts

Posted 07 February 2011 - 07:37 AM

20k Hz might be a bit much for netmf. You'd most likely have to implement a native driver at least. (I'm sampling at 25k Hz in native code though.)


Mmmmm , native driver, i guess i'm out of my league here. Can you give me a starting point /direction?

greets,

Marcel




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.