?? convert_assembak.c
字號:
//###########################################################################
//
// FILE: Example_281xEvPwm.c
//
// TITLE: DSP281x Event Manager PWM Generation.
//
// ASSUMPTIONS:
//
// This program requires the DSP281x V1.00 header files.
// As supplied, this project is configured for "boot to H0" operation.
//
// Other then boot mode pin configuration, no other hardware configuration
// is required.
//
// DESCRIPTION:
//
// This program sets up the EV timers (TIMER1, TIMER2, TIMER3 and TIMER4)
// to generate T1PWM, T2PWM, T3PWM, T4PWM and PWM1-12 waveforms.
// The user can then observe the waveforms using an scope.
//
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 11 Sep 2003 | L.H. | No change since previous version (v.58 Alpha)
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#define ADC_usDELAY 8000L
#define ADC_usDELAY2 20L
#define ADC_CKPS 0x3 // ADC module clock = HSPCLK/2*ADC_CKPS = 25MHz/(1*2) = 12.5MHz
#define ADC_SHCLK 0x0 // S/H width in ADC module periods = 16 ADC clocks
//#define WaveCon(void) DSP28x_WaveCon(void)
// Prototype statements for functions found within this file.
void init_eva(void);
void init_evb(void);
void InitAdc(void);
interrupt void T1PINTIsr(void);
interrupt void T1UFINTIsr(void);
interrupt void T2UFINTIsr(void);
interrupt void ADCINTIsr(void);
// Global counts used in this example
Uint16 sinv[100]={0,58,117,176,234,293,351,409,466,523,579,635,690,744,798,851,903,
954,1004,1053,1102,1149,1195,1239,1283,1325,1366,1406,1444,1481,
1516,1550,1583,1613,1643,1670,1696,1720,1743,1764,1783,1800,
1816,1829,1841,1851,1860,1866,1871,1874,1875,1874,1871,1866,1860,
1851,1841,1829,1816,1800,1783,1764,1743,1720,1696,1670,1643,1613,
1583,1550,1516,1481,1444,1406,1366,1325,1283,1239,1195,1149,1102,
1053,1004,954,903,851,798,744,690,635,579,523,466,409,351,293,234,
176,117,58};
Uint16 step,CMPR_LAST,CMPR_LAST1;
Uint16 UD,UDK;
Uint16 IL,ILK_H,ILK_L;
Uint16 Io,IoK_L,IoK_H;
Uint16 Uo,UoK_L,UoK_H;
Uint16 AX,BX,CX;
Uint16 CM[16],energy_step,CM_largest,CM_larger;
int16 DIF;
int32 CM_energy,CM_energy_last;
float M;
//union FLAG_REG FLAG1;
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Initialize only GPAMUX and GPBMUX for this test
EALLOW;
// Enable PWM pins
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins
GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.T1PINT = &T1PINTIsr;
PieVectTable.T1UFINT = &T1UFINTIsr;
PieVectTable.T2UFINT = &T2UFINTIsr;
PieVectTable.ADCINT=&ADCINTIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
init_eva();
init_evb();
//---------------------------------------------------------------------------
// InitAdc:
//---------------------------------------------------------------------------
// This function initializes ADC to a known state.
//
InitAdc();
// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = 0;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; //ADC_CKPS;
AdcRegs.ADCTRL1.bit.CPS =0; //1;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 0; // Setup continuous run
// Step 5. User specific code, enable interrupts:
EALLOW;
PieCtrlRegs.PIECRTL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER1.bit.INTx6=1; // PIE Group 1, INT6,ADCINT
PieCtrlRegs.PIEIER2.bit.INTx4=1; // PIE Group 2, INT4,T1PINT
PieCtrlRegs.PIEIER2.bit.INTx6=1; // PIE Group 2, INT6,T1UFINT
PieCtrlRegs.PIEIER3.bit.INTx3=1; // PIE Group 3, INT3,T2UFINT
IER = 0x0007; // Enable CPU INT1,INT2,INT3
// Set I/O
GpioMuxRegs.GPFMUX.bit.MFSXA_GPIOF10 =0;
GpioMuxRegs.GPFDIR.bit.GPIOF10 =1; //SET FPIOF10 AS OUTPUT PIN
GpioDataRegs.GPFDAT.all=0x0000;
//GpioMuxRegs.GPFDIR.bit.GPIOF11 =1; //SET FPIOF10 AS OUTPUT PIN
EINT;
EDIS;
// initialize the variable
flag_regs.flag1.bit.CM_start=0;
CM_energy_last=0;
CM_energy=0;
energy_step=512;
step=0;
M=0.8;
UoK_L=0;
UoK_H=0;
DIF=25;
CM_largest=CM_larger=0;
// Just sit and loop forever:
// PWM pins can be observed with a scope.
while(1)
{
if (energy_step==0)
{
if (flag_regs.flag1.bit.CM_start==1)
{
if (CM_energy>CM_energy_last)
{
if (flag_regs.flag1.bit.ad_dire==1)
{flag_regs.flag1.bit.ad_dire=0;}
else
{flag_regs.flag1.bit.ad_dire=1;}
}
if (flag_regs.flag1.bit.ad_dire==0)
{DIF=DIF+2;}
else
{DIF=DIF-2;}
if (DIF>40)
{DIF=40;}
else if (DIF<-8)
{DIF=-8;}
}
flag_regs.flag1.bit.CM_start=1;
CM_energy_last=CM_energy;
CM_energy=0;
energy_step=512;
DIF=25;
}
};
}
void init_eva()
{
// EVA Configure T1PWM, T2PWM, PWM1-PWM6
// Initalize the timers
// Initalize EVA Timer1
EvaRegs.T1PR = 0x1D4C; // Timer1 period
EvaRegs.T1CMPR = 0x1C00; // Timer1 compare
EvaRegs.T1CNT = 0x0000; // Timer1 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T1CON.all = 0x0843;
// Initalize EVA Timer2
EvaRegs.T2PR = 0x0EA6; // Timer2 period
EvaRegs.T2CMPR = 0x03C0; // Timer2 compare
EvaRegs.T2CNT = 0x0000; // Timer2 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x0000;
// Setup T1PWM and T2PWM
// Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.TCMPOE = 0;
// Polarity of GP Timer 1 Compare = Active low
EvaRegs.GPTCONA.bit.T1TOADC=0;
EvaRegs.GPTCONA.bit.T2TOADC=1;
//T2UFINT starts ADC
EvaRegs.GPTCONA.bit.T1PIN = 1;
// Polarity of GP Timer 2 Compare = Active high
EvaRegs.GPTCONA.bit.T2PIN = 2;
// Enable compare for PWM1-PWM6
EvaRegs.CMPR1 = 0x0400;
EvaRegs.CMPR2 = 0x0400;
EvaRegs.CMPR3 = 0x0400;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -