Hi Nick,
Sorry about the typo, told you I didn't test it though.
Currently I have no idea why my original code (less the typo) did not work while your new one does. I just tried it here, again with two 12F1840's so that MIGHT have something to do with it but I don't think so. I also figured out that once you've enabled PWM mode on the CCP pin you can't control that output manually. So in order to force the PWM output low during the OFF period of the carrier you have to disable the CCP module and THEN force it low, I've implemented that in the TX-code below:
Code:
' ***************************************************************
' 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 8Mhz
' ***************************************************************
' Variables and aliases
' ***************************************************************
i VAR BYTE
LED VAR PortA.4
' ***************************************************************
' Initialization
' ***************************************************************
OSCCON = %01110000 ' 8MHz internal osc
ANSELA = 0 ' Digital only for all PortA pins
TRISA = %00000000 ' Make PORTA outputs
CCP1CON = %00001100 ' Normal PWM
PR2 = 3 ' 500kHz output @8MHz system clock
CCPR1L = 2 ' 50% Dutycycle
CCP1CON.5 = 0
CCP1CON.4 = 0
' ***************************************************************
' Actual program
' ***************************************************************
' Show that we're up and running.
For i = 0 to 9
Toggle LED
Pause 200
NEXT
Main:
CCP1CON = %00001100 ' Normal PWM mode
T2CON.2 = 1 ' Timebase ON
PAUSE 15
T2CON.2 = 0 ' Timebase OFF
CCP1CON = %00000000 ' Disable PWM to regain control of PortA.2
PortA.2 = 0 ' Force output low to prevent saturation of coil
PAUSE 5
Goto Main
For the RX-side I did this, which is pretty much exactly like I wrote it earlier. I found that I could ditch the delay to speed up the response time since the exection time for the loop is longer than the PWM-period. If you change the frequency you may need to add some delay.
Code:
' ***************************************************************
' 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 8Mhz
' ***************************************************************
' Variables and aliases
' ***************************************************************
oldCnt VAR BYTE
i VAR BYTE
LED VAR PortA.4
' ***************************************************************
' Initialization
' ***************************************************************
OSCCON = %01110000 ' 8MHz internal osc
ANSELA = 0 ' Digital only for all PortA pins
TRISA = %00000100 ' T0CKI is input, rest outputs
' ***************************************************************
' Actual program
' ***************************************************************
OPTION_REG.5 = 1 ' TMR0 as counter
oldCnt = 0
TMR0 = 0
' Show the world that we're alive
For i = 0 to 9
Toggle LED
PAUSE 200
NEXT
Main:
IF TMR0 <> oldCnt THEN
LED = 1
ELSE
LED = 0
ENDIF
oldCnt = TMR0
Goto Main
I'm going to try to add two screen-grabs from the scope. Last time I did the uploader didn't work but hopefully that's fixed by now. Nope the bloody thing still doesn't work, sorry but you'll have to trust me that it does work here.
/Henrik.
Bookmarks