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

Timing Accuracy


  • Please log in to reply
9 replies to this topic

#1 wjousts

wjousts

    Member

  • Members
  • PipPip
  • 22 posts

Posted 28 July 2011 - 06:19 PM

I've only just now discovered Netduino and I'm wondering if it can do accurate timings? What I need to do is create a device that can switch something on (a relay, for example) for a fixed period of time and turn it off again with good accuracy. The period might be as low as 10 ms. Prior to this I've used a relay board controlled via a serial port, but then all the timing has to be done on the PC side which isn't very reliable. The .NET timers won't do anything less than about 15 ms and are prone to being interrupted by whatever else the PC might be running. I was thinking about looking into learning how to program a microcontroller to do the job, but now looking a Netduino, it looks like it might be a much easier path using skills I already have (C# and .NET) instead of wading through using C or assembler and a bunch of mucking around with USB. My idea would be to have a device where I can programmatically tell it (from the PC) that I want a 10 ms pulse. It will then turn on the appropriate digital output for 10 ms and turn it off again. The start time is less important than the duration and shouldn't be too much of a concern unless it's wildly inconsistent. Then I could tell it to do another pulse for, say, 30 ms, etc. So, might a Netduino board do the job? Is it possible to get it to do accurate timings?

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 July 2011 - 03:50 AM

Wjousts, welcome in the forum. This question is one of the most discussed. The timings on Netduino as slightly better than a PC, but the problems are substantially the same. C# is a language designed to work in a managed environment, thus the garbage collector (GC) has to do its work periodically. That leads to a unpredictable delays, in any context. Supposing that your Netduino has to do *only* those pulses and nothing else, probably the GC won't steal so much time. So maybe you may reach the precision you're expecting. However, bear in mind that the Micro Framework (and the .Net in general) is *NOT* a real-time platform. Cheers
Biggest fault of Netduino? It runs by electricity.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 July 2011 - 06:41 AM

...that I want a 10 ms pulse. ... Then I could tell it to do another pulse for, say, 30 ms, etc.

A simple circuit with 555 timer working in monostable mode should easily fit your needs. For more advanced logic or if the PC is not able to trigger it directly, you could use Netduino to control the 555 timer(s).

The .NET timers won't do anything less than about 15 ms and are prone to being interrupted

Just out of curiosity, have you tried Multimedia Timers?

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 29 July 2011 - 06:56 AM

Agree with CW2 at all. However it depends on what you are going to do.
Biggest fault of Netduino? It runs by electricity.

#5 wjousts

wjousts

    Member

  • Members
  • PipPip
  • 22 posts

Posted 01 August 2011 - 03:41 PM

A simple circuit with 555 timer working in monostable mode should easily fit your needs. For more advanced logic or if the PC is not able to trigger it directly, you could use Netduino to control the 555 timer(s).


So, out of curiosity, how might you go about that? A 555 timer in monostable mode is controlled by the RC network attached to it. I would need to be able to vary the R and/or C in order to change the pulse width on the fly. I could imagine using the digital outputs of the Netduino as a switch to connect / disconnect several different RC networks to the 555 giving some number of pre-defined pulse widths, but is there a solution that could allow me to dial up any arbitrary pulse width?

#6 wjousts

wjousts

    Member

  • Members
  • PipPip
  • 22 posts

Posted 01 August 2011 - 09:08 PM

Thinking about this some more....
Initially I thought I could use resistors in series to program a 555 timer with the Netduino controlling which resistors are included in the series. I could have say 1K, 2K, 4K and 8K and by including various combinations of resistors I could have 15 different resistances giving 15 different pulse widths. My problem with this is that a simple switch (e.g. SCR, SCS or some type of transistor) wouldn't work. I need something equivalent to a SPDT switch because I need to bypass the unused resistors.
So then I though it would be easier to use the capacitors in parallel instead. Same deal, 4 different capacitors giving 15 different total capacitance values. The problem here is finding capacitors with big enough values and tight enough tolerances. The capacitors with good tolerances have low capacitance which then would require a huge resistor to give a useful pulse width.
Then I decided that this was all too complicated, and started look for something more integrated. I came across this:
82C54 CMOS Programmable Intervel Timer
If I'm reading this correctly, this might do the job. I could use the Netduino to program the 82C54 and it will fire off a single pulse (in mode 1) at some multiple of the clock signal. I would just have to find an appropriate clock source (a crystal perhaps?).
Any thoughts from the experts out there?

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 August 2011 - 04:11 AM

