pwm.c

来自「MC56F802BLDC 可以使用的算法 就是电机启动有点慢」· C语言 代码 · 共 115 行

C
115
字号
/******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2001 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
*******************************************************************************
*
* FILE NAME: pwm.c   
*
* DESCRIPTION: Source file for PWM Driver
*
* MODULES INCLUDED: types.h
*                   arch.h
*                   periph.h
*                   mc.h
*                   appconfig.h
*                   pwm.h
*
* NOTES:
*
*******************************************************************************/

#include "types.h"
#include "arch.h"
#include "periph.h"
#include "mc.h"

#include "appconfig.h"
#include "pwm.h"


/********************************************************************************
 pwmInit() function performs the PWM module static configuration
 based on the configurable items from appconfig.h 
********************************************************************************/
void pwmInit(arch_sPWM *pPwmBase)
{
           if(pPwmBase == PWM_A)
           {  
               #ifdef PWM_A_FAULT_CONTROL_REG
                  	periphMemWrite(PWM_A_FAULT_CONTROL_REG, &ArchIO.PwmA.FaultControlReg);
               #endif
               #ifdef PWM_A_FAULT_STATUS_REG
                  	periphMemWrite(PWM_A_FAULT_STATUS_REG, &ArchIO.PwmA.FaultStatusReg);
               #endif
               #ifdef PWM_A_COUNTER_MODULO_REG
                  	periphMemWrite(PWM_A_COUNTER_MODULO_REG, &ArchIO.PwmA.CounterModuloReg);
               #endif
               #ifdef PWM_A_DEAD_TIME_REG
                  	periphMemWrite(PWM_A_DEAD_TIME_REG, &ArchIO.PwmA.DeadtimeReg);
               #endif
               #ifdef PWM_A_DISABLE_MAPPING_1_REG
                  	periphMemWrite(PWM_A_DISABLE_MAPPING_1_REG, &ArchIO.PwmA.DisableMapping1Reg);
               #endif
               #ifdef PWM_A_DISABLE_MAPPING_2_REG
                  	periphMemWrite(PWM_A_DISABLE_MAPPING_2_REG, &ArchIO.PwmA.DisableMapping2Reg);
               #endif
               #ifdef PWM_A_CHANNEL_CONTROL_REG
                  	periphMemWrite(PWM_A_CHANNEL_CONTROL_REG, &ArchIO.PwmA.ChannelControlReg);
               #endif
               #ifdef PWM_A_CONFIG_REG
                  	periphMemWrite(PWM_A_CONFIG_REG, &ArchIO.PwmA.ConfigReg);
               #endif
               #ifdef PWM_A_OUTPUT_CONTROL_REG
                  	periphMemWrite(PWM_A_OUTPUT_CONTROL_REG, &ArchIO.PwmA.OutputControlReg);
               #endif
               #ifdef PWM_A_CONTROL_REG
                  	periphMemWrite(PWM_A_CONTROL_REG, &ArchIO.PwmA.ControlReg);
					if((PWM_A_CONTROL_REG & PWM_LDOK) > 0 )  /* Load OK set inside GCT */
                  	    periphBitSet(PWM_LDOK, &ArchIO.PwmA.ControlReg);
               #endif

            }
            #if( defined(DSP56F805) || defined(DSP56F807) )
            else if(pPwmBase == PWM_B)
            {  
               #ifdef PWM_B_FAULT_CONTROL_REG
                  	periphMemWrite(PWM_B_FAULT_CONTROL_REG, &ArchIO.PwmB.FaultControlReg);
               #endif
               #ifdef PWM_B_FAULT_STATUS_REG
                  	periphMemWrite(PWM_B_FAULT_STATUS_REG, &ArchIO.PwmB.FaultStatusReg);
               #endif
               #ifdef PWM_B_COUNTER_MODULO_REG
                  	periphMemWrite(PWM_B_COUNTER_MODULO_REG, &ArchIO.PwmB.CounterModuloReg);
               #endif
               #ifdef PWM_B_DEAD_TIME_REG
                  	periphMemWrite(PWM_B_DEAD_TIME_REG, &ArchIO.PwmB.DeadtimeReg);
               #endif
               #ifdef PWM_B_DISABLE_MAPPING_1_REG
                  	periphMemWrite(PWM_B_DISABLE_MAPPING_1_REG, &ArchIO.PwmB.DisableMapping1Reg);
               #endif
               #ifdef PWM_B_DISABLE_MAPPING_2_REG
                  	periphMemWrite(PWM_B_DISABLE_MAPPING_2_REG, &ArchIO.PwmB.DisableMapping2Reg);
               #endif
               #ifdef PWM_B_CHANNEL_CONTROL_REG
                  	periphMemWrite(PWM_B_CHANNEL_CONTROL_REG, &ArchIO.PwmB.ChannelControlReg);
               #endif
               #ifdef PWM_B_CONFIG_REG
                  	periphMemWrite(PWM_B_CONFIG_REG, &ArchIO.PwmB.ConfigReg);
               #endif
               #ifdef PWM_B_OUTPUT_CONTROL_REG
                  	periphMemWrite(PWM_B_OUTPUT_CONTROL_REG, &ArchIO.PwmB.OutputControlReg);
               #endif
               #ifdef PWM_B_CONTROL_REG
                  	periphMemWrite(PWM_B_CONTROL_REG, &ArchIO.PwmB.ControlReg);
					if((PWM_B_CONTROL_REG & PWM_LDOK) > 0 )  /* Load OK set inside GCT */
                  	    periphBitSet(PWM_LDOK, &ArchIO.PwmB.ControlReg);
               #endif
            }
            #endif
            
         return;
}

⌨️ 快捷键说明

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