Hi,
I'm programming a TMS320F28026 and am suspecting a wrong CPU configuration or calibration. I am setting the following:
CLK_setOscSrc(handles.clk, CLK_OscSrc_Internal);
....
PLL_setup(handles.pll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
PLL_enable(handles.pll);
....
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*Device_cal)();
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;
EDIS;
With this configuration, I get a timer that interrupts on the set timeout correctly and PWMs that have the correct frequency. This leads me to believe that at least the peripherals are clocked correctly.
On the other hand, I see very slow operations with relation to the ADC. The ADCs are configured as follows:
ADC_enableBandGap(handles.adc);
ADC_enableRefBuffers(handles.adc);
ADC_powerUp(handles.adc);
ADC_enable(handles.adc);
ADC_setVoltRefSrc(handles.adc, ADC_VoltageRefSrc_Ext);
...
/*
* configure ADC itself
*
* Note: The first of each chain of conversions will be double sampled
* to workaround the ADC 1st sample issue for rev0 silicon errata. If the
* results of a chain start with SOCX, then ADC_forceConversion with
* ADC_SocNumber_(X-1) must be called.
*
* Note: the revision in use is 0 (read the microcontroller's errata)
*/
ADC_setIntPulseGenMode(handles.adc, ADC_IntPulseGenMode_Prior); /* ADCINT* trips after AdcResults latch */
ADC_enableInt(handles.adc, ADC_IntNumber_1);
ADC_enableInt(handles.adc, ADC_IntNumber_2);
ADC_setIntMode(handles.adc, ADC_IntNumber_1, ADC_IntMode_ClearFlag); /* Disable ADCINT1 continuous mode */
ADC_setIntMode(handles.adc, ADC_IntNumber_2, ADC_IntMode_ClearFlag); /* Disable ADCINT2 continuous mode */
ADC_setIntSrc(handles.adc, ADC_IntNumber_1, ADC_IntSrc_EOC3);
ADC_setIntSrc(handles.adc, ADC_IntNumber_2, ADC_IntSrc_EOC5);
...
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_0, ADC_SocChanNumber_A6); /* unused, there because of micro's bug */
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_1, ADC_SocChanNumber_A6);
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_2, ADC_SocChanNumber_B6);
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_3, ADC_SocChanNumber_A4);
...
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_4, ADC_SocChanNumber_B4); /* unused, there because of micro's bug */
ADC_setSocChanNumber(handles.adc, ADC_SocNumber_5, ADC_SocChanNumber_B4);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_1, ADC_SocSampleWindow_7_cycles);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_2, ADC_SocSampleWindow_7_cycles);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_3, ADC_SocSampleWindow_7_cycles);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_4, ADC_SocSampleWindow_7_cycles);
ADC_setSocSampleWindow(handles.adc, ADC_SocNumber_5, ADC_SocSampleWindow_7_cycles);
(The parts configuring the interrupts are omitted). This means that the ADC should take 7 clock cycles to complete. However, the process of setting the SOC, and waiting until the interrupt is received for the chain with 4 conversions, takes about 7 microseconds! I measured this by toggling a pin and measuring the time with oscilloscope. I have enabled optimization to fastest and write directly to registers to avoid function calls (as well as unnecessary EALLOW and EDIS instructions).
I next suspected the CPU clock to be misconfigured. I wrote a loop like the following:
while (1)
{
((GPIO_Obj *)handles.gpio)->GPACLEAR = (uint32_t)1 << GPIO_Number_16; /* set pin to zero */
ADC_readResult(handles.adc, ADC_ResultNumber_3);
/* last line is repeated 512 times */
((GPIO_Obj *)handles.gpio)->GPASET = (uint32_t)1 << GPIO_Number_16; /* set pin to one */
}
The line that calls the ADC function (which is inline) is translated to:
92DC MOV AL,*+XAR4[3] ; [CPU_] |653|
in the assembly listing, so it's a single CPU instruction. In other words, I toggle a GPIO pin after 512 CPU instructions. Looking at the time difference between the pin toggles by an oscilloscope, I see about 68.80 microseconds of time. This means that each MOV instruction took about 134 nanoseconds. From a clock speed of 60MHz, I would have expected a speed of about 20 nanoseconds.
This, and the slow ADC conversion time, makes me suspicious that the CPU clock is not 60MHz, but something smaller. Perhaps that PLL setup failed to achieve the *12/2 operation on the 10MHz input clock? How can I be sure my CPU clock speed is set correctly?
Thank you,
Shahbaz