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.

Problem while running CPU timer programm for ADC (launcpad TMS320F28027

Other Parts Discussed in Thread: CONTROLSUITE

Dear 

I am trying to run simple ADC program by using CPU timer prorgamm but I am not getting update value for the variable in watch window

I have added Adc.c file to project from common folder of the example

This are the changes I made to main loop of the existing example programm of CPU timer

EALLOW;
// sampling mode is sequential
AdcRegs.ADCSOC0CTL.bit.CHSEL= 2; //2 A2 2
AdcRegs.ADCSOC0CTL.bit.TRIGSEL= 1; // at first software trigger is kept
AdcRegs.ADCSOC0CTL.bit.ACQPS= 6; //25 is good
AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0= 0; //1 for simultaneous sampling

AdcRegs.SOCPRICTL.bit.SOCPRIORITY= 16;
EDIS;

interrupt void cpu_timer0_isr(void)
{

CpuTimer0.InterruptCount++;
ir_adc= AdcResult.ADCRESULT0;
ir_grid=(ratio_vsen)*((ir_adc*3.3/4096)-dc_offset);
sample[i]=ir_grid;
if(i>7)
{ i=0;}
i++;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

  • Hi Ashutosh,

    Can you explain a bit more in detail... do you get the ADC values or not?

    Ashutosh Pailwan1 said:
    but I am not getting update value for the variable in watch window

    Which variable are you talking about? ir_adc or ir_grid?

    Regards,

    Gautam

  • Both values are not getting updated

  • Is your CPU_timer getting triggered ? Also, check the core ADC result register.

    Hint: Integrate the cpu_timer example code with adc_soc sample code. The only editing you need to do is... remove/disable the ADC interrupt from adc_soc code.

    Regards,

    Gautam

  • Whenever I add the simple gpio clear and set code in CPU timer interrupt routine the gpio don't toggle I am using existing example of cputimrr from control suite in main() loop I have configured the gpio pin while the variable cpuinterruptcounter is updated
  • Please check your GPIO initializations. There's no reason why it shouldn't toggle. Refer GPIO sample code in controlSuite for proper configuration.
  • Dear 

    Still the GPIO is not toggling

    Below is the code for it

    #include "DSP28x_Project.h" // Device Headerfile and Examples Include File

    // Prototype statements for functions found within this file.
    interrupt void cpu_timer0_isr(void);
    interrupt void cpu_timer1_isr(void);
    interrupt void cpu_timer2_isr(void);
    //void Gpio_select(void);

    void main(void)
    {

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

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


    // 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 DSP2802x_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 DSP2802x_DefaultIsr.c.
    // This function is found in DSP2802x_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;
    PieVectTable.TINT1 = &cpu_timer1_isr;
    PieVectTable.TINT2 = &cpu_timer2_isr;
    EDIS; // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize the Device Peripheral. This function can be
    // found in DSP2802x_CpuTimers.c
    InitCpuTimers(); // For this example, only initialize the Cpu Timers
    // Gpio_select();
    #if (CPU_FRQ_60MHZ)
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 60MHz CPU Freq, 1 second Period (in uSeconds)

    ConfigCpuTimer(&CpuTimer0, 60, 1000000);
    ConfigCpuTimer(&CpuTimer1, 60, 1000000);
    ConfigCpuTimer(&CpuTimer2, 60, 1000000);
    #endif
    #if (CPU_FRQ_50MHZ)
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 50MHz CPU Freq, 1 second Period (in uSeconds)

    ConfigCpuTimer(&CpuTimer0, 50, 1000000);
    ConfigCpuTimer(&CpuTimer1, 50, 1000000);
    ConfigCpuTimer(&CpuTimer2, 50, 1000000);
    #endif
    #if (CPU_FRQ_40MHZ)
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 40MHz CPU Freq, 1 second Period (in uSeconds)

    ConfigCpuTimer(&CpuTimer0, 40, 1000000);
    ConfigCpuTimer(&CpuTimer1, 40, 1000000);
    ConfigCpuTimer(&CpuTimer2, 40, 1000000);
    #endif
    // 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 DSP2802x_CpuTimers.h), the
    // below settings must also be updated.

    CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
    CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
    CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0

    // Step 5. User specific code, enable interrupts:
    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; // 0=GPIO, 1=EPWM4A, 2=EPWMSYNCI, 3=EPWMSYNCO
    GpioCtrlRegs.GPADIR.bit.GPIO7 = 1; // 1=OUTput, 0=INput
    GpioDataRegs.GPACLEAR.bit.GPIO7 = 1; // uncomment if --> Set Low initially
    EDIS;

    // 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;
    IER |= M_INT13;
    IER |= M_INT14;

    // 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):
    for(;;);
    //{}
    }


    interrupt void cpu_timer0_isr(void)
    {
    CpuTimer0.InterruptCount++;
    //GpioDataRegs.GPATOGGLE.bit.GPIO7=1;
    GpioDataRegs.GPASET.bit.GPIO7=1;
    // Acknowledge this interrupt to receive more interrupts from group 1
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }

    interrupt void cpu_timer1_isr(void)
    {
    CpuTimer1.InterruptCount++;
    // The CPU acknowledges the interrupt.
    GpioDataRegs.GPACLEAR.bit.GPIO7=1;
    EDIS;
    }

    interrupt void cpu_timer2_isr(void)
    { EALLOW;
    CpuTimer2.InterruptCount++;
    // The CPU acknowledges the interrupt.
    EDIS;

    }

  • Is your CPU timer counts working ???