Scott Pierce wrote: > I'm trying to use the CCP module on a 16F628 to generate a 40Khz pulse > in order to communicate via IR. The following test program I wrote > using the PICC compiler should set up the CCP module for a free running > 40Khz, 50% > Duty pulse. RB3, the output of the CCP module on the F628 is connected > to > the Anode of an IR LED. The Cathode of the IR LED is connected to > RB5. Not a good idea. First, there is no need for a separate pin to enable/disable the 40KHz pulse output. You can do that just as easily in software by enabling/disabling the CCP module. Second, you need a resistor in series with the LED if running it from 5V. The forward voltage of an IR LED is nowhere near 5V, so without a resistor something will have to give. That will probably be one or both of the PIC pins. Third, IR LEDs can take a lot more current than most visible LEDs of the same size. Check the data sheet. Most likely you can put at least 100mA thru it when it's on, for an average current of 50mA. Fourth, you can't drive that much current with a PIC pin. Connect the CCP output pin to a resistor, other end of resistor to base of NPN transistor, emitter to ground, collector to LED cathode, LED anode to another resistor, and the other end of that resistor to 5V. Size the LED resistor to get 100mA (depending on your LED) thru the LED when the transistor is on. Size the base resistor to make sure the transistor is saturated when sinking the LED current. With a jellybean transistor like 2N4401 you can count on a gain of at least 50. That means you need at least 2mA base drive to support 100mA LED current. A 2Kohm base resistor will get you a little more than that, which is probably a good answer. > a 40khz pulse should be output on the IR LED for a short period of time > (about a second). That's not a short period of time. The IR detector will probably want to see pulses from 10 to 50 cycles. Much beyond that and it's automatic gain circuitry will decide the pulse is ambient and set its threshold to filter it out. > I have included a simple Excel spreadsheet I made to help calculate > the settings for the CCP Module for the PIC 16F628, which I used to > come up with my values for the program. That's silly. What happens when you change the PIC oscillator frequency or want to use a different IR modulation frequency? These should be parameters directly in your code, probably a top level include file, and everything else should be computed from that at assembly time. ****************************************************************** Embed Inc, Littleton Massachusetts, (978) 742-9014. #1 PIC consultant in 2004 program year. http://www.embedinc.com/products -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist