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-F2800137: LAUNCHXL-F2800137

Part Number: LAUNCHXL-F2800137
Other Parts Discussed in Thread: SYSCONFIG, C2000WARE

#include "F2806x_Device.h"
#include "F2806x_Examples.h"

// Define ADC and PWM settings
#define ADC_CHANNEL     ADC_SOC_Number0   // ADC channel to use
#define PWM_PERIOD      1000              // PWM period in SysClk cycles (change as needed)

// Function prototypes
void ConfigureADC(void);
void ConfigurePWM(void);

void main(void)
{
    // Initialize system
    InitSysCtrl();

    // Initialize peripherals
    ConfigureADC();
    ConfigurePWM();

    // Main loop
    while(1)
    {
        // Start ADC conversion
        AdcRegs.ADCSOCFRC1.bit.SOC0 = 1;
        while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0); // Wait for ADC conversion
        AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;      // Clear ADC interrupt flag

        // Read ADC result
        Uint16 adcResult = AdcResult.ADCRESULT0;

        // Map ADC result to PWM duty cycle (0-1000)
        Uint16 dutyCycle = (adcResult * PWM_PERIOD) / 4095; // Assuming 12-bit ADC

        // Set PWM duty cycle
        EPwm1Regs.CMPA.half.CMPA = dutyCycle;

        // Add delay or other processing as needed
    }
}

// Configure ADC settings
void ConfigureADC(void)
{
    // Enable ADC clock
    AdcRegs.ADCTRL3.all = 0x00;

    // Initialize ADC settings
    AdcRegs.ADCMAXCONV.all = 0x0000; // Set maximum conversion
    AdcRegs.ADCCHSELSEQ1.all = 0x0000; // Disable all ADC channels
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = ADC_CHANNEL; // Enable selected ADC channel
    AdcRegs.ADCSOC0CTL.bit.CHSEL = ADC_CHANNEL; // Select ADC channel for SOC0

    // Configure ADC trigger
    AdcRegs.ADCTRL1.bit.CONT_RUN = 0; // Single conversion mode
    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable ADCINT1
    AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // Enable ADC SOC0
    AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SOC conversion

    // ADC Calibration
    AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power up bandgap reference circuit
    AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power up reference buffer circuit
    AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power up rest of ADC circuits
    AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC

    // Delay for ADC calibration
    DELAY_US(1000); // Adjust delay as needed
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // Select ePWM1 as SOC trigger
}

// Configure PWM settings
void ConfigurePWM(void)
{
    // Enable PWM clocks
    CpuSysRegs.PCLKCR2.bit.EPWM1 = 1; // Enable ePWM1 clock

    // Initialize ePWM settings
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Up-down count mode
    EPwm1Regs.TBPRD = PWM_PERIOD - 1; // Set PWM period
    EPwm1Regs.CMPA.half.CMPA = PWM_PERIOD / 2; // Set initial duty cycle (50%)
    EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; // Clear PWM output on CMPA up-count
    EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; // Set PWM output on zero

    // Enable PWM outputs
    EPwm1Regs.TBCTL.bit.PHSEN = 0; // Disable phase sync
    EPwm1Regs.TBCTL.bit.PHSDIR = 1; // Set phase direction to count up after sync
    EPwm1Regs.TBCTL.bit.SYNCOSEL = 0; // Pass through EPWMxSYNC
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // High-speed clock divider
    EPwm1Regs.TBCTL.bit.CLKDIV = 0; // Clock divider
    EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // Load TBPRD immediately

    // Start PWM counter
    EPwm1Regs.TBCTL.bit.SWFSYNC = 1; // Force immediate synchronization
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Up-down count mode
}

