Hi all forum people, I have any problem.
The program when execute in the ezdsp emulator don't entry in timer interrupt.
The program mix timer and ADC, is posible that the problem is in the configuration interrupt table?
Anybody can make any suggestion?
I put below the program
// TI File $Revision: /main/4 $
// Checkin $Date: 3 agosto 2010 23:29 $
//###########################################################################
//
// FILE: Example_2833xAdcSeqModeTest_5.c
//
// TITLE: DSP2833x ADC Seq Mode Test.
//
// ASSUMPTIONS:
//
// This program requires the DSP2833x header files.
//
// Make sure the CPU clock speed is properly defined in
// DSP2833x_Examples.h before compiling this example.
//
// Connect the signal to be converted to channel A0, A1, A3.
//
// As supplied, this project is configured for "boot to SARAM"
// operation. The 2833x Boot Mode table is shown below.
// For information on configuring the boot mode of an eZdsp,
// please refer to the documentation included with the eZdsp,
//
// $Boot_Table:
//
// GPIO87 GPIO86 GPIO85 GPIO84
// XA15 XA14 XA13 XA12
// PU PU PU PU
// ==========================================
// 1 1 1 1 Jump to Flash
// 1 1 1 0 SCI-A boot
// 1 1 0 1 SPI-A boot
// 1 1 0 0 I2C-A boot
// 1 0 1 1 eCAN-A boot
// 1 0 1 0 McBSP-A boot
// 1 0 0 1 Jump to XINTF x16
// 1 0 0 0 Jump to XINTF x32
// 0 1 1 1 Jump to OTP
// 0 1 1 0 Parallel GPIO I/O boot
// 0 1 0 1 Parallel XINTF boot
// 0 1 0 0 Jump to SARAM <- "boot to SARAM"
// 0 0 1 1 Branch to check boot mode
// 0 0 1 0 Boot to flash, bypass ADC cal
// 0 0 0 1 Boot to SARAM, bypass ADC cal
// 0 0 0 0 Boot to SCI-A, bypass ADC cal
// Boot_Table_End$
//
// DESCRIPTION:
//
// Canal A0 es convertido para la corriente (ILensed)
// Canal A1 es convertido para la tension de entrada (vi_11)
// Canal A2 es convertido para la tension de salida (vo_11)
//
// Watch Variables:
// ILensed, vi_11, vo_11.
//
//###########################################################################
//
// Original source by: S.S.
// Modificado por: guillermo ruiz magaz
// $TI Release: DSP2833x/DSP2823x C/C++ Header Files V1.31 $
// $Release Date: August 4, 2010 $
//###########################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/2*ADC_CKPS = 25.0MHz/(1*2) = 12.5MHz
#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 16 ADC clocks
#define AVG 1 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 1 // Sample buffer size
// Global variable for this example
Uint16 ILsensed=0; //corriente sensada del inductor
Uint16 vi_11=0; //voltage de entrada
Uint16 vo_11=0; //voltage de salida
Uint16 ILsensed1=0; //variable intermedia para calcular el Ton
float T=15e-6; //T es el periodo que deseamos mantener constante
int control=0;
float calculo_resto_ton=0;
float calculo_toff=0;
float IREF=3686; //corresponde a 2.7 volts
//como me da un error de compilacion pq me dice que n esta definida la funcion del timer
//la pongo aqui abajo
interrupt void cpu_timer0_isr(void);
main()
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Specific clock setting for this example:
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Enable the pin GPIO34 as output
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO pin
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // Output pin
//lineas añadidas guillermo
//GpioDataRegs.GPBSET.bit.GPIO34 = 1; //Set GPIO high
//fin lineas añadidas guillermo
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2833x_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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_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.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitCpuTimers();
InitAdc(); // For this example, init the ADC
// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 0; // 1 Cascaded mode, lo pongo a cero sin modo cascada
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
//codigo guillermo
AdcRegs.ADCMAXCONV.all=0x2; // tres conversiones
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; //añado dos conversiones mas la 1 y la 2
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
//fin codigo guillermo
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
// Step 5. User specific code, enable interrupts:
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
// Step 6. inicializo el sistrema con el mosfet en OFF
//control lo pongo a -1 para que entre en el default del case, es la condicion inicial
control=0;
//mosfet OFF
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; //Set GPIO down
//duracion timer 10ms para dar tiempo a cargar los condensadores Cin y Cout de la planta.
ConfigCpuTimer(&CpuTimer0, 150, 1000000);
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
for(;;)
{
}
}// fin de main
////////////////////////////////////////////////////////////////////////////
//
interrupt void cpu_timer0_isr(void)
{
//Tomo lectura ADC
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
//la siguiente linea es del ejemplo del timerledblink
//GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Toggle GPIO32
ILsensed =((AdcRegs.ADCRESULT0>>4) );
vi_11 = ((AdcRegs.ADCRESULT1>>4) );
vo_11 = ((AdcRegs.ADCRESULT2>>4) );
//fin lectura ADC
//toma de decisiones segun estemos en un tramo u otro de la corriente IL
switch (control)
{
case 0:{ //esta es la condicion inicial
control=1;
GpioDataRegs.GPBSET.bit.GPIO34 = 1; //Set GPIO high
break;
}//fin caso 0
case 1:{//estamos tramo a,b,c, y en concreto punto a.
ILsensed1=ILsensed; //me guardo esta lectura, la necesitamos para cuandoe estemos en el case1
ConfigCpuTimer(&CpuTimer0, 150, 1);//duracion timer 1us
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
control =2;
GpioDataRegs.GPBSET.bit.GPIO34 = 1; //Set GPIO high
break;
}//fin caso 1
case 2:{ //estamos tramo d,f y en concreto punto d.
//calculo resto TON
calculo_resto_ton=1e-6*((IREF-ILsensed1)/(ILsensed-ILsensed1)) ;
//cargo timer0 con valor calculad0
ConfigCpuTimer(&CpuTimer0, 150, calculo_resto_ton);//duracion timer calculo_resto_ton
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
control =3;
GpioDataRegs.GPBSET.bit.GPIO34 = 1; //Set GPIO high
break;
}//fin caso 2
case 3:{ //estamos en el punto g,h,i,j y en concreto punto h
calculo_toff=T*vi_11/vo_11;
ConfigCpuTimer(&CpuTimer0, 150,calculo_toff );
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
control=1;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; //Set GPIO down
break;
}
}//fin switch
//interrupcion no reentrante
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
}// fin interrupt void cpu_timer0_isr(void)
//===========================================================================
// No more.
//===========================================================================