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.

F28335 adc to epwm not working properly

Other Parts Discussed in Thread: CONTROLSUITE

Sir i am having same problem as quarry same as

F28335 EPWM to GPIO

 there is small modification in code to compare input from adc0 and give result from epwm0

sir i am not gating any output from my code and example code of adc_soc.

i am using ccs 6.1.2 and latest control suite.

here is my code



#include "DSP28x_Project.h" // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
__interrupt void adc_isr(void);

// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;

main()
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();

EALLOW;
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
EDIS;

// Define ADCCLK clock frequency ( less than or equal to 25 MHz )
// Assuming InitSysCtrl() has set SYSCLKOUT to 150 MHz
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;
EDIS;

// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;

// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
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

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitAdc(); // For this example, init the ADC

// Step 5. User specific code, enable interrupts:

// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

LoopCount = 0;
ConversionCount = 0;

// 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)

// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.TBPRD = 15000; // Set timer period 801 TBCLKs
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter

// Set Compare values
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.CMPB = 0x0080; // Set Compare B value

// Setup counter mode
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;


// 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

EPwm1Regs.AQCTLB.bit.CBU = AQ_SET; // Set PWM1B on event B, up count
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR; // Clear PWM1B on event B, down count

EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event



// Wait for ADC interrupt
for(;;)
{
LoopCount++;
}
}

__interrupt void adc_isr(void)
{

EPwm1Regs.CMPA.half.CMPA = 3*AdcRegs.ADCRESULT0; // Set compare A value
EPwm1Regs.CMPB = AdcRegs.ADCRESULT1;

// If 40 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;
}


sir please help me where am i wrong? I am not gating error for build.
if any modification is necessary in run this code.

  • I'm not able to understand what you are trying to do. Please provide a more detailed description of what you are trying to accomplish.

    Also please note most of the U.S. team is on holiday this week and responses may be delayed.

    Thank you
    Lori
  • Hello,

    Can you clarify which expected outputs you are not seeing when running the adc_soc example? Are you having similar issues with other example projects?

    The controlSUITE examples have comments at the top of the source file detailing if there are any variables to watch or external connections that can be monitored. These instructions can also be found in the User’s Guide found in the doc directory: controlSUITE\device_support\<device>\<version>\doc

    Elizabeth
  • Sir, I just want to take input waveform from adc and give this to epwm cpma so that it give me output which i needed. In future i apply mathematics for AI controller. I already used ADC_SOC example but it is not giving any output at epwm. so I just modified output result Voltage_V1[10] to Cpma so I can get result from different epwm. I actualy want to geting three inputs from ADC ant modify that By their combinations and take output as per epwm for gate signal. I am also using a filter on epwm 03 to get output wave for as described in documentation for further processing.

    Sir/Mam

    I  think there is some problem with example. Other two ADC examples are working properly.

  • Hello,

    For the adc_soc example, can you provide more feedback what the problem is? Then I can loop your feedback back to the team for review.

    If you're unsure on how to generate EPWM output waveforms, I recommend looking at an EPWM example like epwm_up_aq or epwm_updown_aq. If you make the external connections stated in the comments, you'll be able to view the output with an oscilloscope. These examples have calls to InitEPwm1Gpio(), a function which enables the GPIO pins for EPWM functionality. The source for this function is in DSP2833x_common\source\DSP2833x_EPwm.c. This function may be of some help in your project.

    Elizabeth
  • Sir/Mam,

    I already looked in epwm_updown_aq and generated output waveform from epwm 3,4,5. now i just tried to start soc from epwm timer at zero. After that with some manupulation i want modified output from epwm 3,4,5. In literature Adc_Soc is given example so i tried to run it. After running there is no error. but when i connected voltage reference with 10k pot from it's own supply. But their is no output at epwm pin.

    Sir if their any basic algorithem is avalable for like

    it take input from adc; sync with epwm timer; adc result goes to compare regs CPMA or CPMB; output come from epwm.

    I studied in literature adc_soc is best sutable example for this. but that example is not giving any output at epwm pin. than i modified it somewhat (code is already given) but there is no output et al 

    sir/ mam can you provide the basic algorithem.

  • Hi Jitendra,

    If you want some examples of an actual control loop using ADC readings to adjust the ePWM timings, take a look in ControlSUITE in the development kits directory:

    \ti\controlSUITE\development_kits\

    These various application kits have the schematics, code, and documentation for our various application development kits (e.g. motor control, power supplies, etc). These may be helpful even if you don't purchase the application kit.