Tool/software:
I'm trying to measure the the ADC values with the interrupt of ePWM. ePWM is initialized well and counting upwards and doing it's function. But somehow it ain't triggering the ADC to take samples. Attached is my program that I'm trying to run. Need your thoughts or improvements that'd be required to run this code. I'm very new with TI's DSP i don't know much about it yet.
#include "DSP28x_Project.h"
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
//
// HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
//
#define ADC_MODCLK 0x3
#endif
#if (CPU_FRQ_100MHZ)
//
// HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
//
#define ADC_MODCLK 0x2
#endif
//
// ADC module clock = HSPCLK/2*ADC_CKPS = 25.0MHz/(1*2) = 12.5MHz
//
#define ADC_CKPS 0x1
// Prototype statements for functions found within this file.
__interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[10];
Uint16 Voltage2[10];
void main(void)
{
Uint32 delay;
/* Initialize the ADC Clocks*/
InitSysCtrl();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
DINT; // Disable CPU interrupt
//
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags
//
IER = 0x0000;
IFR = 0x0000;
IER |= M_INT1;
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 register
PieVectTable.ADCINT = &adc_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
InitAdc();
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv.
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 1; // Trigger Interrupt at every Sequence
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EALLOW; // This is needed to write to EALLOW protected registers
// Set up ePWM1 in up/down count mode
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up/down mode
EPwm1Regs.TBPRD = 5000; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0001; // Clear counter
// Set Compare values
EPwm1Regs.CMPA.half.CMPA = 2500; // Set compare A value
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on event A, up count
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM1A on event A, down count
// Trigger ADC
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; // Select SOC from counter zero event
EPwm1Regs.ETPS.bit.SOCAPRD = ET_1ST; // Generate pulse on 1st event
EDIS; // Disable write to EALLOW protected registers
AdcRegs.ADCTRL2.all = (1<<13);
// Configure GPIO34 as a GPIO output pin
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
EDIS;
while(1)
{
// Toggle LED
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
// Delay for a bit
for(delay = 0; delay < 2000000; delay++);
}
}
// Definition of ISR function for ADC interrupt
__interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount] = AdcRegs.ADCRESULT1 >>4;
// If 9 conversions have been logged, start over
if(ConversionCount == 9)
{
ConversionCount = 0;
}
else
{
ConversionCount++;
}
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
During debugging I see that ADCTRL1 = 0x0000;
I put a breakpoint in the adc_isr to see if it reaches there and it never hits that break point.