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.

LAUNCHXL-F28379D: ADC in not working properly

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE

Hi,

I tried to implement a simple ADC conversion on F28379D in which SOC is suppose to generate when ePWM2 TBCTR = PRD. ADC result register is read in the main code for test purposes. But it contains the value of zero.

When I tried to read SOCAPRD of ETPS register it didn't update and remains at zero. But I couldn't find any error with my code. Following is the main code of mine,

#include "Lab.h" // Main include file


//--- Global Variables
Uint16 DEBUG_TOGGLE = 1; // Used for realtime mode investigation test
Uint16 SINE_ENABLE = 0; // Used for DAC waveform generation
Uint16 PWM_MODULATE = 0; // Used for PWM modulation
Uint16 AdcBuf[ADC_BUF_LEN]; // ADC buffer allocation
Uint16 DacOffset; // DAC offset
Uint16 DacOutput; // DAC output
Uint32 PwmDuty; // measured PWM duty cycle
Uint32 PwmPeriod; // measured PWM period
int whilecount =0;

float ind_current=0;

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)
	// Initialize the ECap (FILE: ECap.c)
	
	GpioDataRegs.GPACLEAR.bit.GPIO2 = 0x1; //Turn off IGBT S3
	GpioDataRegs.GPACLEAR.bit.GPIO3 = 0x1; //Turn off IGBT S2
	GpioDataRegs.GPACLEAR.bit.GPIO5 = 0x1; //Turn off IGBT S1
	GpioDataRegs.GPACLEAR.bit.GPIO7 = 0x1; //Turn off IGBT S4
	GpioDataRegs.GPACLEAR.bit.GPIO6 = 0x1; //Turn off IGBT DC bus
	GpioDataRegs.GPACLEAR.bit.GPIO4 = 0x1; //Turn off the reserved gate
	GpioDataRegs.GPACLEAR.bit.GPIO6 = 0x1; //Turn off IGBT DC bus
	
	
	//--- Enable global interrupts
	// asm(" CLRC INTM, DBGM"); // Enable global interrupts and realtime debug
	
	//--- Main Loop
	while(1) // endless loop - wait for an interrupt
	{
		whilecount++;
		ind_current=(3/4096)*AdcbResultRegs.ADCRESULT2;
		asm(" NOP");
	}
	
	
} //end of main()

 

ADC.c file of mine is as follows,

#include "Lab.h" // Main include file

/**********************************************************************
* Function: InitAdca()
*
* Description: Initializes ADC-A on the F28x7x
**********************************************************************/
void InitAdca(void)
{
	asm(" EALLOW"); // Enable EALLOW protected register access
	
	//--- Reset the ADC.
	DevCfgRegs.SOFTPRES13.bit.ADC_A = 1; // ADC is reset
	DevCfgRegs.SOFTPRES13.bit.ADC_A = 0; // ADC is released from reset
	
	DevCfgRegs.SOFTPRES13.bit.ADC_B = 1; // ADC is reset
	DevCfgRegs.SOFTPRES13.bit.ADC_B = 0; // ADC is released from reset
	
	DevCfgRegs.SOFTPRES13.bit.ADC_C = 1; // ADC is reset
	DevCfgRegs.SOFTPRES13.bit.ADC_C = 0; // ADC is released from reset
	
	
	//--- Configure the ADC 'B' base registers
	
	AdcbRegs.ADCCTL1.all = 0x0004; // Main ADC configuration
	
	
	AdcbRegs.ADCCTL2.all = 0x0006; // ADC clock configuration
	
	
	AdcbRegs.ADCBURSTCTL.all = 0x0000;
	
	
	AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
	
	//--- SOC0 configuration
	AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 0x7; // Trigger using ePWM2-ADCSOCA
	AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0x2; // Convert channel ADCINB2 (Main current sensor)
	AdcbRegs.ADCSOC0CTL.bit.ACQPS = 19; // Acquisition window set to (19+1)=20 cycles (100 ns with 200 MHz SYSCLK)
	
	AdcbRegs.ADCINTSOCSEL1.bit.SOC0 = 0; // No ADCINT will trigger SOC0
	
	AdcbRegs.ADCSOCPRICTL.bit.SOCPRIORITY = 0; // All SOCs handled in round-robin mode
	
	//--- ADCb interrupt configuration
	AdcbRegs.ADCINTSEL1N2.bit.INT1CONT = 1; // Interrupt pulses regardless of flag state
	AdcbRegs.ADCINTSEL1N2.bit.INT1E = 0; // Enable the interrupt in the ADC
	AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // EOC0 triggers the interrupt
	
	//--- Enable the ADC interrupt
	PieCtrlRegs.PIEIER1.bit.INTx1 = 0; // Disable ADCA1 interrupt in PIE group 1
	IER |= 0x0000; // Disable INT1 in IER to enable PIE group
	
	//--- Finish up
	// AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Power up the ADC
	// DelayUs(1000);
	AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
	DelayUs(1000);
	// AdccRegs.ADCCTL1.bit.ADCPWDNZ = 1;
	// DelayUs(1000); // Wait 1 ms after power-up before using the ADC
	asm(" EDIS"); // Disable EALLOW protected register access
	
} // end InitAdc()

