View previous topic :: View next topic |
Author |
Message |
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Sat Dec 27, 2014 6:39 am |
|
|
How to configure pins of 16F1827 for:
-4 PWM with independent duty cycle;
-2 (better 3) interrupt buttons;
-I2C;
-external crystal;
I can't choose right pins config.
I also can't understand what is the relations between P1A... P1D and P2A...P2D. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Dec 27, 2014 12:16 pm |
|
|
Start with the oscillator.
HS. Selects 4MHz or greater crystal. This uses the OSC1 & OSC2 pins.
Pins RA6 & RA7 used.
Then the I2C. You can actually use any pins for software I2C, but assuming you want the hardware, this is going to need one pair of the SCL/SDA pins. So RB1/RB4 or RB2/RB5.
Then the PWM's. Look at the data sheet. CCP3, and CCP4 are the standard single PWM outputs for these PWM's. For the ECCP look at table 24-6. Note that for a single output, only PxA is modulated. Then look at Table 1 (pin summary). So CCP3 is RA3, CCP4 is RA4. P1A is RB0. P2A is RA7.
So now see if we can get the inputs. The only interrupt that can give two/three pins, is the 'interrupt on change'. This requires pins on port B. Given that both the I2C options are on PortB, it doesn't matter which pair of pins we use. So lets select RB1/4, and use the remaining pins on this port for the inputs
At this point we have:
RA0
RA1
RA2
RA3 CCP3
RA4 CCP4
RA5
RA6 OSC2
RA7 OSC1
RB0 P1A
RB1 SDA1
RB2 IOC
RB3 IOC
RB4 SCL1
RB5 IOC
RB6 P2A
RB7 IOC
So you have four pins left on port A.
The PxA to D pins are for when you run the ECCP in full bridge or half bridge mode, operating two complementary pins from the single PWM. PWM2 only supports half bridge (two pins). PWM1 supports full bridge (two 'pairs' of pins operated for forward/reverse). Figure 24-6 shows which combinations of pins operate for the different modes. |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Mon Dec 29, 2014 1:28 am |
|
|
Thanks, Ttelmah!
You always give answers on the merits and without demagoguery. |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Thu Jan 15, 2015 1:52 am |
|
|
Is this right init for this settings?
Code: |
#define P1A PIN_B0
#define P2A PIN_B6
setup_ccp1(CCP_PWM|CCP_PWM_H_H);
setup_ccp2(CCP_PWM|CCP_PWM_H_H);
setup_ccp3(CCP_PWM);
setup_ccp4(CCP_PWM);
|
Will the unused pwm outputs (P1B-D, P2B-D) act as generic i/o pins? |
|
|
|