Created
April 1, 2014 07:18
-
-
Save GeorgeHahn/9909352 to your computer and use it in GitHub Desktop.
Capture timing data for a signal on one pin of a Netduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using Microsoft.SPOT.Hardware; | |
using SecretLabs.NETMF.Hardware.Netduino; | |
namespace Analyzer | |
{ | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var LED = new OutputPort(Pins.ONBOARD_LED, false); | |
int count = 0; | |
var input = new InputPort(Pins.GPIO_PIN_D13, false, Port.ResistorMode.Disabled); | |
int[] statetime = new int[500]; | |
bool[] states = new bool[500]; | |
var statetimer = Utility.GetMachineTime().Ticks; | |
bool state = input.Read(); | |
while (true) | |
{ | |
var tempstate = input.Read(); | |
if (state != tempstate) | |
{ | |
states[count] = state; | |
statetime[count] = (int)(Utility.GetMachineTime().Ticks - statetimer); | |
statetimer = Utility.GetMachineTime().Ticks; | |
count++; | |
state = tempstate; | |
if (count >= 500) | |
{ | |
LED.Write(true); | |
Thread.Sleep(1); // Breakpoint here to pull in data | |
count = 0; | |
statetime = new int[500]; | |
states = new bool[500]; | |
LED.Write(false); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment