Code for IR remote control emulator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code for IR remote control emulator

1,017 Views
quevedo
Contributor V

Hello,

 

I am trying to emulate a remote control using a S08PT60, connected to a switching transistor and an IR LED. However, my algorithm is not working. I have sliced the code into 500us slices, because all "on" and "off" times are multiples of 500us. Then I have a boolean vector which indicates whether the LED should be oscillating or not during that 500us period. The microcontroller enters a periodic interrupt every 500us to enable or disable the PWM oscillator, which controls the transistor.

 

Using an IR receiver, I have confirmed that the oscillator is being switched on and off. However, all timing seems to be wrong. Times are bigger than they should be.

 

Does anybody have a hint on how I can switch the PWM oscillator with correct timing?

 

Thanks in advance.

Labels (1)
0 Kudos
1 Reply

308 Views
bigmac
Specialist III

Hello,

 

Without seeing the actual code, I can only guess at the cause of the problem.

 

I assume that you are attempting to generate the 38 kHz, or thereabouts, carrier waveform using the channel output of a FTM module operating with edge-aligned PWM mode?  You have not disclosed the method you are using to enable or disable this waveform in accordance with the modulation state.  The possibilities would seem to be to enable and disable the FTM channel, to alternate between 0 percent and 50 percent duty, or possibly to make use of the new output mask feature.  The coherency delays may differ for each method.

 

Using any of these software methods will produce timing errors due to interrupt latency for the timer associated with the modulation waveform.  The latency period will be unpredictable should any other ISR be executing when the timer interrupt becomes pending, which may be further extended should another higher priority interrupt also become pending prior to completion of the ISR code.  Within the timer ISR, your coding will need to ensure that the latency cycles remain constant, and are the same for both turn on and turn off processes.

 

You have not said which timer module you are using to generate the modulation timing.  I might suggest using a channel from another FTM module (free-running mode), and using output compare interrupts.  Since you would already know the amount of time required to the next change of state, the channel register is easily updated for the next compare event.  This will reduce the number of interrupts, and may increase flexibility, over interrupting at 500us fixed intervals.

 

The timing errors due to the ISR latency could be eliminated if you were to separately generate the modulation waveform at the output pin of the timer channel, in addition to providing a constant PWM output.  However, additional external gating circuitry would be required to combine the PWM and modulation signals.  The additional circuitry might consist of as little as a MOSFET transistor, or a bipolar transistor and one or two resistors.  The configuration will depend on your existing arrangement to drive the IRED, and the peak current through the device.

 

Regards,

Mac

0 Kudos