Correct way of generating a modulated IR pulse

General JP1 chit-chat. Developing special protocols, decoding IR signals, etc. Also a place to discuss Tips, Tricks, and How-To's.

Moderator: Moderators

Post Reply
Barf
Expert
Posts: 1524
Joined: Fri Oct 24, 2008 1:54 pm
Location: Munich, Germany
Contact:

Correct way of generating a modulated IR pulse

Post by Barf »

There is a discussion here on the correct way of generating an ON-pulse (called "flash" or "mark" in different communities) in software. The problem is that using the common on-off modulation, it may happen that the target time does not end with the light on, in which case the pulse will effectively be too short, and the leading silence will effectively be added to the following gap. I ("bengtmartensson") originally suggested the following algorithm (somewhat edited)

(micros() is a function generating the time since system start, in micro seconds, periodTime is the desired period time of the carrier, and periodOnTime the desired onTime (thus duty cycle = perioOnTime/periodTime))

Code: Select all

    unsigned long start = micros();
    unsigned long stop = start + time;
    unsigned int count = 0U;
    while (micros() < stop) {
            count++;
            unsigned long now = micros();
            int onTime = min(periodOnTime, (int) (stop - now));
            if (onTime > 0) {
                    TURN_ON;
                    delayMicroseconds((unsigned) onTime);
            }
            TURN_OFF;
            unsigned long targetTime = min(start + count * periodTime, stop);
            int timeOff = (int) (targetTime - micros());
            if (timeOff > 0)
                    delayMicroseconds((unsigned) timeOff);
    }
So, what do the experts here say? What is the correct ("correctest"?) way to generate an flash (or mark) when the times do no match up? What are the UEI executors doing?
3FG
Expert
Posts: 3434
Joined: Mon May 18, 2009 11:48 pm

Post by 3FG »

I think the correctest way is to always generate full length on pulses for each modulation period. Regarding the UEI executors, the approach used in MAXQ and CC254x processors (the newest micros used by UEI) is similar to Pronto Hex-- typically On durations are expressed in units of the modulation period, so the question does not arise. I think S3F80 executors which are of recent vintage make an attempt to give the same behavior even though these are timer based.
Post Reply