Log in

View Full Version : Question about kevin's code


ImmortalAres
22-06-2005, 14:18
the code found here: http://kevin.org/frc/edu_accel_lcd.zip

contains the following



// initialize CCP modules 2 & 3
TRISEbits.TRISE7 = 1; // set CCP pins to inputs
TRISGbits.TRISG0 = 1;

PIE2bits.CCP2IE = 0; // disable the CCP interrupts
PIE3bits.CCP3IE = 0;

T3CONbits.T3CCP1 = 0; // CCP 2 captures timer 1, CCP 3 captures timer 3
T3CONbits.T3CCP2 = 1;

CCP2CON = 0x05; // initialize CCP modules to capture on each rising edge
CCP3CON = 0x05;

IPR2bits.CCP2IP = 0; // CCP modules use the low priority interrupt
IPR3bits.CCP3IP = 0; //

PIR2bits.CCP2IF = 0; // make sure the interrupt flags are zero before...
PIR3bits.CCP3IF = 0; //

PIE2bits.CCP2IE = 1; // enable the CCP interrupts
PIE3bits.CCP3IE = 1; //



my question is about the 2 lines



T3CONbits.T3CCP1 = 0; // CCP 2 captures timer 1, CCP 3 captures timer 3
T3CONbits.T3CCP2 = 1;

this doesn't make sense to me. can someone please explain what's going on, the comment doesn't seem to match the code or does it and i'm jsut missing it

Thanks

Ryan M.
22-06-2005, 16:11
I think that it means that whichever one you set to 1 will be the one that works.

That help any?

Dave Flowerday
22-06-2005, 17:24
my question is about the 2 lines



T3CONbits.T3CCP1 = 0; // CCP 2 captures timer 1, CCP 3 captures timer 3
T3CONbits.T3CCP2 = 1;

this doesn't make sense to me. can someone please explain what's going on, the comment doesn't seem to match the code or does it and i'm jsut missing it
Take a look at the datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/39609b.pdf), page 152, specifically figure 16-1. Notice Kevin is setting T3CCP1 to 0 and T3CCP2 to 1, which corresponds to T3CCP<2:1> = 10 in that figure. This shows that timers 1 and 2 are connected to CCP1 and CCP2, and timers 3 and 4 are connected to CCP3, 4, and 5. Then look at table 16-1 in the upper right corner, which says that in capture mode, timers 1 and 3 are available. You can check the settings of CCP2CON and CCP3CON to see that they are being set to capture mode, so you can conclude from all this that CCP2 captures timer 1 and CCP3 captures timer 3, just like the comment says.

ImmortalAres
23-06-2005, 11:13
Notice Kevin is setting T3CCP1 to 0 and T3CCP2 to 1, which corresponds to T3CCP<2:1> = 10 in that figure.

i didn't realize that was what occurred. If i reversed it, T3CCP1 to 1 and T3CCP2 to 0 i should get the T3CCP<2:1> = 01 configuration correct?