SignalGenerator for 1-8 digital outputs

Hello

With OutputCompare you can write digital data to one output pin.
But if you need to write several pins simultaneously and synchronously there is no function available for the C# programmer. This is a lack.

I wrote a feature request 4 month ago and it was rejected:
http://www.tinyclr.com/forum/6/4296/#/1/msg40877

So I had to write my own code in RLP.
I offer it here for download for anybody who finds it usefull.
Note that the design of the code here is simpler than what I requested but it is enough for my current needs.

Download the sourcecode here: (ZIP file with Managed and Native project)

The code is approved.
It works perfectly.
I checked it on the oscilloscope.
The code is really fast: The time offset between two output pins, that switch their state at the same time, is 2 µs on FEZ domino.

The ZIP file contains an entire RLP project and the corresponding Managed project (C#).

ATTENTION:
The code requires 3 changes before it can be compiled:

1.) in the Native project in RLP.h you must remove the comments in 2 lines depending on your hardware.
2.) in the Managed project you must enter your activation code into Program.cs.
3.) in the Managed project you must add a reference to the assembly for your platform (e.g. FEZDomino_GHIElectronics.NETMF.FEZ)

Afterwards you can compile it.
The ELF file in the ZIP is compiled for FEZ devices.

IMPORTANT:
The function SignalGenerator() is a blocking function.
This is by design.
It does not return before all data has been written.
If you need output in an extra thread you must modify the code to use

RLPext->Task.ScheduleTimeOffset()

instead of

RLPext->Delay()

If you never worked with RLP you find a very good manual here:

How to use:

public static void Main()
{
    LoadELF();

    FEZ_Pin.Digital[] e_Pins = new FEZ_Pin.Digital[] { FEZ_Pin.Digital.Di4,  // Bit 0 = u8_Data[x] & 1
                                                       FEZ_Pin.Digital.Di5,  // Bit 1 = u8_Data[x] & 2
                                                       FEZ_Pin.Digital.Di6,  // Bit 2 = u8_Data[x] & 4
                                                       FEZ_Pin.Digital.LED}; // Bit 3 = u8_Data[x] & 8
    ResetSignalGenerator(e_Pins, 0x00);

    // Outputs with 250 µs clock:  (use oscilloscope to check!)
    // Pin 4: ...___X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X.... Pause 100 ms 
    // Pin 5: ...____XX__XX__XX__XX__XX__XX__XX__XX__XX__XX.... Pause 100 ms
    // Pin 6: ...______XXXX____XXXX____XXXX____XXXX____XXXX.... Pause 100 ms
    // LED  : ...___XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.... Pause 100 ms
    // The LED is on all the time while data is written

    Byte[] u8_Data = new Byte[4096];
    for (int i=0; i<u8_Data.Length; i++)
    {
        u8_Data[i] = (Byte)((i%8) | 8);
    }

    while (true)
    {
        SignalGenerator(250, e_Pins, u8_Data);

        ResetSignalGenerator(e_Pins, 0x00);
        Thread.Sleep(100);
    }
}

The code can output up to 8 pins simultaneously.
The function SignalGenerator() is typesafe.

This code writes a 250 µs square signal on pin 4, a 500 µs signal on pin 5 and a 1 ms signal on pin 6.

After 4096 clocks it makes a pause of 100 ms.
You can perfectly check that on your oscilloscope.
While data is written the LED lights up.

And if you don’t have an oscillocope: You can use the parallel port of your PC.
I wrote an open-source 17 channel logic-analyzer via the printer port that captures up to 500.000 samples / second and generates a graphical display:
http://www.codeproject.com/Articles/75279/17-Channel-Logic-Analyzer

Elmü

Thank you for sharing your drivers.

Because we have a dedicated area fro uploading drivers, http://code.tinyclr.com/

Your driver will be lost over time. It would be great if you uploaded to the code section.

OK
I changed that

I see it in code share now. Thanks for sharing.