i am getting errors when i am trying to build the program 

  • Hello Gangadhar,

    Are you trying to port code from a F2806x device to F280013x device? If so, it would be better to switch to using driverlib/SysConfig, as bitfields are not very migration-friendly. I will help resolve this query, but I highly advise against using bitfields in the future because they can introduce issues like this. Also, in the future please include the console output for your error. Stating that you get errors does not help determine what errors those are or how you're getting them (and providing this information would be faster than trying to replicate the issue on my side).

    #include "F2806x_Device.h"
    #include "F2806x_Examples.h"

    It seems these are for the incorrect device, I swapped them out with: #include "f28x_project.h"

            // Start ADC conversion
            AdcRegs.ADCSOCFRC1.bit.SOC0 = 1;

    ADCs in bitfield notation are denoted by the ADC instance, such as AdcaRegs, AdcbRegs, etc.

    There are numerous errors like this, you need to take a look at the device reference manual or one of the F280013x bitfield examples in the device_support folder to find what the proper naming convention is. Doing a copy/paste of an old example is not sufficient. Please go through your code any make sure you have the proper register names, and if you still have further problems then we can work from there.

  • sir the actual problem is i want to use one of the adc pin to give input and based on that input i wanted to generate pwm dutycycle can you give some advice how to do it in f2800137

  • Hello Gangadhar,

    If you look at the ePWM and eCAP Lab in C2000 Academy, the lab has a variable for configuring the duty of the ePWM based on a variable. You could import that project into CCS and use it as a template, modifying it so the duty variable would be controlled by the ADC. The example can be found at C2000Ware_5_01_00_00\training\device\f280013x\control_peripherals\lab_ePwm_eCap. For explanations on how the lab works, you can refer to the Academy lab instruction page.

  • Sir I have done this but now i want to change the duty cycle based on analog voltage which i am going to give through adc input pin can you tell me how to do it

    Regrets

    Gangadhar

  • Hi Gangadhar,

    i want to change the duty cycle based on analog voltage which i am going to give through adc input pin can you tell me how to do it

    This will be up to you to implement, you will need to decide how you want the ADC to control the ePWM's duty, either through an ADC interrupt or an ePWM interrupt or just through polling the ADC register. There are examples on how to set up the ADC, create an ADC interrupts, etc. Please refer to these examples and decide how you want to move forward. I will help support any questions regarding the reference manual or the peripheral itself, but the implementation is something you will need to determine for your own application.

  • Good morning Sir,

    i am getting pwm as shown above why i am getting like this when i am changing voltage through adc pin ,please help me out in this 

    Regrets

    Gangadhar

  • I'm not sure what you're doing here, how is the ADC pin reading configuring the ePWM? Let's say you get the digital value of 1024 on the ADC pin after converting the voltage, how does this translate to the ePWM period?

    Also, is that scope shot directly from the ePWM pin or from something the ePWM pin is connected to in your your setup? The ePWM should only be 0V or 3.3V approximately, it should not be giving half-way values.

  • Good Morning Sir,

    actually i am using system integration lab which is given in c2000 academy and i am unable to get the pwm duty cycle as shown in the system integration lab.

  • Hi Gangadhar,

    Some questions for you to understand the context here:

    1. Did you develop the code following the Academy instructions, or did you import the solution directly from C2000Ware? This is system integration for F280013x LaunchPad, correct?
    2. Are there any other issues you are getting with your code? Or does it seem like the software is running properly, but you are just unable to view the PWM signal on the oscilloscope (also, what pin are you scoping?)?
    3.  Are you also able to view "adcAResult", "CMPA_result", "EPwm1Regs.TZFLG.OST" and "duty" in the expression windows while running (as described at the end of the instructions on C2000 Academy - System Integration Lab)?

    Best Regards,

    Allison

  • Good afternoon Madam,

    1.I imported the solution directly from C2000Ware,yes

    2.I am scopin pin number 9

    3.Yes,but i am unable to see EPwm1Regs.TZFLG.OST in the code 

    The main problem is i am unable to change the duty cycle of the pwm based on analog voltage.

    please refer me any reference example to change the pwm dutycycle based on adc value

    Regrets

    Gangadhar

  • Hi Gangadhar,

    Could you please describe your testing process?

    1. Are you able to run the software and what values do you initially see for "adcAResult", "CMPA_result", and "duty"?
    2. How are you varying the analog voltage (what connections are you using and what are you changing when you try to vary PWM duty cycle?)?
    3. When you say you are unable to change the duty based on analog voltage, do you mean you are changing the analog voltage and no change is occurring in the duty? Or is there some other issue or behavior of PWM you see occur?
    4. Can you please share any scope shots you have for your test cases?

    Best Regards,

    Allison

  • Good Morning Mam,

    1.Yes i am able run the software and the values are 2060,494,0.504882812 respectively

    2.i am using ADCINA2 pin which is 25 and i am connecting 3.3V to it by using potentiometer i am changing the voltage and i am pointing at pin number 9 to check the pwm by varying voltage at pin 25.

    3.Yes i am changing analog voltage and i am getting the scope as below.

  • Hi Gangadhar,

    Can I ask why you are scoping at pin 9? The F280013x Launchpad should have EPWM1A signal on GPIO0 (pin 40 of the launchpad). Please try scoping at this pin to see the PWM signal.

    Best Regards,

    Allison