with a little help from peripherals
Hi, Rubik
a 555 running at 40 khz would easily solve your headache ...without any program timing difficulties ...
Alain
The peripherals are already built-in!
Just use the PIC12F683's internal hardware PWM peripheral. This way you can easily generate the 40KHz, turn it on and off, adjust the duty cycle and it runs in the background. The datasheet will show you exactly how to set it up.
Personally I don't like using the HPWM command in PB Pro because its too limited. It's easier to do it by manually setting the registers.
This is exactly how I generate the 40KHz IR for my lasertag systems.
'register setup (this is for a 16F684, so it may need to be modified slightly for your chip)
PR2 = 49 'PWM Period 40K=49
CCPR1L = 10 'PWM Duty Cycle
T2CON = 4 'Timer2 = ON; Prescale = 1:1
CCP1CON = 0 'PWM module off
'generate 1ms 40KHz pulse
CCP1CON = 12 'PWM ON
PauseUS 1000
CCP1CON = 0 'PWM OFF