Guys,
I have the following basic code that does nothing more then counting pulses with interrupts on 3 IO’s. I do see now and then that the GC kicks in. Can this code be optimized to reduce the GC calls?
namespace FEZ_Panda_Counters
{
public class Program
{
static FEZ_Pin.Interrupt gasPin = FEZ_Pin.Interrupt.Di7;
static FEZ_Pin.Interrupt watPin = FEZ_Pin.Interrupt.Di6;
static FEZ_Pin.Interrupt elePin = FEZ_Pin.Interrupt.Di5;
static int g_Counter;
static long g_prevPulse;
static long g_lastPulse;
static float g_duration;
static int w_Counter;
static long w_prevPulse;
static long w_lastPulse;
static float w_duration;
static int e_Counter;
static long e_prevPulse;
static long e_lastPulse;
static float e_duration;
static float tps = TimeSpan.TicksPerSecond;
public static void Main()
{
InterruptPort g = new InterruptPort((Cpu.Pin)gasPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
InterruptPort w = new InterruptPort((Cpu.Pin)watPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
InterruptPort e = new InterruptPort((Cpu.Pin)elePin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
g.OnInterrupt += new NativeEventHandler(g_OnInterrupt);
w.OnInterrupt += new NativeEventHandler(w_OnInterrupt);
e.OnInterrupt += new NativeEventHandler(e_OnInterrupt);
Thread.Sleep(Timeout.Infinite);
}
static void g_OnInterrupt(uint data1, uint data2, DateTime time)
{
g_Counter++;
g_prevPulse = g_lastPulse;
g_lastPulse = time.Ticks;
displayCounter();
}
static void w_OnInterrupt(uint data1, uint data2, DateTime time)
{
w_Counter++;
w_prevPulse = w_lastPulse;
w_lastPulse = time.Ticks;
displayCounter();
}
static void e_OnInterrupt(uint data1, uint data2, DateTime time)
{
e_Counter++;
e_prevPulse = e_lastPulse;
e_lastPulse = time.Ticks;
displayCounter();
}
static void displayCounter()
{
g_duration = (g_lastPulse - g_prevPulse) / tps ;
w_duration = (w_lastPulse - w_prevPulse) / tps;
e_duration = (e_lastPulse - e_prevPulse) / tps;
Debug.Print("gC " + g_Counter + " , gDur: " + g_duration.ToString("F4") + " , wC " + w_Counter + " , wDur: " + w_duration.ToString("F4") + " , eC " + e_Counter + " , eDur: " + e_duration.ToString("F4"));
}
}
}
In the end, it should send the counters/times over serial to a Cobra, but I’ll deal with that later.
Thanks