Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
11
Добавлен:
21.12.2020
Размер:
8.16 Mб
Скачать

PIC18F8722 FAMILY

18.4.9SETUP FOR PWM OPERATION

The following steps should be taken when configuring the ECCP1 module for PWM operation using Timer2:

1.Configure the PWM pins, P1A and P1B (and P1C and P1D, if used), as inputs by setting the corresponding TRIS bits.

2.Set the PWM period by loading the PR2 register.

3.If auto-shutdown is required do the following:

Disable auto-shutdown (ECCP1AS = 0)

Configure source (FLT0, Comparator 1 or Comparator 2)

Wait for non-shutdown condition

4.Configure the ECCP1 module for the desired PWM mode and configuration by loading the CCP1CON register with the appropriate values:

Select one of the available output configurations and direction with the P1M1:P1M0 bits.

Select the polarities of the PWM output signals with the CCP1M3:CCP1M0 bits.

5.Set the PWM duty cycle by loading the CCPR1L register and CCP1CON<5:4> bits.

6.For Half-Bridge Output mode, set the dead-band delay by loading ECCP1DEL<6:0> with the appropriate value.

7.If auto-shutdown operation is required, load the ECCP1AS register:

Select the auto-shutdown sources using the ECCP1AS2:ECCP1AS0 bits.

Select the shutdown states of the PWM output pins using the PSS1AC1:PSS1AC0 and PSS1BD1:PSS1BD0 bits.

Set the ECCP1ASE bit (ECCP1AS<7>).

Configure the comparators using the CMCON register.

Configure the comparator inputs as analog inputs.

8.If auto-restart operation is required, set the P1RSEN bit (ECCP1DEL<7>).

9.Configure and start TMR2:

Clear the TMR2 interrupt flag bit by clearing the TMR2IF bit (PIR1<1>).

Set the TMR2 prescale value by loading the T2CKPS bits (T2CON<1:0>).

Enable Timer2 by setting the TMR2ON bit (T2CON<2>).

10.Enable PWM outputs after a new PWM cycle has started:

Wait until TMRn overflows (TMRnIF bit is set).

Enable the ECCP1/P1A, P1B, P1C and/or P1D pin outputs by clearing the respective TRIS bits.

Clear the ECCP1ASE bit (ECCP1AS<7>).

18.4.10OPERATION IN POWER-MANAGED MODES

In Sleep mode, all clock sources are disabled. Timer2 or Timer4 will not increment and the state of the module will not change. If the ECCP1 pin is driving a value, it will continue to drive that value. When the device wakes up, it will continue from this state. If Two-Speed Start-ups are enabled, the initial start-up frequency from INTOSC and the postscaler may not be stable immediately.

In PRI_IDLE mode, the primary clock will continue to clock the ECCP1 module without change. In all other power-managed modes, the selected power-managed mode clock will clock Timer2 or Timer4. Other power-managed mode clocks will most likely be different than the primary clock frequency.

18.4.10.1Operation with Fail-Safe Clock Monitor

If the Fail-Safe Clock Monitor is enabled, a clock failure will force the device into the power-managed RC_RUN mode and the OSCFIF bit (PIR2<7>) will be set. The ECCP1 will then be clocked from the internal oscillator clock source, which may have a different clock frequency than the primary clock.

See the previous section for additional details.

18.4.11EFFECTS OF A RESET

Both Power-on Reset and subsequent Resets will force all ports to Input mode and the CCP registers to their Reset states.

This forces the Enhanced CCP module to reset to a state compatible with the standard CCP module.

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 203

PIC18F8722 FAMILY

TABLE 18-5:

REGISTERS ASSOCIATED WITH ECCP MODULES AND TIMER1 TO TIMER4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Reset

Name

Bit 7

Bit 6

 

Bit 5

Bit 4

Bit 3

 

Bit 2

Bit 1

Bit 0

 

Values

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

on page

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INTCON

GIE/GIEH

PEIE/GIEL

 

TMR0IE

INT0IE

RBIE

 

TMR0IF

INT0IF

RBIF

 

57

RCON

IPEN

SBOREN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

58

 

RI

TO

PD

POR

BOR

 

PIR1

PSPIF

ADIF

 

RC1IF

TX1IF

SSP1IF

 

CCP1IF

TMR2IF

TMR1IF

 

60

PIE1

PSPIE

ADIE

 

RC1IE

TX1IE

SSP1IE

 

CCP1IE

TMR2IE

TMR1IE

 

60

IPR1

PSPIP

ADIP

 

RC1IP

TX1IP

SSP1IP

 

CCP1IP

TMR2IP

