It's a plugin that generates the configuration code for you. The 18f45k22 is one of the supported devices.
http://www.microchip.com/pagehandler/en ... /home.html
// Initialize PWM output
TRISCbits.TRISC1 = INPUT; // Disable CCP output
// Set up CCP/PWM registers
TMR4 = 0x4E; // Set Period for 800 Hz
PR4 = 0x4E; // Set compare period.
CCPR2L = (PR4 >> 1); // Set pulse width
CCPTMRS0bits.C2TSEL = 01; // Select timer
CCP2CONbits.CCP2M = 0b1100; // set to PWM Mode
CCP2CONbits.DC2B = 0; // lsbs of pulse width compared with timer?
// Timer Setup
TMR4IE = FALSE; // No timer interrupt - freerunning
// flag gets set regardless of interrupt enable or not
T4CONbits.T4CKPS1 = 1; // /16 prescaler
T4CONbits.TMR4ON = YES; // tmr on
TRISCbits.TRISC1 = OUTPUT; // Enable CCP output
// Initialize PWM output==========================
TRISCbits.TRISC1 = INPUT; // Disable CCP output (verified as "1")
// Suggestion from Forum
// These two default to these values on reset anyway
ECCP2AS = 0; // PWM Shutdown disabled
PMD1 = 0; // (normal default setting)
// Timer Setup
TMR2 = 0;
T2CONbits.T2CKPS1 = 1; // /16 prescaler
T2CONbits.TMR2ON = YES; // tmr on
// Set up CCP/PWM registers
PR2 = 0x4E; // Set compare period.
CCPR2L = (PR2 >> 1); // Set pulse width
CCP2CONbits.DC2B = 2; // lsbs of pulse width
CCPTMRS0bits.C2TSEL = 0; // Select timer 4
CCP2CONbits.CCP2M = 0x0C; // set to PWM Mode
// flag gets set at compare regardless of interrupt enable or not
// this does not trigger an interrupt so should be immaterial
// This is done only so that initial PWM is correct pulse width
while (!TMR2IF);
TMR2IF = FALSE; // No timer interrupt - freerunning
TRISCbits.TRISC1 = OUTPUT; // Enable CCP output (verified as "0")
// ============================================================
SLTom992 wrote:DCxB<1:0>: PWM Duty Cycle Least Significant bits - since the PRx register is 8 bits what do these LSB's on a ten bit register do? This is after all a comparison.
The 8-bit timer TMRx register is concatenated
with the 2-bit internal system clock (FOSC), or
2 bits of the prescaler, to create the 10-bit time
base.
What is completely beyond my kin is that the chip defaults to Analog inputs. I would expect that you'd have to specifically set it to Analog Inputs. Because of this you can still output digital signals out of an analog port but you cannot input digital signals without specifically disabling the analog inputs using the ANSELx commands.
The compiler makes errors on REGbits.bitgroup commands and/or numbering system. Sometimes it will make errors on binary, sometimes on decimal and sometimes on hex. So you must have an in-circuit debugger in order to look at each load and/or transfer.
ric wrote:SLTom992 wrote:The compiler makes errors on REGbits.bitgroup commands and/or numbering system. Sometimes it will make errors on binary, sometimes on decimal and sometimes on hex. So you must have an in-circuit debugger in order to look at each load and/or transfer.
I've never struck this, but then I never initialise parts of registers, I always write the entire register in one go during initialisation.
Users browsing this forum: No registered users and 10 guests