Problem with OutputCompare or PWM (or diode?)

Hi,

I am trying to use infrared sender & receiver library from http://code.tinyclr.com/project/267/infrared-sender-and-receiver/ in order to do some device @ FEZ Mini, but first I wanted to copy&paste the code and the example just to see how it works. The problem is, that something is not ok, because after saving a button code from air-condidioner remote controller, every attempt to control the conditioner with my device was unsuccessful. I made several changes in code to better know what are the differences. So here is the changed OnDataReceived():

private static void OnDataReceived(object sender, uint[] pulseWidths, int pulseCount)
{
    // return if one pulse has been already saved
    //if (_savedPulseCount != 0)
    //    return;
    if (_savedPulseCount == pulseCount)
        Debug.Print("Pulse counts are equal");
    if (_savedPulseCount > 0)
    {
        for (int i = 0; i < 16; i++) //just to show some widths
            Debug.Print("Saved pulse width: "+_savedPulse[i]+"\tReceived pulse width: "+pulseWidths[i]);
        MeasureMeanDifference(_savedPulse, pulseWidths, pulseCount);
    }
    else
    {
        _savedPulse = pulseWidths;
        _savedPulseCount = pulseCount;
    }

    Blink(3);
}

private static void MeasureMeanDifference(uint[] savedPulse, uint[] pulseWidths, int pulseCount)
{
    int diffSum = 0;
    for (int i = 0; i < pulseCount; i++)
    {
        var diff = (int)savedPulse[i] - (int)pulseWidths[i];
        if (diff < 0)
            diff = -diff;
        diffSum += diff;
    }
    Debug.Print("Total difference is " + diffSum + "us");
    Debug.Print("Mean difference is " + (double)diffSum/pulseCount + "us");
}

And here are the results for TV remote controller Grundig TP720. I used it instead of air-conditioner one because sometimes the beam reaches the device and changing it’s state for several times might be annoying for someone else in the room ;).

Attempts with still pressing a button on the remote control:

[quote]Saved pulse width: 546 Received pulse width: 544
Saved pulse width: 2624 Received pulse width: 2626
Saved pulse width: 537 Received pulse width: 538
Saved pulse width: 510 Received pulse width: 510
Saved pulse width: 491 Received pulse width: 492
Saved pulse width: 574 Received pulse width: 572
Saved pulse width: 499 Received pulse width: 492
Saved pulse width: 557 Received pulse width: 557
Saved pulse width: 496 Received pulse width: 496
Saved pulse width: 560 Received pulse width: 560
Saved pulse width: 493 Received pulse width: 493
Saved pulse width: 563 Received pulse width: 563
Saved pulse width: 500 Received pulse width: 500
Saved pulse width: 556 Received pulse width: 556
Saved pulse width: 497 Received pulse width: 497
Saved pulse width: 559 Received pulse width: 559
Total difference is 17us
Mean difference is 0.80952380952380953us

Total difference is 60us
Mean difference is 2.8571428571428572us

Total difference is 112us
Mean difference is 5.333333333333333us

Total difference is 26us
Mean difference is 1.2380952380952381us

Total difference is 91us
Mean difference is 4.333333333333333us[/quote]

Now I was using the FEZ Mini to generate signal:

[quote]Pulse counts are equal
Saved pulse width: 551 Received pulse width: 570
Saved pulse width: 2618 Received pulse width: 2616
Saved pulse width: 551 Received pulse width: 576
Saved pulse width: 505 Received pulse width: 477
Saved pulse width: 496 Received pulse width: 524
Saved pulse width: 560 Received pulse width: 528
Saved pulse width: 493 Received pulse width: 515
Saved pulse width: 563 Received pulse width: 564
Saved pulse width: 501 Received pulse width: 520
Saved pulse width: 555 Received pulse width: 532
Saved pulse width: 498 Received pulse width: 521
Saved pulse width: 558 Received pulse width: 531
Saved pulse width: 496 Received pulse width: 522
Saved pulse width: 561 Received pulse width: 557
Saved pulse width: 493 Received pulse width: 517
Saved pulse width: 589 Received pulse width: 562
Total difference is 1555us
Mean difference is 23.923076923076923us

Total difference is 1532us
Mean difference is 23.569230769230771us

Total difference is 1370us
Mean difference is 21.076923076923077us

Total difference is 1524us
Mean difference is 23.446153846153845us

Total difference is 1453us
Mean difference is 22.353846153846153us[/quote]

I am using the same IR diode and receiver module (TSOP312) as the author of the library.

Does anyone know (maybe someone had the same issue with this library) what is the possible reason?

Regards,
Tomasz

Do it hte way ti is done in our free ebook http://www.ghielectronics.com/downloads/FEZ/FEZ_Internet_of_Things_Book.pdf

Now I suppose that problem might be somewhere else - using both FEZ Mini or Domino also the example from this e-book didn’t make my device send proper signal…

Regards,
Tomasz

Have you “AND’ed” ir output and pwm output?

Can’t find the schematics, the link in the code project seems to be dead.

Hi,

I have everything connected like in the Gralin’s example schematics: http://code.tinyclr.com/file/423/
Actually, I cannot resolve “AND’ed” in my mind, I find my lack of skills disturbing - therefore please explain me a little bit or link to proper place.

My bad :/.

Regards,
Tomasz

From the code:


private OutputCompare _infraredLed;
private PWM _frequencyGenerator;

The pwm create the base modulation frequency, the outputcompare creates the ir signal.

Maybe in that schematic, one pin is the PWM output and the other pin is the IR signal output, that is an easy way to AND both signals. I would have implemented it with transistors or FET’s because IR LED’s can draw more current then those pins can deliver… (BTW, Why does the schematic mention a UV led??)

Hi,

Issue solved. With some help I figured out how to connect IR LED with a transistor to supply it with more current, and it uses only OutputCompare.
If someone would need it (for FEZ Internet of Things e-book example) I can post the schema.

Regards,
Tomasz

I see that the OutputCompare class has the ability to modulate the signal, so idd that should be the only class you’ll need.