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

Setting Interrupt for Analog Input


Best Answer cutlass, 02 May 2013 - 04:43 AM

In general, you would never see that type of functionality in an ADC.  If you look at my ADC examples, it becomes clear why that is the case.

Pretty much, all ADCs have "noise".  For an ADC on a SOC, there is often a good deal of noise, and the linearity also suffers.

So, there would always have to be some "intelligence" to look for "some range" of value change.  It could be an FPGA, micro-controller, an i7 desktop PC sucking down 400watts of power, etc. :)

 

Good Luck.

Go to the full post


  • Please log in to reply
8 replies to this topic

#1 xmakina

xmakina

    Member

  • Members
  • PipPip
  • 13 posts

Posted 01 May 2013 - 10:09 AM

Hi Guys,

 

Can you help me on how to setup an interrupt for an analog input port, say Pins.GPIO_A0 ? I want to have an event handler that is triggered when the analog input voltage changes. Is this possible with my NDP2 ?

 

Thanks in advance,

 

xMakina



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 May 2013 - 01:37 AM

Hi xMakina, AnalogInputs only measure voltage when you call their .Read() function. If you wanted, you could create an AnalogInterrupt class that woke up a few times every second to measure the voltage...and then raised an event whenever the voltage changed a certain number of millivolts. Chris

#3 cutlass

cutlass

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationNew England. :)

Posted 02 May 2013 - 04:43 AM   Best Answer

In general, you would never see that type of functionality in an ADC.  If you look at my ADC examples, it becomes clear why that is the case.

Pretty much, all ADCs have "noise".  For an ADC on a SOC, there is often a good deal of noise, and the linearity also suffers.

So, there would always have to be some "intelligence" to look for "some range" of value change.  It could be an FPGA, micro-controller, an i7 desktop PC sucking down 400watts of power, etc. :)

 

Good Luck.



#4 cutlass

cutlass

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationNew England. :)

Posted 02 May 2013 - 04:45 AM

FYI:

 

Analog Input Example on the Netduino Plus and Netduino Plus 2

http://forums.netdui...etduino-plus-2/



#5 xmakina

xmakina

    Member

  • Members
  • PipPip
  • 13 posts

Posted 02 May 2013 - 01:46 PM

Thank you so much Chris and Cutlass. These are very informative. :)



#6 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 03 May 2013 - 11:54 PM

In general, you would never see that type of functionality in an ADC.  If you look at my ADC examples, it becomes clear why that is the case.

Pretty much, all ADCs have "noise".....

actually, that functionality does exist on the ST processors.  I just stumbled across it and remembered this post, and so wanted to record for posterity.  Mind you I don't think it is exposed via dotNETMF, so it won't help you there, but nonetheless.  If your curious, q.v:

 

http://www.st.com/st.../CD00225773.pdf

section 10.3.7

 

the noise problem cutlass referrs to is real, of course.  ST lets you to cope allowing you to specify a band of voltage change, rather than a single.threshold.



#7 cutlass

cutlass

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationNew England. :)

Posted 04 May 2013 - 02:41 AM

actually, that functionality does exist on the ST processors.  I just stumbled across it and remembered this post, and so wanted to record for posterity.  Mind you I don't think it is exposed via dotNETMF, so it won't help you there, but nonetheless.  If your curious, q.v:

 

http://www.st.com/st.../CD00225773.pdf

section 10.3.7

 

the noise problem cutlass referrs to is real, of course.  ST lets you to cope allowing you to specify a band of voltage change, rather than a single.threshold.

 

 

10.3.7 Analog watchdog
The AWD analog watchdog status bit is set if the analog voltage converted by the ADC is below a lower threshold or above a higher threshold. These thresholds are programmed in the 12 least significant bits of the ADC_HTR and ADC_LTR 16-bit registers. An interrupt can be enabled by using the AWDIE bit in the ADC_CR1 register.  The threshold value is independent of the alignment selected by the ALIGN bit in the ADC_CR2 register. The analog voltage is compared to the lower and higher thresholds before alignment.

Table33 shows how the ADC_CR1 register should be configured to enable the analog watchdog on one or more channels.

 

 

That function checks to see if the analog input is above or below specific programmed values.  That's not exactly what the original poster asked for.

But :), knowing the ADC noise factor, and knowing the current value, a big enough high and low value could be programmed in.  Then, after an "ADC value change" interrupt, the guard band values could be updated.

So, with that feature, and some interrupt handling code, the function that the original poster asked for could be implemented.  VERY NEAT!

 

Great find ziggurat29!

 

 

 

BTW, does anyone if there is a way we can read/write physical addresses directly in C# code with this .NETMF version? 

IIRC, with C# and Windows, you use "unsafe" code.

http://msdn.microsof...y/tcy5wf0h.aspx

http://www.c-sharpco...UnsafeCode.aspx



#8 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 04 May 2013 - 05:14 PM

I have used unsafe in netduino in a very limited way to bitfiddle value types, however if I do anything more sophisticated, the CLR locks up so tight that I have to go into DFU mode to erase the deployment block.  Like this will lock it up:  

static uint ReadAt(uint addr){    //let us see if indeed there is any safety in numbers    uint number = 0;    unsafe    {        //here's some well known data at a well known address        //08000000 <EntryPoint>:        // 8000000:    e00c          b.n    800001c <Start>        // 8000002:    2000          .short    0x2000        number = *((uint*)&addr);    //this works perfectly fine, but is not interesting of course        uint* p1 = &addr;            //this will make netduino lock up so tight you need to go into                                    //  DFU mode to erase the deployment area.  mind you, you won't                                    //  even be able to step into the "uint number = 0;" line above.        number = *((uint*)addr);    //this works but doesn't return what you expect    }    return number;}

so possibly not possible.



#9 cutlass

cutlass

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts
  • LocationNew England. :)

Posted 04 May 2013 - 07:55 PM

I have used unsafe in netduino in a very limited way to bitfiddle value types, however if I do anything more sophisticated, the CLR locks up so tight that I have to go into DFU mode to erase the deployment block.  Like this will lock it up:

 

Thanks for the info!

 

My guess is that it's possible to do with a subroutine in an unmanaged subroutine.  However, it would take some time and effort to learn and write unmanaged code for the netduino.

 

Thanks again ziggurat29!






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.