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.

CCS/TMDSDOCK28335: pwm from given dc signal provided to adc pin

Part Number: TMDSDOCK28335
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Sir/Madam

I am learning  tms28335 experimental kit. My aim is to give the analog D.C signal from signal generator to adc pin A0 and observe the pulse from the controller. I dont know where ie the problem. I am copying the code below.

#include"DSP2833x_Device.h"
#include"math.h"

// external function prototypes
extern void InitAdc(void);
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);

// Prototype statements for functions found within this file.
void Gpio_select(void);
void Setup_ePWM1(void);
interrupt void adc_isr(void); // ADC End of Sequence ISR

// Global Variables
Uint16 pwm=750;
float Voltage_VR1;
float duty_pwm;


//###########################################################################
// main code
//###########################################################################
void main(void)
{
InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;
SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog
EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output
// to 4 LEDs at Peripheral Explorer)

Setup_ePWM1(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

InitAdc(); // Basic ADC setup, incl. calibration

AdcRegs.ADCTRL1.all = 0;
AdcRegs.ADCTRL1.bit.ACQ_PS = 1; // 7 = 8 x ADCCLK
AdcRegs.ADCTRL1.bit.SEQ_CASC =0; // 1=cascaded sequencer
AdcRegs.ADCTRL1.bit.CPS = 0; // divide by 1
AdcRegs.ADCTRL1.bit.CONT_RUN = 0; // single run mode

AdcRegs.ADCTRL2.all = 0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // 1=enable SEQ1 interrupt
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 =1; // 1=SEQ1 start from ePWM_SOCA trigger
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0; // 0= interrupt after every end of sequence

AdcRegs.ADCTRL3.bit.ADCCLKPS = 2; // ADC clock: FCLK = HSPCLK / 2 * ADCCLKPS
// HSPCLK = 75MHz (see DSP2833x_SysCtrl.c)
// FCLK = 12.5 MHz

AdcRegs.ADCMAXCONV.all = 0; // 1 conversion from Sequencer 1

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0; // Setup ADCINA0 as 1st SEQ1 conv.

EALLOW;
PieVectTable.ADCINT = &adc_isr;
EDIS;

PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // CPU Timer 0
PieCtrlRegs.PIEIER1.bit.INTx6 = 1; // ADC

IER |=1;

EINT;
ERTM;
}

void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O
GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O
GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O
GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O
GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9
GpioCtrlRegs.GPADIR.bit.GPIO31 = 1; // peripheral explorer: LED LD2 at GPIO11


GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49
GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs
EDIS;
}

interrupt void adc_isr(void)
{
Voltage_VR1 = (AdcMirror.ADCRESULT0); // store result global
// 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
}

void Setup_ePWM1(void)
{
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // HSPCLKDIV = 2
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.bit.CAU = 2; // set ePWM1A on CMPA up
// clear ePWM1A on CMPA down

EPwm1Regs.AQCTLA.bit.CAD = 1; // set ePWM1B on CMPB up
// clear ePWM1B on CMPB down

duty_pwm = pwm*(Voltage_VR1)/4096;  
EPwm1Regs.CMPA.half.CMPA = duty_pwm; 
}


//===========================================================================
// End of SourceCode.
//===========================================================================

  • Guntuku,

           Start with an ADC example in controlSUITE. Then determine which pin the ADC is sampling, it will help to look at "C:\ti\controlSUITE\development_kits\~controlCARDs\CC2833xHWdevPkg\F28335controlCARD-PinOutTable.pdf" which contains the pin out for the controlCARD.

    The ADC example will work without modification, start from that point and modify the code to suit your needs.


    Regards,
    Cody 

  • Sir

    I already worked with adc pins with embedded coder( Matlab and 28335) with matlab and i got results. Now i want learn the same in coding. So, my question is how to generate the variable duty ratio of the pulses from the given dc signal from the signal generator which was not mentioned in the example. Tell me any corrections in the pasted code above. Thank you sir

    Regards

    kishore

  • Kishore,

    I was not referring you to Embedded Coder. ControlSUITE is a software library which contains a set of examples write entirely in C code. These examples are designed to allow a customer with no experience in coding to setup and evaluate individual modules in a reasonable use case.

    Try importing the project found in "<Install directory>\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\adc_soc". This example will setup the ADC for you.

    If you would like to then generate a PWM based off of that ADC reading you will need to setup the PWM module. "<Install Directory>\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\epwm_up_aq" is a good example.

    When you undoubtedly run into a register you don't know the purpose of, or maybe you would like to implement a more advanced feature like a Trip-Zone, you can find details in the respective module's User's Guide found Here.

    In my experience code reviews are not very fruitful. The fastest way to find a problem is to test the code while executing on the device. You should start by verifying your configuration using breakpoints to step through your code while reading back the configuration using the memory browser.

    If you find something that isn't working properly, provide a description and I will gladly help you work through that problem! The more details you provide the more I can help.

    Regards,
    Cody 

  • Sir

    Its not about review. I already dumped it. It is successful. But I am not getting any results on DSO.

    Regards

    kishore

  • Kishore,

    try loading one of the PWM examples, and if it works we can rule out hardware issues.

    Have you enabled the clock to the PWM module?

    Is the TBCLK counting?

    Have you verified the GPIO configuration by reading the registers in the memory browser?

    Have you connected the oscilloscope's probe to the correct pin?

    Regards,
    Cody 

  • I am going to close this issue due to inactivity. If you question has not been answered feel free to reply or start a new related thread.

    Regards,
    Cody