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

Measuring square wave frequency when it's an input

pwm square wave frequency measurement

  • Please log in to reply
7 replies to this topic

#1 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 05 February 2013 - 07:45 AM

We're thinking of using a TSL235R to measure irradiance in a variety of applications. It outputs a 50% duty cycle square wave whose frequency is indicative of light intensity.

 

How would I measure this with a Netduino? Are there any external ICs that could digitize this signal?



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 05 February 2013 - 08:52 AM

i dont think you can measure that kind of output with an netduino  (cos of the speed the pins are read)

 

but you could add an capacitor and measure the voltage - than calculate the light intensity from that

 

edit: that would only work if the duty cycle changes ofc :(



#3 cutlass

cutlass

    Advanced Member

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

Posted 05 February 2013 - 10:10 AM

The meaning of "Real Time" varies depending on the requirements. :)

IMHO, for a Netduino, "real time" is 1Hz (1 per second), or slower.  :)

 

The .NET Micro framework is not designed for "real time".

According to the book "Expert .NET Micro Framework", the .NET Micro Framework (at least for 2.x) only does interpreted code execution, it does not do JIT.  That mat have changed for 4.x, but I doubt it.

 

From

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

The CLR is fast; it performs at about 15,000 managed method calls per second at 27.6 MHz. (These results are based on the average method-call complexity developed for the SPOT watch application.)

 

 

Hmm, 27MHz results in an execution rate of ~15KHz.  Seems realistic for a fully interpreted framework.

BTW, even with the ~15KHz rate, don't forget that the framework can, at any time, suck up many many CPU cycles doing garbage collection.  So, again, .NET isn't designed for "real time" sampling by software control for anything faster than ~1->100Hz (in general you want an 5-10x faster sample/control rate, and I figure ~10+ instructions per loop).  Yea, people can optimize loops, and there will be faster ARM chips.  I'm giving "general reasonable" expectations for a novice/intermediate user. :)

 

IMHO, your best bet would be to use an Arduino Nano operating at 5V (because the sensor has a 5V output) (~$25 from Amazon).  Then, have the Arduino Nano convert the freq to some nice output that you can use.

 

One thing to be careful of is that the sensor that you picked has a 5Volt output.  Many microcontrollers and ICs use 3.3V.  Some have 5V tolerant inputs, many do not.  Same for FPGAs.

 

 

Good Luck!



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 05 February 2013 - 11:30 AM

just to add: when doing a simple framecounter i get around 1200 updates per second on the mini, and ~8000 on the stm32 versions

- but thats without any other code running



#5 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 05 February 2013 - 11:33 AM

You may want to look into using a Frequency to Voltage IC like the LM2907 or LM 2917. With the proper circuitry this will give your analog input a voltage level 0-3.3v that can be translated digitally based on your scale to 0-1023 (on the Netduino Plus) or 0-4096 (on Netduino Plus 2).



#6 cutlass

cutlass

    Advanced Member

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

Posted 05 February 2013 - 12:51 PM

just to add: when doing a simple framecounter i get around 1200 updates per second on the mini, and ~8000 on the stm32 versions

- but thats without any other code running

Opps, sorry, I should have added that for an ATmega328 (Arduino Nano), you'd want to use one of the internal counters. :)  You'd poll the counter at some interval, get the result, and then forward the result.  I would also do at least some sort of simple averaging (like the last four or eight samples).  I'm assuming that for the light application, a response time of 1/10 to 1 second would be fine.

 

If very a very fast response time is needed below ~1/10th to 1/100th of a second, then all of the delays (including something like a UART transmit delay), would need to be considered.

And, again, the .NET micro framework isn't meant to be a speed demon. :) IMHO, .NET Micro does what it was meant to do, and it does it surprisingly well. :)

 

Atmel App Note: AVR205: Frequency Measurement Made Easy with Atmel tinyAVR and Atmel megaAVR

http://www.atmel.com...ges/doc8365.pdf

 

ATmega328 doc:

http://www.atmel.com...ges/doc8161.pdf

 

 

IMHO, if you want something with a very fast response time, then use an FPGA.  I've done countless ;) counters/timers/etc in FPGAs. :)  And, with an FPGA, you can respond to within a cycle to any change.  Plus, tons of options for filtering and error checking.

That's another reason I like/love C#, it's similar to Verilog for FPGA.  So, I can switch between Verilog, C# for Windows, C# for a Micro, and keep my syntax and style "similar".  IMHO, before, doing hardware and doing "C with MFC" or VB6 was a PITA. :)

 

BTW:  My C program, written with MFC back in the mid 90's works great without any problems on Win8. :)  Yea, it was pretty "simple".  Regardless, it still works. Mainly because I used the basic MFC stuff and kept it simple. :)

 

Hence, one of the great things about using .NET - portability! In 5+ years, when a faster, better ARM and Netduino are available, it will be simple/trivial to port any user code. :)



#7 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 05 February 2013 - 02:30 PM

There's also this discussion around a similar project using cascading counters and a shiftregister to count pulses over time and the TSL235R is mentioned so you might find something useful in there:

 

http://forums.netdui...cy-measurement/



#8 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 05 February 2013 - 07:15 PM

You might also want to look at the ams/Taos TSL230BRD. It has the capability to scale both sensitivity
and frequency (divide by 1 to 100),

 

http://www.ams.com/e...s/Light-Sensors







Also tagged with one or more of these keywords: pwm, square wave, frequency, measurement

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.