At this point the 555 is not convenient, because you should switch several resistor with a transitor or similar. The circuit is not particularly difficult, but it is not linear. Then you must select the exact value of any resistor, finally write a function in C# that maps the time in the relative resistor switches. IMHO, the task is not worth. The 82C54 is nice (supposing you're able to find somewhere), but it has a parallel access. It's designed to interface with microprocessors, and not with microcontrollers. That makes hard to exchange data with it, very hard. You need tons of I/O and the time to set them: the setting procedure could take more than 10ms! I'd have a decent solution, but I need some parameter from you. Which is the minimum time you need? Which is the maximum error on the time? If I understand well, you are going to create some pulse-sequences on/off: is it true? Cheers
Biggest fault of Netduino? It runs by electricity.

#8 wjousts

wjousts

    Member

  • Members
  • PipPip
  • 22 posts

Posted 02 August 2011 - 12:49 PM

At this point the 555 is not convenient, because you should switch several resistor with a transitor or similar. The circuit is not particularly difficult, but it is not linear. Then you must select the exact value of any resistor, finally write a function in C# that maps the time in the relative resistor switches.
IMHO, the task is not worth.

The 82C54 is nice (supposing you're able to find somewhere), but it has a parallel access. It's designed to interface with microprocessors, and not with microcontrollers. That makes hard to exchange data with it, very hard. You need tons of I/O and the time to set them: the setting procedure could take more than 10ms!

I'd have a decent solution, but I need some parameter from you.
Which is the minimum time you need?
Which is the maximum error on the time?
If I understand well, you are going to create some pulse-sequences on/off: is it true?
Cheers


Thanks for the input Mario. I figure a minimum pulse width of 10 ms, maybe 5 ms would be nice. Anything less than that is definitely overkill. Maximum pulse might be around 200 ms. As for error, the less the better (obviously), I think around 10 - 20% would be acceptable. Precision is probably more important than accuracy, so if it's consistently 1 ms too long on a 10 ms pulse (averaging to 11 ms), that's probably better than sometimes being 9 ms, sometimes 11 ms (averaging to 10 ms).
The final application would involve, for a set of pulse widths (let's say 10, 20, 50, 100, 200 ms), generating in random order one of those pulses, then several seconds later generate another one, and so on until all pulse widths have been presented. The way I envision it, I would use an application running on the PC to order up the pulses as and when they are needed (the PC would also need to collect feedback after each pulse). The start of the pulse isn't as important as the width, so if the pulse doesn't start until 100 ms after the PC decides it needs it, it's not a problem. If it doesn't start until several seconds later, then it becomes a problem.

Hope that makes at least some sense.

Thanks again.

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 August 2011 - 01:21 PM

I see. Since it costs almost zero, I'd suggest to try directly with the pure C# code in the Netduino. Then, you will decide whether the accuracy is acceptable or not. I'd avoid to make you useless circuits unless strictly need. It seems that the Netduino will make a very little job. There are tricks to minimize the GC task, and to maximize the precision on timings. So, start considering the Netduino WILL BE able to solve your problem. Write the code to exchange data to/from PC, and toggle the output port on/off. When the code is ready, but the timings aren't so accurate, post your code and will trim it as the best. Cheers
Biggest fault of Netduino? It runs by electricity.

#10 wjousts

wjousts

    Member

  • Members
  • PipPip
  • 22 posts

Posted 02 August 2011 - 01:24 PM

I see.
Since it costs almost zero, I'd suggest to try directly with the pure C# code in the Netduino. Then, you will decide whether the accuracy is acceptable or not.
I'd avoid to make you useless circuits unless strictly need.

It seems that the Netduino will make a very little job. There are tricks to minimize the GC task, and to maximize the precision on timings.
So, start considering the Netduino WILL BE able to solve your problem. Write the code to exchange data to/from PC, and toggle the output port on/off. When the code is ready, but the timings aren't so accurate, post your code and will trim it as the best.
Cheers


Thanks Mario.

I just got my Netduino board and I'm going to start playing around with it. I agree with you that it makes sense to see how good (or bad) the timings are with just the Netduino board by itself before I start resorting to something external. I'll play around and see what happens.




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.