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

GPIO as analog input

gpio analog input analog

  • Please log in to reply
12 replies to this topic

#1 tomabecea

tomabecea

    New Member

  • Members
  • Pip
  • 5 posts

Posted 27 February 2013 - 10:34 AM

Hello,   I need to use gpio pins as analog inputs as follows:   using AnalogInput_SecretLabs = SecretLabs.NETMF.Hardware.AnalogInput;   AnalogInput_SecretLabs input1 = new AnalogInput_SecretLabs(Pins.GPIO_PIN_D2);   Pins D2, D3, D7, D8, D9 should be able to be used as analog inputs but at running time a System.ArgumentException is thrown.

 

Can pins D2, D3, D7, D8, D9 used as analog inputs ? If yes, how should the code be written ?

 

Thanks,

 

tomabecea



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 February 2013 - 10:43 AM

There are six pins Pins.GPIO_PIN_A0 to Pins.GPIO_PIN_A5 that can be used as analog inputs.



#3 tomabecea

tomabecea

    New Member

  • Members
  • Pip
  • 5 posts

Posted 27 February 2013 - 10:56 AM

Yes, there are and all of them works but I need more than 6 analog inputs. This is why I want (and try) to use GPIO pins.



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 27 February 2013 - 11:48 AM

short: doesent work.

 

solutions: multiplex your analog inputs (bad) or use external adc ic's over spi/i2c (spi prefeered, can use more)

 

in the link in  my signature is code for the MCP3201 ... its only one port, but easy to change for the 4 or 8 port versions



#5 mHammer

mHammer

    Member

  • Members
  • PipPip
  • 23 posts

Posted 27 February 2013 - 03:42 PM

With MUX (sorry) shield, Is the only down side that you have to constantly poll the input to check for new values?

For inputs would that really matter?

I know for outputs it would be different, because you would want a seamless stream of analog or digital control.



#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 05:52 AM

Hi tomabecea, The NETMF STM32 core only recognizes the 6 analog channels, but if you wanted to tweak the firmware you could access the analog feature of additional pins. Chris

#7 tomabecea

tomabecea

    New Member

  • Members
  • Pip
  • 5 posts

Posted 28 February 2013 - 06:10 AM

Noom:

It would be a bad solution to mutliplex or use external shield while STM32 core has already powerful capabilities.

 

mhzpower:

I'm afraid I'm not sure what your first phrase means, my english is not that good. If I correctly understood your question, yes, my inputs needs as much Samples/sec as it is possible. Currently we use 1kS/sec per channel but with other devices.

 

Chris Walker:

The STM32 core is capable to use more than those 6 analog pins. So I'm heading toward some tweaking, though I'm still confused about how this can be done. For example I start to look what IDE and C libraries STM offers.

If you have any clues or ideas which you can share with us about tweaking firmware, please let us know.

It would be great to combine ethernet with 8 analog inputs :)



#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 07:27 AM

Hi tomabacea, The code for STM32 ADCs in NETMF is located in: C:MicroFrameworkPK_v4_3DeviceCodeTargetsNativeSTM32DeviceCodeSTM32_AnalogSTM32_AD_functions.cpp It's set up to use a series of sequential pins...but you could change STM32_AD_CHANNELS to a greater number of pins and modify AD_GetPinForChannel to return the related pins you want to use. Chris

#9 mHammer

mHammer

    Member

  • Members
  • PipPip
  • 23 posts

Posted 28 February 2013 - 05:54 PM

tomabacea,

Sorry, I was meaning Mux Shield by Mayhew Labs.  I have this shield so I am curious what others think.

 

I'm just getting started with ND2+ so someone else might be able to comment on the maximum samples per second.  And feel free to correct me if I'm wrong.

 

The fastest you could sample on the Mux Shield, would be reading 3 inputs at one time.  The CD74HC4067 has a analog in rise time of 500ns, so that might limit your sampling to 2000 per second.



#10 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 28 February 2013 - 09:23 PM

Noom:

It would be a bad solution to mutliplex or use external shield while STM32 core has already powerful capabilities.

 

mhzpower:

I'm afraid I'm not sure what your first phrase means, my english is not that good. If I correctly understood your question, yes, my inputs needs as much Samples/sec as it is possible. Currently we use 1kS/sec per channel but with other devices.

 

Chris Walker:

The STM32 core is capable to use more than those 6 analog pins. So I'm heading toward some tweaking, though I'm still confused about how this can be done. For example I start to look what IDE and C libraries STM offers.

If you have any clues or ideas which you can share with us about tweaking firmware, please let us know.

It would be great to combine ethernet with 8 analog inputs :)

It absolutely would not be a bad idea to use external parts, regardless of the STM32's power! My projects use AD7714 24-bit ADCs. Each part gives you 5 pseudo-differential inputs, and since they're SPI, you can use as many parts as you want, provided you can wire into CS individually. I use a full 6-wire interface for my parts, which means that I would need 3 ports for each part, aside from the SPI. That means I could use 5 of these ADCs, giving me 25 channels, each with 24-bit resolution.

 

I can even use more if I multiplex my IO.

 

The STM32 can't touch that.



#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 11:08 PM

Another benefit of external ADCs is enhanced accuracy and, as Verdris noted, superior precision. On-MCU ADCs are very convenient, but they are usually by nature less accurate and can't offer the amazing precision that off-board ADCs can bring to your project. Chris

#12 tomabecea

tomabecea

    New Member

  • Members
  • Pip
  • 5 posts

Posted 01 March 2013 - 05:45 AM

Verdris,

 

This is a good idea, thanks for sharing.

Of course there are more other viable solutions (I can extend your idea) and talk about my current solution (64 channels, 16 bits ADC, single ended, etc) which are more powerful than STM32. What I'm following is to see how much of its power I can squeeze of it with keeping the combination between efficiency, ease of programming and reduced costs because the project I'm working on it (gas chromatography) must be implemented in many equipments.

 

Thanks.



#13 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 01 March 2013 - 07:24 PM

Verdris,

 

This is a good idea, thanks for sharing.

Of course there are more other viable solutions (I can extend your idea) and talk about my current solution (64 channels, 16 bits ADC, single ended, etc) which are more powerful than STM32. What I'm following is to see how much of its power I can squeeze of it with keeping the combination between efficiency, ease of programming and reduced costs because the project I'm working on it (gas chromatography) must be implemented in many equipments.

 

Thanks.

The neat thing about using multiple identical parts on the SPI bus is that your code can be crafted to make things easy. For example, I have a function that gets a reading from a specified channel. It's overloaded, so I can either get a single or integrated reading, I can set the PGA, and I can choose between fully differential or pseudodifferential sensors, all with a single function call. If I wanted to grab a 30-reading integration of channel 19 with gain of 8 and it's a pseudodifferential sensor, I can just call ReadChannel(19,30,false,8); and I'm done.







Also tagged with one or more of these keywords: gpio, analog input, analog

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.