This is a simple example of OutputCompare.
I wrote it to learn about the OC so it might help others, or it might not.
What surprised me was that the OutputCompare kept on running when the program was paused…
All it does is “breathe” the onboard led on a Panda/Domino. What is nice is that it is “fire and forget”…
using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
namespace USBizi_Application1
{
public class Program
{
public static void Main()
{
OutputCompare oc = new OutputCompare((Cpu.Pin)FEZ_Pin.Digital.LED, false, 360);
uint[] Buffer = new uint[360];//Create a buffer for 180 on times and 180 off times
for (int i = 0; i < 360; i=i+2) //Fill the buffer with the on times from the SIN function.
{
int SinValue=(Microsoft.SPOT.Math.Sin(i)+1000)*10;//Value will vary between 0 and 20000
Buffer[i] = (uint)(SinValue);//On time
Buffer[i + 1] = 20000 - Buffer[i]; //Off time is the remaining time, of 20000us, after On time.
}
oc.Set(false,Buffer,0,Buffer.Length,true);//Start the Output Compare, repeating.
//while (true) ;
Thread.Sleep(Timeout.Infinite) ;// Sleep CPU
}
}
}