Tool/software: Code Composer Studio
Hi,
I am trying make a system using the lauchpad-F28379D where, the ADC is triggered by EPWM (for precise sampling rate), and the samples are then sent to PC (Matlab) via SCI_UART.
The whole operation is triggered by MATLAB, as soon as the MIcrocontroller receives data from matlab over UART.
The ADC is set at 12bit resolution and ACQPS = 19 (=100ns for 200MHz CPU)
ADC sampling Rate = 1 MHz (EPWM CLK = 100 MHz, TBPRD = 99),
So the problem occurs when the TBPRD (EPWM) is set such that the sampling rate exceeds 1 MHz, say 2 MHz (TBRD = 49)
The code somwhow doesn't stop at; while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } and the value of startup gets set to 1 which should not happen... Please help. Thanks!!
Please refer to the code below.
void main(void)
{
//--- CPU Initialization
InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c)
InitGpio(); // Initialize the shared GPIO pins (FILE: Gpio.c)
InitXbar(); // Initialize the input, output & ePWM X-Bar (FILE: Xbar.c)
InitPieCtrl(); // Initialize and enable the PIE (FILE: PieCtrl.c)
InitWatchdog(); // Initialize the Watchdog Timer (FILE: WatchDog.c)
//--- Peripheral Initialization
InitAdca(); // Initialize the ADC-A (FILE: Adc.c)
InitDacb(); // Initialize the DAC-B (File: Dac.c)
InitEPwm(); // Initialize the EPwm (FILE: EPwm.c)
InitScia(); // Initialize the SCI-A (FILE: Sci.c)
//--- Enable global interrupts
asm(" CLRC INTM, DBGM"); // Enable global interrupts and realtime debug
//--- Main Loop
while(1) // endless loop - wait for an interrupt
{
// Wait for inc character (wait for receiving data from Matlab)
while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state
Rx_char = SciaRegs.SCIRXBUF.all;
startup = 1;
EPwm2Regs.ETSEL.all = 0x0A00; // Enable SOCA to ADC
EPwm2Regs.TBCTL.bit.CTRMODE = 0; //unfreeze, and enter up count mode
} //end while : Main loop
} //end of main()
ISR:
interrupt void ADCA1_ISR(void) // PIE1.1 @ 0x000D40 ADC-A interrupt #1
{
static Uint16 *AdcBufPtr = AdcBuf; // Pointer to buffer
static Uint16 iQuadratureTable = 0; // Quadrature table index
static volatile Uint16 GPIO34_count = 0; // Counter for pin toggle
int byte[2]; // changing 16-bits to 2 8-bit numbers for SCI_UART transmission
Uint16 i = 0;
if(startup == 1){
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Must acknowledge the PIE group
//--- Manage the ADC registers
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADCINT1 flag
//--- Read the ADC result
*AdcBufPtr++ = AdcaResultRegs.ADCRESULT0; // Read the result
//--- Brute-force the circular buffer
if( AdcBufPtr == (AdcBuf + ADC_BUF_LEN) )
{
AdcBufPtr = AdcBuf; // Rewind the pointer to beginning
}
//--- Write to DAC-B to create input to ADC-A0
if(SINE_ENABLE == 1)
{
DacOutput = DacOffset + ((QuadratureTable[iQuadratureTable++] ^ 0x8000) >> 5);
}
else
{
DacOutput = DacOffset;
}
if(iQuadratureTable > (SINE_PTS - 1)) // Wrap the index
{
iQuadratureTable = 0;
}
DacbRegs.DACVALS.all = DacOutput;
counter++;
}//startup
if(counter == ADC_BUF_LEN){
EPwm2Regs.ETSEL.all = 0x0000; //disable SOCA
EPwm2Regs.TBCTL.bit.CTRMODE = 3; //freeze counter
startup = 0;
i = 0;
counter = 0;
while(i < ADC_BUF_LEN ){
byte[0] = AdcBuf[i] >> 8; // high byte
byte[1] = AdcBuf[i] & 0x00FF; // low byte
scia_xmit(byte[0]);
scia_xmit(byte[1]);
i++;}
}// end if
}// end ISR

