Professional Documents
Culture Documents
//
// This example sets up the PLL in x10/2 mode.
//
// For 150 MHz devices (default)
// divides SYSCLKOUT by six to reach a 25.0Mhz HSPCLK
// (assuming a 30Mhz XCLKIN).
//
// For 100 MHz devices:
// divides SYSCLKOUT by four to reach a 25.0Mhz HSPCLK
// (assuming a 20Mhz XCLKIN).
//
// Interrupts are enabled and the ePWM1 is setup to generate a periodic
// ADC SOC on SEQ1. Two channels are converted, ADCINA3 and ADCINA2.
//
// Watch Variables:
//
//
Voltage1[10]
Last 10 ADCRESULT0 values
//
Voltage2[10]
Last 10 ADCRESULT1 values
//
ConversionCount Current result number 0-9
//
LoopCount
Idle loop counter
//###########################################################################
#include "DSP28x_Project.h"
void InitEPwm1Example(void);
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
interrupt void cpu_timer0_isr(void);
interrupt void epwm1_isr(void);
#define
#define
#define
#define
EPWM1_MAX_DB
EPWM1_MIN_DB
DB_UP 1
DB_DOWN 0
0x03FF
0
InitEPwm1Gpio();
/* EALLOW;
// Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3)
25.0 MHz
EDIS;*/
//EALLOW;
//
SysCtrlRegs.WDCR= 0x00AF;
// Re-enable the watchdog
//EDIS;
// 0x00AF to NOT disable the Watchdog, Prescale
r = 64
//
//
//
//
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 DSP2833x_DefaultIsr.c.
This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
InitAdc();
/////////////////////////////////////////////////////////////////////////
AdcRegs.ADCTRL1.all = 0;
AdcRegs.ADCTRL1.bit.ACQ_PS = 7;
// 7 = 8 x ADCCLK
AdcRegs.ADCTRL1.bit.SEQ_CASC =1;
// 1=cascaded sequencer
AdcRegs.ADCTRL1.bit.CPS = 0;
// divide by 1
AdcRegs.ADCTRL1.bit.CONT_RUN = 0;
// single run mode
AdcRegs.ADCTRL2.all = 0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // 1=enable SEQ1 interrupt
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 =1; // 1=SEQ1 start from ePWM_SOCA t
rigger
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0;
of sequence
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3;
* ADCCLKPS
= 20 s
/ 6.667 ns
EPwm2Regs.ETPS.all = 0x0100;
y ePWM2
/*
bit
bit
bit
bit
bit
bit
bit
*/
15-14
13-12
11-10
9-8
7-4
3-2
1-0
00:
00:
00:
01:
0000:
00:
00:
EPWMxSOCB, read-only
SOCBPRD, don't care
EPWMxSOCA, read-only
SOCAPRD, 01 = generate SOCA on first event
reserved
INTCNT, don't care
INTPRD, don't care
EPwm2Regs.ETSEL.all = 0x0A00;
// Enable SOCA to ADC
/*
bit 15
0:
SOCBEN, 0 = disable SOCB
bit 14-12
000:
SOCBSEL, don't care
bit 11
1:
SOCAEN, 1 = enable SOCA
bit 10-8
010:
SOCASEL, 010 = SOCA on PRD event
bit 7-4
0000: reserved
bit 3
0:
INTEN, 0 = disable interrupt
bit 2-0
000:
INTSEL, don't care
*/
/////////////////////////////////////////////////////////////////////////
// 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 register
//PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.EPWM1_INT = &epwm1_isr;
PieVectTable.ADCINT = &adc_isr;
EDIS;
// This is needed to disable write to EALLOW protected registers
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm1Example();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
EPwm1TimerIntCount = 0;
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// InitAdc(); // For this example, init the ADC
//InitCpuTimers();
// Step 5. User specific code, enable interrupts:
/*
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT;
// Enable Global interrupt INTM
ERTM;
// Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x0001;
//
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; //
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; //
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;//
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; //
// Assumes ePWM1 clock is already enabled
EPwm1Regs.ETSEL.bit.SOCAEN = 1;
EPwm1Regs.ETSEL.bit.SOCASEL = 4;
t
EPwm1Regs.ETPS.bit.SOCAPRD = 1;
EPwm1Regs.CMPA.half.CMPA = 0x0080;
EPwm1Regs.TBPRD = 0xFFFF;
EPwm1Regs.TBCTL.bit.CTRMODE = 0;
in InitSysCtrl();
// Enable SOC on A group
// Select SOC from from CPMA on upcoun
// Generate pulse on 1st event
// Set compare A value
// Set period for ePWM1
// count up and start
// CPU Timer 0
// ADC
// start timer0
{
//
//
asm("
NOP");
while(CpuTimer0.InterruptCount <5)
{
// wait for 500 ms
//EALLOW;
//SysCtrlRegs.WDKEY = 0x55;
// Servi
ce watchdog #1
//EDIS;
//}
// Display VR1 voltage
//while(CpuTimer0.InterruptCount <10)
ms
//
{
//EALLOW;
//SysCtrlRegs.WDKEY = 0x55;
ce watchdog #1
//
//EDIS;
}
// Display VR2 voltage
//CpuTimer0.InterruptCount = 0;
}
}
interrupt void epwm1_isr(void)
{
EPwm1Regs.TBPRD = PWM_CYCLE;
if(EPwm1_DB_Direction == DB_UP)
{
if(EPwm1Regs.DBFED < EPWM1_MAX_DB)
{
//EPwm1Regs.DBFED++;
//EPwm1Regs.DBRED++;
}
else
{
//EPwm1_DB_Direction = DB_DOWN;
//EPwm1Regs.DBFED--;
//EPwm1Regs.DBRED--;
}
}
else
{
if(EPwm1Regs.DBFED == EPWM1_MIN_DB)
{
//EPwm1_DB_Direction = DB_UP;
//EPwm1Regs.DBFED++;
//EPwm1Regs.DBRED++;
}
else
{
//EPwm1Regs.DBFED--;
//EPwm1Regs.DBRED--;
}
}
EPwm1TimerIntCount++;
// Servi
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
// Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4;
// Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV4;
EPwm1Regs.CMPCTL.bit.SHDWAMODE
EPwm1Regs.CMPCTL.bit.SHDWBMODE
EPwm1Regs.CMPCTL.bit.LOADAMODE
EPwm1Regs.CMPCTL.bit.LOADBMODE
=
=
=
=
CC_SHADOW;
// Load registers every ZERO
CC_SHADOW;
CC_CTR_ZERO;
CC_CTR_ZERO;
// Setup compare
//EPwm1Regs.CMPA.half.CMPA = (Uint32)(duty_cycle * PWM_CYCLE);
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAD = AQ_SET;
// service WD #2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
interrupt void adc_isr(void){
Voltage1 = AdcMirror.ADCRESULT0;
//Voltage2 = AdcMirror.ADCRESULT1;
//Voltage3 = AdcMirror.ADCRESULT2;
//Voltage4 = AdcMirror.ADCRESULT3;
// If 40 conversions have been logged, start over
/*if(ConversionCount == 9){
ConversionCount = 0;
}
else ConversionCount++;*/
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
return;
}
// Reset SEQ1
// Clear INT SEQ1 bit
// Acknowledge interrupt to PIE