Hi Nick,
No problem, I didn't have a 12F683 at home but I did have a 12F1840. Now, the 1840 has an ECCP module while the 683 has a standard CCP module so the following code MAY need to be changed slightly (the CCP1CON register) in order to work properly on the 683 (I'm not using the data modulator here). It sets the CCP module up to output a 1MHz, 50% dutycycle PWM on PortA.2. The main program then simply toggles the timebase (TMR2) for the CCP module on and off to modulate the output.
Code:
' ***************************************************************
' Pin Connections
' ***************************************************************
' RA0 -> Not used
' RA1 -> Not used
' RA2 -> CCP1 output
' RA3 -> Not used
' RA4 -> Not used
' RA5 -> Not used
' ***************************************************************
' Device Fuses
' ***************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
__config _CONFIG2, _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF
#ENDCONFIG
' ***************************************************************
' Compiler directives
' ***************************************************************
DEFINE OSC 8 ; We're running at 16Mhz
' ***************************************************************
' Initialization
' ***************************************************************
OSCCON = %01110000 ' 8MHz internal osc
ANSELA = 0 ' Digital only for all PortA pins
TRISA = %00000000 ' Make PORTA outputs
CCP1CON = %00001100 ' Normal PWM
PR2 = 1 ' 1MHz output @8MHz system clock
CCPR1L = 0 ' 50% Dutycycle
CCP1CON.5 = 1
CCP1CON.4 = 1
' ***************************************************************
' Actual program
' ***************************************************************
Main:
T2CON.2 = 1 ' Timebase ON
PAUSE 15
T2CON.2 = 0 ' Timebase OFF
PAUSE 5
Goto Main
I have a scope screen grab of the output but for some reason the file upload manager on the forum refuses to work, the upload just hangs...aarghh....
Now, if you intend to do other things with the PIC as well then this simple aproach obviously won't work. But you could use a timer interrupt in order to turn on and off the carrier at the correct intervals. I haven't personally used the data signal modulator module in the 12F1840 but it sure sounds like the "correct" way forward. The 12F1840 also allows you to run at 32MHz using the internal oscillator and 4x PLL which would allow you to get higher output frequency using the CCP module than on the 12F683 which tops out at 8MHz.
/Henrik.
Bookmarks