Other Parts Discussed in Thread: C2000WARE
Since my customer can't post on the forum, I submit a question for him.
"I am using a TMDSPREX28335 board and I am trying to dump two signals:
1) an external 50 Hz sinusoidal signal ranging between 1 Volt and 2 Volt
2) a DC signal which is 1 V
After converting the signals in a proper manner I tried to watch the external AC signal and an internally generated unit amplitude 50 Hz sine wave in the same graph window. I found two anomalies while viewing the externally dumped 50 Hz signal in the graph window. They are as follows:
a) The frequency is much more than 50 Hz
b) The data is not getting logged properly and there are abrupt discontinuities in the obtained plot
The code that I am using for ADC initialization, sine wave generation and plotting the data is as follows:
// Global variables used in this example
Uint32 EPwm3TimerIntCount, EPwm5TimerIntCount, CpuTimer0IntCount = 1;
float duty = 0.405, omega = 2*3.1415926535*50, ref_sine = 0, time = 0, ref_sine_offset = 0, wt = 0, wt_offset = 0;
float ref_sine_n = 0, ref_sine_offset_n = 0;
float voltage_grid = 0, voltage_pv = 0, current_grid = 0, current_pv = 0, voltage_offset = 0;
// Variables used for plotting
int plot_count = 0, sample = 0;
float array_sine[400][2], array_sine_offset[400];
void main(void)
{
InitSysCtrl();
DINT; // disable CPU interrupts
InitPieCtrl(); // disable all peripheral interrupts
InitEPwmTimer(); // initiate the required ePWM registers and configure interrupt requirements
IER = 0x0000; // disables all interrupts
IFR = 0x0000; // clears flags of all interrupts
InitPieVectTable();
//************ADC INITIALISATION and CONFIGURATION BEGINS************//
InitAdc(); // basic ADC setup (including calibration)
AdcRegs.ADCTRL1.all = 0; // clear ADCTRL1 before initializing
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; // sample and hold for (15+1)=16 ADC cycles
AdcRegs.ADCTRL1.bit.CPS = 0; // divide further by 1
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // continuous run mode for ADC
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascaded mode for ADC (16 states)
AdcRegs.ADCTRL2.all = 0; // clear ADCTRL2 before initializing
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // start SEQ1
// AdcRegs.ADCTRL2.bit.RST_SEQ2 = 1; // reset SEQ2
// AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // enable interrupt on SEQ1
AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // sequential simultaneous conversion for ADC
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // 3 because from DSP2833x_SysCtrl.c FCLK for ADC is 75 MHz and not 150 MHz;
// 75/(2*3) = 12.5 MHz
AdcRegs.ADCMAXCONV.all = 0x0001; // 2 conversions
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x2; // assign ADCINA2 to conv00
// AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0xa; // assign ADCINB2 to conv01
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x3; // assign ADCINA3 to conv02
// AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 11; // assign ADCINB3 to conv03
// AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 4; // assign ADCINA4 to conv04
//************ADC INITIALISATION and CONFIGURATION ENDS************//
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.EPWM3_INT = &epwm3_timer_isr;
PieVectTable.EPWM5_INT = &epwm5_timer_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0, 150, 25); // generate TINT0 at 25 us or 40 kHz
CpuTimer0Regs.TCR.all = 0x4000;
// Initialize counters:
EPwm3TimerIntCount = 1;
EPwm5TimerIntCount = 1;
IER |=1; // enable timer0 interrupt
IER |=4; // enable INT3 for ePWM3 and ePWM5
/* Enable TINT0
// Enable EPWM3A INT in the PIE: Group 3 interrupt 3
// Enable EPWM5A INT in the PIE: Group 3 interrupt 5
*/
PieCtrlRegs.PIEIER1.bit.INTx7=1;
PieCtrlRegs.PIEIER3.bit.INTx3=1;
PieCtrlRegs.PIEIER3.bit.INTx5=1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0IntCount++;
//****************************READ VALUES FROM ADC BEGINS****************************//
voltage_grid = AdcRegs.ADCRESULT0>>4; // read grid voltage from ADCINA2 into voltage_grid from ADCResult2 register
current_grid = AdcRegs.ADCRESULT1>>4; // read grid current from ADCINB2 into current_grid from ADCResult3 register
// voltage_pv = AdcRegs.ADCRESULT6>>4; // read pv voltage from ADCINA3 into voltage_pv from ADCResult6 register
// current_pv = AdcRegs.ADCRESULT7>>4; // read pv current from ADCINB3 into current_pv from ADCResult7 register
// voltage_offset = AdcRegs.ADCRESULT8>>4; // read reference voltage from ADCINA4 into voltage_offset from ADCResult8 register
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // clear interrupt generated by SEQ1
//****************************READ VALUES FROM ADC ENDS****************************//
if (time > 0.02)
time=0;
wt = omega*time;
wt_offset = omega*(time - 0.0001); // offset of 100 microseconds for the second sine wave
ref_sine = fabs((sin(wt)));
ref_sine_n = sin(wt);
ref_sine_offset = fabs(sin(wt_offset));
ref_sine_offset_n = sin(wt_offset);
if (plot_count == 0)
{
if(sample > 399)
sample = 0;
array_sine[sample][0] = voltage_grid/1000;
array_sine[sample][1] = ref_sine_n;
array_sine_offset[sample] = ref_sine_offset_n;
sample++;
plot_count = 2;
}
plot_count--;
time = time + 0.000025;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
And the plot in question is as follows:

As you can see the data is not getting logged properly and compared to the internal sine, the sine obtained from ADC is at least 5 times faster."
Thank you very much for your help.
Best regards,
