Neither am I. That's the 1st bit of code I've compiled or tested on this one.I am not all that familiar with this chip yet.
Quite a lot. With the 16F1827 you only need a single pin. Here's a schematic;How is it different than the 16F877A using PWM1 at 38.8Khz and sending serial data out on say RB4 data out?
RB3 ----/\/\/\-----|>|---GND.
Or you could use an NPN transistor if you need more range. Look at the logic picture below.
The top signal is the modulated data output from RB3 MODOUT. The lower signal is
the USART TX output.
Here's a copy of the previous code with better explanations, and both the USART TX out,
and PWM output pins disabled.
Even with PWM on, and the USART sending data, there is no PWM output on the CCP1 pinCode:' MODOUT, RB3, outputs whatever you send with HSEROUT as a 40kHz ' modulated data stream. ASM __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _VCAPEN_OFF & _LVP_OFF & _STVREN_OFF ENDASM DEFINE OSC 8 DEFINE HSER_BAUD 2400 Duty VAR WORD TRISB = 0 Init: CCPTMRS = %00000000 ' CCP1 is based off Timer 2 in PWM Mode PR2 = 49 ' Set PWM for ~40kHz CCP1CON = %00001100 ' Mode select = PWM T2CON = %00000100 ' %00000100 = TMR2 ON 1:1 prescale Duty = 100 ' Roughly 50% duty cycle CCP1CON.4 = duty.0 ' Setup 10-bit duty cycle as CCP1CON.5 = duty.1 ' a 10-bit word CCPR1L = DUTY >> 2 APFCON0 = 1 ' Assigns CCP1 PWM output to RB0 (RB3 is used for MODOUT) OSCCON = %01110000 ' 8MHz internal ANSELA = 0 ' all digital. A/D disabled ANSELB = 0 ' Data Signal Modulator setup ' Notes: ' MDSRC.7 = 1, which eliminates the USART TX signal output on RB2/TX. ' The PWM output signal, on CCP1 pin, which is set to RB0 with APFCON0=1 ' has been disabled by setting MDCARL.7 ' So even with the hardware USART outputting data, and PWM on, thier output pins ' are disabled. PWM and the serial data output from the USART are "mixed" internally ' by the Data Signal Modulator. MDCON = %11100000 ' modulator, MODOUT pin, slew rate limiting enabled MDSRC = %10001010 ' USART TX is modulation source, TX output "pin" disabled MDCARH = %00000000 ' carrier OFF during idle periods MDCARL = %10000100 ' carrier ON only when sending data, CCP1 PWM "pin" output disabled Main: HSEROUT [$55] ' sends USART data out modulated at 40kHz PAUSE 500 GOTO Main END
or data output on the USART TX pin. Both signals are mixed internally by the DSM,
and output only on RB3 or MODOUT.
I only had the USART TX pin output enabled to capture the logic analyzer traces below to
show the MODOUT signal compared to the USART TX output signal.




Bookmarks