When you're having problems like this, it's sometimes much easier to simplify
everything & start with a single peice of code that gets a peripheral you're
having problems with working first.
Then move on to testing your other routines step-by-step, inserting tested
& known working code with new code until you hit the problem again. Then
you at least have some idea of what may be causing the problem.
Try something like this without any other code to test your CCP module.
Disconnect all external circuits just in case it's an external circuit connection
that causing problems.
Code:
DEFINE HPWM1_TIMER 2
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2 ' RC2
DEFINE HPWM2_TIMER 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1 ' RC1
TRISC.1 = 0
TRISC.2 = 0 ' HPWM automatically does this for you, but just in case
CCP1CON = %00001100 ' PWM mode
CCP2CON = %00001100 ' PWM mode
HPWM 1,127,3600 ' RC2/CCP1 3.6kHz @ ~50% duty
HPWM 2,127,3600 ' RC1/CCP2 3.6kHz @ ~50% duty
Does it work?
If it does, then you have verified your CCP module & PBP code to control
it. If it doesn't work then you may have a hardware or config problem.
Your PBP device header file (18F4520.INC) has "deafult" config fuse settings
in it something like the following;
Code:
INCLUDE "P18F4520.INC" ; MPASM Header
__CONFIG _CONFIG1H, _OSC_XT_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
If you think maybe your programmer isn't setting HS when selected manually,
then edit your inc file changing XT in the first line to HS. Save it, close it,
and re-compile. Then check to see if it's really set to HS when you open the
.HEX file with your programmer before programming your 4520.
Once you get hardware PWM working, then move on to insert other code
modules one-by-one, and re-test.
Bookmarks