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

Clock - Time to on and off an output pin


  • Please log in to reply
5 replies to this topic

#1 GB30

GB30

    Member

  • Members
  • PipPip
  • 10 posts

Posted 30 September 2010 - 01:58 PM

Hi! I observed with an oscilloscope the behaviour of this code: static OutputPort out1 = new OutputPort(Pins.GPIO_PIN_D0, false); public static void Main() { while (1==1) { out1.Write(true); out1.Write(false); } } and I measure on pin ton time: it is 60 us. I think that it is a long time for only 2 instructions! if Netduino clock is around 48 MHz, it is a long period Have you got some ideas about it? Thanks!

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 September 2010 - 02:24 PM

Hi GB30, Your C# code is running at the managed code layer, so it's being interpreted by the .NET runtime...there is a lot going on behind the scenes. If you'd like to take advantage of the raw speed of the microcontroller, you can write your time-sensitive code in C++ (with a C# wrapper class) and compile it into the Netduino firmware. You can also erase the Netduino and use C/C++ and SAM-BA for a fast 100% native code solution--but that sort of defeats the purpose of having .NET on there. We put the erase pad on the board so that it's fully "hackable." Chris

#3 GB30

GB30

    Member

  • Members
  • PipPip
  • 10 posts

Posted 30 September 2010 - 03:17 PM

Hi GB30,

Your C# code is running at the managed code layer, so it's being interpreted by the .NET runtime...there is a lot going on behind the scenes. If you'd like to take advantage of the raw speed of the microcontroller, you can write your time-sensitive code in C++ (with a C# wrapper class) and compile it into the Netduino firmware.

You can also erase the Netduino and use C/C++ and SAM-BA for a fast 100% native code solution--but that sort of defeats the purpose of having .NET on there. We put the erase pad on the board so that it's fully "hackable."

Chris




Thank you for the response. Obviously there is a lot going on behind the scenes.
Is there an example of C# wrapper class?

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 30 September 2010 - 03:22 PM

Is there an example of C# wrapper class?

Please have a look at sweetlilmre's generic BitBanger. What exactly do you want to do?

#5 BotDuino

BotDuino

    New Member

  • Members
  • Pip
  • 7 posts

Posted 04 August 2011 - 06:47 PM

Hi GB30,

Your C# code is running at the managed code layer, so it's being interpreted by the .NET runtime...there is a lot going on behind the scenes. If you'd like to take advantage of the raw speed of the microcontroller, you can write your time-sensitive code in C++ (with a C# wrapper class) and compile it into the Netduino firmware.

You can also erase the Netduino and use C/C++ and SAM-BA for a fast 100% native code solution--but that sort of defeats the purpose of having .NET on there. We put the erase pad on the board so that it's fully "hackable."

Chris



I am trying to write code for my own Software I2C library and need very exacting timing of roughly 30 microseconds. I did the same thing using an oscilloscope, and got about 60 to 70 microseconds. I was wondering if there was a way I could get information on how I could edit/add a library in the firmware to support this.

I opened the firmware, and had no idea where to even begin, any help on this will be greatly appreciated.

#6 Tom Cerul

Tom Cerul

    New Member

  • Members
  • Pip
  • 2 posts

Posted 15 November 2011 - 06:03 PM

Hi GB30,

Your C# code is running at the managed code layer, so it's being interpreted by the .NET runtime...there is a lot going on behind the scenes. If you'd like to take advantage of the raw speed of the microcontroller, you can write your time-sensitive code in C++ (with a C# wrapper class) and compile it into the Netduino firmware.

You can also erase the Netduino and use C/C++ and SAM-BA for a fast 100% native code solution--but that sort of defeats the purpose of having .NET on there. We put the erase pad on the board so that it's fully "hackable."

Chris



AHA! That would explain the crazy times that I've been seeing!

int a, b, c; b = 2; c = 1;
b++;  // 0 micro seconds (us)
a = b - c;  // 21.4 us !!

long tick = DateTime.Now.Ticks;  // 149.3 us
TimeSpan time = Utility.GetMachineTime(); // 64 us.  NOTE: this is a faster timestamp than getting straight ticks

Good to know that we should only expect 1/1,000th of the performance that the cpu has.




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.