TMR1IP

 

60

PIR2

OSCFIF

CMIF

 

EEIF

BCL1IF

 

HLVDIF

TMR3IF

CCP2IF

 

60

PIE2

OSCFIE

CMIE

 

EEIE

BCL1IE

 

HLVDIE

TMR3IE

CCP2IE

 

60

IPR2

OSCFIP

CMIP

 

EEIP

BCL1IP

 

HLVDIP

TMR3IP

CCP2IP

 

60

PIR3

SSP2IF

BCL2IF

 

RC2IF

TX2IF

TMR4IF

 

CCP5IF

CCP4IF

CCP3IF

 

60

PIE3

SSP2IE

BCL2IE

 

RC2IE

TX2IE

TMR4IE

 

CCP5IE

CCP4IE

CCP3IE

 

60

IPR3

SSP2IP

BCL2IP

 

RC2IP

TX2IP

TMR4IP

 

CCP5IP

CCP4IP

CCP3IP

 

60

TRISB

TRISB7

TRISB6

 

TRISB5

TRISB4

TRISB3

 

TRISB2

TRISB1

TRISB0

 

60

 

 

 

 

 

 

 

 

 

 

 

 

 

TRISC

TRISC7

TRISC6

 

TRISC5

TRISC4

TRISC3

 

TRISC2

TRISC1

TRISC0

 

60

 

 

 

 

 

 

 

 

 

 

 

 

 

TRISE

TRISE7

TRISE6

 

TRISE5

TRISE4

TRISE3

 

TRISE2

TRISE1

TRISE0

 

60

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TRISG

 

TRISG4

TRISG3

 

TRISG2

TRISG1

TRISG0

 

60

TRISH(2)

TRISH7

TRISH6

 

TRISH5

TRISH4

TRISH3

 

TRISH2

TRISH1

TRISH0

 

60

TMR1L

Timer1 Register Low Byte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

58

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TMR1H

Timer1 Register High Byte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

58

 

 

 

 

 

 

 

 

 

 

 

 

 

 

T1CON

RD16

T1RUN

 

T1CKPS1

T1CKPS0

T1OSCEN

 

T1SYNC

 

TMR1CS

TMR1ON

 

58

TMR2

Timer2 Register

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

58

 

 

 

 

 

 

 

 

 

 

 

T2CON

T2OUTPS3

T2OUTPS2

T2OUTPS1

T2OUTPS0

TMR2ON

T2CKPS1

T2CKPS0

 

58

PR2

Timer2 Period Register

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

58

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TMR3L

Timer3 Register Low Byte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

59

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TMR3H

Timer3 Register High Byte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

59

 

 

 

 

 

 

 

 

 

 

 

 

T3CON

RD16

T3CCP2

 

T3CKPS1

T3CKPS0

T3CCP1

 

T3SYNC

 

TMR3CS

TMR3ON

 

59

TMR4

Timer4 Register

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

61

 

 

 

 

 

 

 

 

 

 

 

T4CON

T4OUTPS3

T4OUTPS2

T4OUTPS1

T4OUTPS0

TMR4ON

T4CKPS1

T4CKPS0

 

61

PR4

Timer4 Period Register

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

61

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CCPRxL(1)

Enhanced Capture/Compare/PWM Register x Low Byte

 

 

 

 

 

 

 

 

 

 

 

 

59, 61

CCPRxH(1)

Enhanced Capture/Compare/PWM Register x High Byte

 

 

 

 

 

 

 

 

 

 

 

 

59, 61

CCPxCON(1)

PxM1

PxM0

 

DCxB1

DCxB0

CCPxM3

 

CCPxM2

CCPxM1

CCPxM0

 

59

ECCPxAS(1)

ECCPxASE

ECCPxAS2

ECCPxAS1

ECCPxAS0

PSSxAC1

PSSxAC0

PSSxBD1

PSSxBD0

 

59, 61

ECCPxDEL(1)

PxRSEN

PxDC6

 

PxDC5

PxDC4

PxDC3

 

PxDC2

PxDC1

PxDC0

 

61

Legend:

— = unimplemented, read as ‘0’. Shaded cells are not used during ECCP operation.

Note 1:

Generic term for all of the identical registers of this name for all Enhanced CCP modules, where ‘x’ identifies the

 

individual module (ECCP1, ECCP2 or ECCP3). Bit assignments and Reset values for all registers of the same

 

generic name are identical.

2:This register is not implemented on PIC18F6527/6622/6627/6722 devices.

DS39646B-page 204

Preliminary

2004 Microchip Technology Inc.

Соседние файлы в папке Склад