This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: ADC trigger with cpu timer

Part Number: TMS320F28377S


Hello,

Can anybody tell me where my mistake is. I am trying to trigger adc with cpu timer 0 and the adc isr wont run.

#define _LAUNCHXL_F28377S 1
#include "F28x_Project.h"


#define dac_num 1


//
// Function Prototypes
//
__interrupt void cpu_timer0_isr(void);
void configureDAC();
void ConfigureADC(void);
void SetupADC_TINT(Uint16 channel);
__interrupt void adca1_isr(void);



volatile struct DAC_REGS* DAC_PTR[4] = {0x0,&DacaRegs,&DacbRegs,&DaccRegs};

Uint16 stejt = 0;

void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
    InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
    InitGpio();


//
// 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 F2837xS_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 F2837xS_DefaultIsr.c.
// This function is found in F2837xS_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.ADCA1_INT = &adca1_isr;
    PieVectTable.ADCA_EVT_INT = &adca1_isr;
    PieVectTable.TIMER0_INT = &cpu_timer0_isr;

    EDIS;    // This is needed to disable write to EALLOW protected registers

//
// Step 4. Initialize the Device Peripheral. This function can be
//         found in F2837xS_CpuTimers.c
//
    InitCpuTimers();   // For this example, only initialize the Cpu Timers
    ConfigCpuTimer(&CpuTimer0, 200, 22.675);
    ConfigureADC();

    SetupADC_TINT(2);
    //configureDAC();
//
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 200MHz CPU Freq, 1 second Period (in uSeconds)
//
    //ConfigCpuTimer(&CpuTimer0, 200, 11.338);



//
// To ensure precise timing, use write-only instructions to write to the
// entire register. Therefore, if any of the configuration bits are changed in
// ConfigCpuTimer and InitCpuTimers (in F2837xS_cputimervars.h), the below
// settings must also be updated.
//
    CpuTimer0Regs.TCR.all = 0x4000;


//
// Step 5. User specific code, enable interrupts:
//

//
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
//
    IER |= M_INT1;

//
// Enable TINT0 in the PIE: Group 1 interrupt 7
//
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

//
// Enable global Interrupts and higher priority real-time debug events:
//
    EINT;  // Enable Global interrupt INTM
    ERTM;  // Enable Global realtime interrupt DBGM

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//


    CpuTimer0.RegsAddr->TCR.bit.TIE = 1;
    while(1)
    {
        //GPIO_WritePin(13, stejt);
        //DAC_PTR[dac_num]->DACVALS.all = stejt;

    }
}


__interrupt void cpu_timer0_isr(void)
{
   CpuTimer0.InterruptCount++;
   //stejt = 4095 - stejt;
   //
   // Acknowledge this interrupt to receive more interrupts from group 1
   //
   //stejt = 4000;
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}
void ConfigureADC(void)
{
    EALLOW;

    //
    //write configurations
    //
    AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

    //
    //Set pulse positions to late
    //
    AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;

    //
    //power up the ADC
    //
    AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;

    //
    //delay for 1ms to allow ADC time to power up
    //
    DELAY_US(1000);

    EDIS;
}

void SetupADC_TINT(Uint16 channel)
{


    //
    //Select the channels to convert and end of conversion flag
    //
    EALLOW;
    AdcaRegs.ADCSOC0CTL.bit.CHSEL = 2;  //SOC0 will convert pin A2
    AdcaRegs.ADCSOC0CTL.bit.ACQPS = 14; //sample window is 100 SYSCLK cycles - 12bit
    AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 1; //trigger on CPU Timer 0
    AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
    AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag
    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
    EDIS;
}


interrupt void adca1_isr(void)
{
    //DAC_PTR[dac_num]->DACVALS.all = AdcaResultRegs.ADCRESULT0;
    //stejt = AdcaResultRegs.ADCRESULT2;
    stejt = 4000;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

void configureDAC()
{
    EALLOW;
    DAC_PTR[dac_num]->DACCTL.bit.DACREFSEL = 1;
    DAC_PTR[dac_num]->DACOUTEN.bit.DACOUTEN = 1;
    DAC_PTR[dac_num]->DACVALS.all = 0;
    DELAY_US(10); // Delay for buffered DAC to power up
    EDIS;
}


//
// End of file
//

  • This discussion is a continuation of this thread:

    Hi Nakon,

    Have a read through the interrupt (PIE module) section of the device technical reference manual (spruhx5e).  You can see that these are the two PIE locations of interest:

    You enabled interrupts for row 1 via this command:

    IER |= M_INT1;

    And you enabled the interrupt for cell INT1.7 (CPU timer 0) via this command:

    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    But I don't see a similar command that would enable the interrupt for cell INT1.1 (ADCAINT1)