📄 pwm.dsp
字号:
/****************************************************************************************
* *
* Library: Configuration of PWM block for single update mode *
* File: pwm.dsp *
* *
* Description: pwm code file *
* Purpose : Library routines for PWM block operation *
* *
* Author : JC *
* Version : 1.0 *
* Date : Dec 2001 *
* Modification History: none *
* *
* Embedded Control Systems *
* Analog Devices Inc. *
****************************************************************************************/
#include <main.h>;
/***************************************************************************************
* Calculate Configuration Register Contents from Parameters *
***************************************************************************************/
#define PWM_Period H_clock * 1000 / 2 /PWM_freq
#define PWM_DeadTime Deadtime * H_clock / 1000 / 2 / 1000
#define PWM_syncwidth PWM_syncpulse*H_clock/1000/1000-1
/***************************************************************************************
* Constants Defined in the Module *
***************************************************************************************/
/*none*/
/***************************************************************************************
* Routines Defined in this Module *
***************************************************************************************/
.global PWM_Init_;
/***************************************************************************************
* Global Variables Defined in this Module *
***************************************************************************************/
/* None */
/***************************************************************************************
* Local Variables Defined in this Module *
***************************************************************************************/
/* None*/
/***************************************************************************************
* *
* Type: Routine *
* *
* Call: call PWM_Init_; *
* *
* Initialises the PWM block and produces 50% dutycycle PWM outputs *
* *
* Inputs : Configuration Constants *
* *
* Ouputs : None *
* *
* Modified: AR *
* *
***************************************************************************************/
.section/pm seg_pmcode;
PWM_Init_: // Initialise PWM block
IOPG=PWM0_Page; // page of PWM0 block
ar = PWM_Period;
IO(PWM0_TM)= ar; //write to PWM period register
ar =PWM_DeadTime;
IO(PWM0_DT)= ar; //write to PWM deadtime register
ar =PWM_syncwidth;
IO(PWM0_SYNCWT)= ar;//write to PWMSYNC width register
ar = 0; //50% duty cycle
IO(PWM0_CHA)= ar; //Write duty cycle to Channel A
IO(PWM0_CHB)= ar; //Write duty cycle to Channel B
IO(PWM0_CHC)= ar; //Write duty cycle to Channel C
ar= 0x0003;
IO(PWM0_CTRL)=ar; // enable PWM block, SYNC will be generated after a TRIP
rts;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -