Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale...

15
Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005. TM AW60 Low Level Driver Design Training Freescale Semiconductor Inc

Transcript of Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale...

Page 1: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

TM

AW60 Low Level Driver Design Training

Freescale Semiconductor Inc

Page 2: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 2

Agenda

• Timer/PWM Module (TPM) TPM Block Diagram Overview of TPM Functionality Architectural Components Modes of Operation Architectural Components Interface

• Demo Code Implement PWM and CPWM on the AW60 EVB.

Page 3: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

TM

Timer/PWM Module (TPM)

Page 4: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 4

TPM Block Diagram

Page 5: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 5

TPM Function Overview

Input Capture (IC)

Output Compare (OC)

PWM

CPWM

When the CPWM control bit CPMWS In TPM status and control register Is cleared, each channel In TPM can be

configured 1 of 3 functionality listed In

left box

When the CPWM control bit CPMWS In TPM status and control

register Is set, all channels In TPM will

be configured In CPWM functionality

CPWMS0 1

Page 6: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 6

Architectural Components

TPM1

TPM1SC

TPM1CnVH:L

TPM1CnSC

TPMMODH:L

TPM1CNTH:L

TPM1CLK

TPM1CH0

TPM1CH1

TPM1CH2

TPM1CH3

TPM1CH4

TPM1CH5

Clock source/prescaler

TPM counter

TPM modulo value

Channel function select

Channel value

TPM1 Registers TPM1 PinsH/W Layer

LLD Layer

Char TPM_Init(TPMConfig* tpm1cfg)

void isr_TMR1_Chnl1(void);

Char InputCapture(UCHAR IC_Chnl,UCHAR IC_Mode,void (*CaptureEvent)(void))

Void TPM1_Disable(void)

Void TPM1_Enable(void)

Char OutputCompare(UCHAR OC_Chnl,UCHAR OC_Mode,UINT ChnlVal,void (*CompareEvent)(void))

HAL Layer

Char TPMChnl_Init(TPMChnlConfig* TPMChnlCfg);

Page 7: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 7

Modes of Operation

Mode, Edge and Level Selection

Page 8: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 8

Architectural Components Interface

Operation Level Function Name

Module Level char TPM_Init(TPMConfig* TPMCfg);

Module Events1.void isr_TMR1_OV(void);

2.void isr_TMR2_OV(void);

Channel Level

1. char TPMChnl_Init(TPMChnlConfig* TPMChnlCfg);

2. char InputCapture(UCHAR IC_Chnl,UCHAR IC_Mode,void (*CaptureEvent)(void));

3. char OutputCompare(UCHAR OC_Chnl,UCHAR OC_Mode,UINT ChnlVal,void (*CompareEvent)(void));

4. char PWM(UCHAR PWM_Chnl,UCHAR PWM_Mode,UINT ChnlVal,void (*PWMEvent)(void));

5. char CPWM(UCHAR CPWM_Chnl,UCHAR CPWM_Mode,UINT ChnlVal,void (*CPWMEvent)(void));

Channel Events

1.void isr_TMR1_Chnl0(void);

2.void isr_TMR1_Chnl1(void);

3.void isr_TMR1_Chnl2(void);

4.void isr_TMR1_Chnl3(void);

5.void isr_TMR1_Chnl4(void);

6.void isr_TMR1_Chnl5(void);

7.void isr_TMR2_Chnl0(void);

8.void isr_TMR2_Chnl1(void);

Page 9: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 9

TPM module configuration structure

typedef struct TPMConfig_t

{

UCHAR TPM;

UCHAR CPWMS;

UCHAR ClkSrc;

UCHAR Prescaler;

UINT reg_TPMMOD;

void (*TPMEvent)(void);

}TPMConfig;

Note:

void (*TPMEvent)(void) is the function pointer pointing to user application space associated to the TPM interruption.

Structure Members Description

UCHAR TPM TPM module selection bit, 1: TPM1, 2 : TPM2

UCHAR CPWMS CPWM select bit, 1:CPWMS,0:other functions

UCHAR ClkSrc TPM clock source select

UCHAR Prescaler prescaler of TPM

UINT reg_TPMMOD the variable in flash to store the configuration of TPMMODH:L

void (*TPMEvent)(void)the function pointer points to the events invoked upon the interruption

of TPM

Page 10: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 10

TPM channel configuration structure

typedef struct TPMChnlConfig_t

{

UCHAR Channel;

UCHAR Mode;

UINT reg_TPMCnV;

void (*ChnlEvent)(void);

}TPMChnlConfig;

Structure Members Description

UCHAR Channel TPM channel selection, refer to the tpm_drv.h

UCHAR Mode Channel mode selection, refer to the tpm_drv.h

UINT reg_TPMCnV Channel value will pass to the register of TPMCnV

void (*ChnlEvent)(void) Function pointer points to the events invoked upon the

interruption of corresponding channel

Note:void (*ChnlEvent)(void) is the function pointer pointing to user application

associated to the corresponding TPM channel interruption.

Page 11: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 11

Demo Code of TPM

• void main(void) • { • UCHAR icgmode,pt,re; • EnableInterrupts; //enable interrupts• • /* include your code here */• • /*GPIO test code */• pt = GPIO_InitPort(PORTA,&paconfig);• pt = PTAD; • pt = GPIO_SetPin(PORTA,PIN4);• pt = PTAD;• • /*ICG test code*/• ICG_Init(&icgconfig);• icgmode = Get_ICG_Mode();• • /*TPM test code*/• re = TPM_Init(&tpm1cfg); //tpm1 module initialization• re = PWM(CHNL10,CPWM_CO,200,NULL); //edge-aligned pwm,clear output on compare• • • for(;;) • { • __RESET_WATCHDOG(); /* feeds the dog */• } /* loop forever */• /* please make sure that you never leave this function */• }

Page 12: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 12

PWM Wave Capture

Page 13: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 13

CPWM Wave Capture

Page 14: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 14

Thanks

Page 15: Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All.

TM Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.

Slide 15

Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.