lle_xgpwm.c

来自「BCM 控制demo源代码」· C语言 代码 · 共 106 行

C
106
字号
/*******************************************************************************/
/**
Copyright (c) 2007 Freescale Semiconductor
\file       lle_Cpu.c
\brief      PWM generation wityh XGATE module
\author     Freescale Semiconductor
\author     B05114
\version    0.1
\date       April/2007
*/
/*******************************************************************************/

/** S12X derivative information */ 
#include <MC9S12XEP100.h> 

/** Variable types and common definitions */
#include "typedefs.h" 

/** Variables and function prototypes for XGATE-PWM generation */
#include "lle_XGPWM.h"


/* Shared variables */
#pragma DATA_SEG SHARED_DATA    
    volatile PWMChannel xPWM_ch[2];    /* Array of PWM channels structs */
#pragma DATA_SEG DEFAULT 


/*******************************************************************************/
/**
* \brief    Periodic interrupt timer initialization
* \author   B05114
* \param    void
* \return   void
*/
void lle_Init_PIT(void)
{            
    PITCFLMT_PITE = 0;      /* Module disabled */
    
    /* Access to configuration data registers for interrupts */ 
    INT_CFADDR =  0x70;         /* Select page containing PIT interrupt */
	INT_CFDATA5_PRIOLVL = 0x01; /* Periodic Time Interrupt, priority 1, */    
    INT_CFDATA5_RQST = 1;       /* routed to XGATE */
    
    PITCFLMT_PITSWAI = 1;   /* PIT stops in wait mode */
    PITCFLMT_PITFRZ = 1;    /* PIT counters stalled in freeze mode */    
     
    PITMUX_PMUX0 = 0;   /* Micro timer 0 connected to PIT channel 0 */
      
    PITINTE_PINTE0 = 1;     /* Channel 0 interrupt enabled */
    
    PITMTLD0 = 0;   /* Micro timer load register initial value */
    
    PITLD0 = 0x00;  /* PIT load register initial value */
        
    PITCE_PCE0 = 1;         /* Enable PIT channel 0 */
     
    PITCFLMT_PFLMT = 1;     /* Force load bits for micro timer 0 */            
    PITCFLMT_PITE = 1;      /* PIT module enabled */ 
}

/*******************************************************************************/
/**
* \brief    PWM duty cycle configuration
* \author   B05114
* \param    
* \return   
*/
void lle_Set_PWM_DutyCycle(PWMChannel volatile *ch,byte duty) 
{
    ch->duty = duty;   
}


/*******************************************************************************/
/**
* \brief    PWM initialization
* \author   B05114
* \param    void
* \return   void
*/
void lle_Init_PWM(void)
{
	// configure PWM channel 0
    // PWM assignment channel vs. HW pin 
    xPWM_ch[0].ddr         = (unsigned char *)(&DDRP);  
    xPWM_ch[0].port        = (unsigned char *)(&PTP);
    xPWM_ch[0].port_mask   = PTP_PTP7_MASK;
    // init value of pwm counter
    xPWM_ch[0].cnt         = 0;                         
    // max value of cnt -> next period
    xPWM_ch[0].period      = 0xFF;                      
    // duty cycle
    xPWM_ch[0].duty        = 0;
   
    // configure PWM channel 1
    xPWM_ch[1].ddr         = (unsigned char *)(&DDRP);  
    xPWM_ch[1].port        = (unsigned char *)(&PTP);
    xPWM_ch[1].port_mask   = PTP_PTP6_MASK;
    xPWM_ch[1].cnt         = 0;                         
    xPWM_ch[1].period      = 0xFF;                      
    xPWM_ch[1].duty        = 0;        
}

/******************************************************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?