📄 main.dsp
字号:
/****************************************************************************************
* *
* Application: ADC block initialisation and usage: Generate three-phase sinewaves *
* File: Main.dsp *
* *
* Description: main program file *
* Purpose : *
* *
* Author : JC *
* Version : 1.0 *
* Date : Mar 2002 *
* Modification History: none *
* *
* Embedded Control Systems *
* Analog Devices Inc. *
****************************************************************************************/
/****************************************************************************************
* Include General System Parameters and Libraries *
****************************************************************************************/
#include <main.h>;
#include <pwm.h>;
#include <trigono.h>;
#include <adc.h>
/****************************************************************************************
* Constants defined in this code *
****************************************************************************************/
#define Two_PI 65536
#define Two_PI_Over_Three Two_PI / 3
#define Fundamental_freq 60 //Desired fundamental frequency [Hz]
#define Theta_Increment Fundamental_freq*Two_PI/PWM_freq
/****************************************************************************************
* Global Routines defined in this code *
****************************************************************************************/
.global start;
/****************************************************************************************
* Global Variables defined in this code *
****************************************************************************************/
/*None*/
/****************************************************************************************
* Local Variables defined in this code *
****************************************************************************************/
.section/data seg_dmdata;
.VAR Theta = 0;// current phase angle [from -pi to pi]
.VAR Amplitude_factor =0x7fff;// scaling factor of amplitude
.VAR PWM_TM_maxvalue;
.VAR Scaled_amplitude;
/****************************************************************************************
* Start of program code *
****************************************************************************************/
.section/pm seg_pmcode;
start:
dmpg1 = 0; // setting data memory indirect access to accessing internal memory, i.e. page 0
dmpg2 = 0;
ijpg = 0; // setting indirect jump page to accessing internal memory, i.e. page 0
ar = 0;
DM(Theta) = ar; // reset angle
dis int; //disable interrupts
PWM_Init(PWM_Trip_Isr, PWM_Sync_Isr); //initialize PWM blocks and setting up ADC end of conversion (instead of PWMSYnc) and PWM trip interrupts
ADC_Init(ADC_Number_of_samples, ADC_EOC_Isr);//Initialise ADC interrupt and calculate the offset values and assign ADC EOC interrupt to USR2
iopg= PWM0_Page;
ar = IO(PWM0_TM); // calculate the maximum duty cycle value, from (-PWMTM/2-PWMDT) to (PWMTM/2 + PWMDT)
sr = lshift ar by -1 (LO); // divide PWMTM by 2
ax0 = IO(PWM0_DT);
ar = sr0 + ax0;
DM(PWM_TM_maxvalue) = ar; // store maximum duty cycle value
ar =0;
IRPTL = ar; // clear pending interrupts
ar = IMASK;
ay0=0xFFDF;
ar=ar and ay0; //disable USR1
ay0 = 0x0050; /* enable USR0 and USR2*/
ar = ar or ay0;
IMASK = ar;
ena int; //enable interrupts
Main:
jump Main;
/****************************************************************************************
*ADC_EOC interrupt service routine *
****************************************************************************************/
ADC_EOC_Isr:
iopg=ADC_Page; //write 1 to clear ADC EOC interrupt
ar=0x0100;
IO(ADC_STAT)=ar;
ADC_Read(ADC_DATA0, Offset_0to3); //read amplitude factor from ADC VIN0, result stored in ar
DM(Amplitude_factor)=ar;
my0=DM(PWM_TM_maxvalue);
mr=ar*my0(ss); // scale the amplitude, with amplitude_factor = (PWMTM/2-PWMDT)/(PWMTM/2+PWMDT) maximum scaling without overmodulation
DM(Scaled_amplitude)=mr1;
iopg = PWM0_Page;
Set_DAG_registers_for_trigonometric;
ax0 = DM(Theta); // load current angle
ay0 = Theta_Increment; // Theta is saved in ax0 so may just increment angle now
ar = ax0 + ay0;
DM(Theta) = ar; // store for next cycle
Sin(ax0); // phase A (result in ax1)
my0 = DM(Scaled_amplitude); // contains maximum value for dutycycle registers (PWMTM/2+Deadtime)xamplitude_factor
mr = ax1 * my0 (SS); //calculate duty cycle for channel A
IO(PWM0_CHA)= mr1; // load duty in channel A
ay0 = Two_PI_Over_Three; // phase B
ar = ax0 - ay0;
Sin(ar); // phase B (result in ax1)
my0 = DM(Scaled_amplitude); // contains maximum value for dutycycle registers (PWMTM/2+Deadtime)xamplitude_factor
mr = ax1 * my0 (SS); //calculate duty cycle for channel B
IO(PWM0_CHB)= mr1; // load duty in channel B
ay0 = Two_PI_Over_Three; // phase C
ar = ax0 - ay0;
Sin(ar); // phase C (result in ax1)
my0 = DM(Scaled_amplitude); // contains maximum value for dutycycle registers (PWMTM/2+Deadtime)xamplitude_factor
mr = ax1 * my0 (SS); //calculate duty cycle for channel C
IO(PWM0_CHC)= mr1; // load duty in channel C
rti;
/****************************************************************************************
*PWMSYNC interrupt service routine *
****************************************************************************************/
PWM_Sync_Isr:
/* this PWM SYNC interrupt service routine is not enabled here
user can enable it by enabling USR1 in the IMASK register*/
// iopg = PWM0_Page; //set io page to PWM page, remove the // sign of these 3 lines if PWM_Sync interrupt is enabled
// ar = 0x0200; // Write 1 to clear interrupt
// IO(PWM0_STAT) = ar;
rti;
/****************************************************************************************
*PWMTRIP interrupt service routine *
****************************************************************************************/
PWM_Trip_Isr:
iopg = PWM0_Page;//set io page to PWM page
ar = 0x0100; // W1 to clear PWMTRIP interrupt status
IO(PWM0_STAT) = ar;
nop;// user can implement the PWM trip interrupt in this routine, here no operation is implemented.
rti;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -