Barf Expert
Joined: 24 Oct 2008 Posts: 1415 Location: Munich, Germany |
Posted: Tue Apr 18, 2017 3:05 am Post subject: Correct way of generating a modulated IR pulse |
|
|
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: |
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
Joined: 19 May 2009 Posts: 3367
|
Posted: Tue Apr 18, 2017 11:07 am Post subject: |
|
|
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. |
|