and EPWM.c file is as follows,

#include "Lab.h" // Main include file

/**********************************************************************
* Function: InitEPwm()
*
* Description: Initializes the Enhanced PWM modules on the F28x7x
**********************************************************************/
void InitEPwm(void)
{
	asm(" EALLOW"); // Enable EALLOW protected register access
	
	// Configure the prescaler to the ePWM modules. Max ePWM input clock is 100 MHz.
	ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 1; // EPWMCLK divider from PLLSYSCLK. 0=/1, 1=/2
	
	// Must disable the clock to the ePWM modules if you want all ePWM modules synchronized.
	CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
	
	asm(" EDIS"); // Disable EALLOW protected register access
	
	
	//---------------------------------------------------------------------
	//--- Configure ePWM2 to trigger ADC SOCA at a 50 kHz rate
	//---------------------------------------------------------------------
	asm(" EALLOW"); // Enable EALLOW protected register access
	DevCfgRegs.SOFTPRES2.bit.EPWM2 = 1; // ePWM2 is reset
	DevCfgRegs.SOFTPRES2.bit.EPWM2 = 0; // ePWM2 is released from reset
	asm(" EDIS"); // Disable EALLOW protected register access
	
	
	EPwm2Regs.TBCTL.bit.CTRMODE = 0x3; // Disable the timer
	
	EPwm2Regs.TBCTL.all = 0xC033; // Configure timer control register
	// bit 15-14 11: FREE/SOFT, 11 = ignore emulation suspend
	// bit 13 0: PHSDIR, 0 = count down after sync event
	// bit 12-10 000: CLKDIV, 000 => TBCLK = HSPCLK/1
	// bit 9-7 000: HSPCLKDIV, 000 => HSPCLK = EPWMCLK/1
	// bit 6 0: SWFSYNC, 0 = no software sync produced
	// bit 5-4 11: SYNCOSEL, 11 = sync-out disabled
	// bit 3 0: PRDLD, 0 = reload PRD on counter=0
	// bit 2 0: PHSEN, 0 = phase control disabled
	// bit 1-0 11: CTRMODE, 11 = timer stopped (disabled)
	
	EPwm2Regs.TBCTR = 0x0000; // Clear timer counter
	EPwm2Regs.TBPRD = ADC_SAMPLE_PERIOD; // Set timer period
	EPwm2Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase
	
	EPwm2Regs.ETPS.all = 0x0100; // Configure SOCA
	// bit 15-14 00: EPWMxSOCB, read-only
	// bit 13-12 00: SOCBPRD, don't care
	// bit 11-10 00: EPWMxSOCA, read-only
	// bit 9-8 01: SOCAPRD, 01 = generate SOCA on first event
	// bit 7-4 0000: reserved
	// bit 3-2 00: INTCNT, don't care
	// bit 1-0 00: INTPRD, don't care
	
	EPwm2Regs.ETSEL.all = 0x0A00; // Enable SOCA to ADC
	// bit 15 0: SOCBEN, 0 = disable SOCB
	// bit 14-12 000: SOCBSEL, don't care
	// bit 11 1: SOCAEN, 1 = enable SOCA
	// bit 10-8 010: SOCASEL, 010 = SOCA on PRD event
	// bit 7-4 0000: reserved
	// bit 3 0: INTEN, 0 = disable interrupt
	// bit 2-0 000: INTSEL, don't care
	
	EPwm2Regs.TBCTL.bit.CTRMODE = 0x0; // Enable the timer in count up mode
	
	
	//---------------------------------------------------------------------
	//--- Enable the clocks to the ePWM module.
	//--- Note: this should be done after all ePWM modules are configured
	//--- to ensure synchronization between the ePWM modules.
	//---------------------------------------------------------------------
	asm(" EALLOW"); // Enable EALLOW protected register access
	CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1; // TBCLK to ePWM modules enabled
	asm(" EDIS"); // Disable EALLOW protected register access
	
} // end InitEPwm()

Please help me to find the error of the above code.

Thanks in advance.

Lahiru

 

  • Hi,

    When posting code onto the forum, please use the code formatting tool marked by the </> button. This allows the code to be easily read and can help you get support faster on the forums. I've modified your previous post to reflect the use of the tool.
    Your query has been forwarded to ADC experts. You should receive a reply soon.

    Regards,
    Veena

  • Hi Veena,

    Thank you for the help. I replaced the micro controller and used the software force SOC instead of ePWM. It works fine now. I would like to know whether I can monitor the status of the bits of registers (ex. SOCACNT bit of the ETPS register) in the watch window.

    Thanks

    Lahiru

  • Hi,

    Did you try executing adc_soc_epwm example present under C2000Ware? This example demonstrate ADC triggering through EPWM.

    Also ETPS.SOCAPRD register is write protected register. Check if EALLOW is missing before configuring this register.

    Thanks
    Vasudha
  • Hi,

    You might not be able to monitor the status of bits of ETPS.SOCACNT register in debug window as the debug window refreshes will be slower. You can though check it in code.

    There is an additional ETSOCPS register to configure the SOC period and checking the count for configuring pre-scale value more than 3. This is enabled when ETPS[SOCPSSEL] = 1. Check device TRM for more details.

    Thanks
    Vasudha