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.

TMS570LC4357: Assign Specific Output Pin for PWM signal.

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

Hello,

I am trying to figure out how to assign the pwm output a specific port.  From the code I currently have, it will only output to a single default port J8-3 (N2HET1_8/MIBSPI1SMO_1/MII_TXD_3/4.2C).  For clarity, I've trimmed the code down to the few lines of code that are currently working.

Thanks

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%% CODE BELOW %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/* USER CODE BEGIN (0) */
#include "HL_het.h"
#include "HL_gio.h"
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
    uint16_t pwmDUTY;                                                // Create a 16 bit integer variables to modify the Duty cycle
    hetSIGNAL_t pwmSignal;  // hetSIGNAL_t is a struct which defined in het.h

/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    gioSetDirection(hetPORT1, 0xFFFFFFFF);
    hetInit();                                                        // Initialize HET driver
    pwmSignal.duty = 50;
    pwmSignal.period = 2; // us period
    while(1){                                                        // Start an infinite loop
            pwmSetSignal(hetRAM1,pwm0,pwmSignal);
    }
/* USER CODE END */
}


/* USER CODE BEGIN (4) */
/* USER CODE END */

  • Hi Ronald,

    The TMS570LC43x supports N2HET and ePWM. Both can generate PWM signals. If you use N2HET to generate PWM, it is easier to use HALCOGen to select N2HET pin and configure PWM attributes.

  • Thanks for replying.  I should have been more specific.  From what I understand, HALCOgen is useful for setting static parameters via a GUI.  However, I would like to be able to manipulate everything using code to allow for variable duty cycles, etc.  For example, read an analog input to adjust the duty cycle.  Or develop a closed loop feedback control.

  • 1. You can use the API  pwmSetSignal() to select a PWM and configure this PWM's attributes.

    2. There is no API to change the pin number of a PWM dynamically.

    What is your specific question?

  • Hello, and thanks for your replay.  I don't want to change the pin output dynamically.  I simply wish to command the pwm signal to come out of a specific pin (initialization).  Duty cycle and frequency (maybe), would be the only things that would need to change dynamically based on analog input.  Duty cycle and frequency can be changed using pwmSetSignal().

    However, I would like to have direct control over which pin the output is being sent to.  Anything done in the GUI has to have code associated with it.  I'm just trying to figure out how to code pwm output pin assignments.

    Thanks

  • pwmStart(() and pwmStop() will start and stop the PWM output signal output.

    Actually you can changing the pin number through the N2HET instruction in N2HET RAM:

    The PWM0 instruction is instruction 1:

    and PWM1 is instruction 3:

    for example, you can change the PWM0 pin number from 8 to 20:

    hetRAM->Instruction[(pwm << 1U) + 1U].Control  &= ~(uint32)0x00001F00U;

    hetRAM->Instruction[(pwm << 1U) + 1U].Control  |= (uint32)0x00001400U; 

  • Thanks again for the reply.  I'm not following the syntax somewhere.  Entering the code in the images causes errors.  Also, the text code seems to require me to declare variables somewhere.  "Control", "Instruction", and "hetRAM" are not reserved words.  I don't understand what this syntax is trying to get across.

  • I managed to get the code to compile by using hetRAM1 and pwm<number>.  But, I'm not really sure what's happening in the code highlighted in yellow.  I can't find an output signal coming out of any pin.  I'm just lost with the syntax.  Thanks again for the help.

    #include "HL_sys_common.h"

    /* USER CODE BEGIN (1) */
        uint16_t pwmDUTY;                                                // Create a 16 bit integer variables to modify the Duty cycle
        hetSIGNAL_t pwmSignal;  // hetSIGNAL_t is a struct which defined in het.h

    /* USER CODE END */

    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */

    /* USER CODE BEGIN (2) */
    /* USER CODE END */

    int main(void)
    {
    /* USER CODE BEGIN (3) */
        gioSetDirection(hetPORT1, 0xFFFFFFFF);
        hetInit();                                                        // Initialize HET driver
        pwmSignal.duty = 50;
        pwmSignal.period = 2; // us period
        hetRAM1->Instruction[(pwm1 << 1U) + 1U].Control  &= ~(uint32)0x00001F00U;
        hetRAM1->Instruction[(pwm1 << 1U) + 1U].Control  |= (uint32)0x00001400U;

        while(1){                                                        // Start an infinite loop
                pwmSetSignal(hetRAM1,pwm1,pwmSignal);
        }
    /* USER CODE END */
    }


    /* USER CODE BEGIN (4) */
    /* USER CODE END */

  • TMS570LC43x has two N2HET modules, so the hetRAM can be hetRAM1 or hetRAM2. The hetRAM1 and hetRAM2 are defined in HET register header file.

  • Hello.  I'm not following what the code stubs are supposed to be doing.  Maybe they make sense in the context of some other code not being shown.  However, I cannot get anything to compile with these pieces of code present.  I don't know where to put them or what they are suposed ot be doing without any commenting.  I'm new  top using this chip and TI chips in general.  Any background knowledge you may be assuming I have, I do not have with this specific product.

    I don't know how to better explain what I'm trying to do.  Maybe someone else can take a crack at this.  All I'm trying to do is use code (not a GUI) to assign PWM output to a specific PIN. With most devices I've used in the past, this is a very simple process. Even with this particular device, assigning non-PWM outputs to specific PINs is very straightforward.  Maybe I'm trying to do something that is just not possible with this device.  I don't know.

    This issue is not resolved.  I just have had no idea of how to pose the question in a way that would actually get a relevant answer.  I still don't.

    Thanks

  • Hi Ronald,

    As I mentioned before, you can use either ePWM modules or N2HET modules to generate PWM signals. From your messages, I knew you are using N2HET modules for PWM. N2HET module is a coprocessor providing sophisticated timing functions. The instructions have to be copied to N2HET RAM, then execute from N2HET SRAM. The HalCoGen generated code (het_init()) will copy the N2HET instructions to N2HET RAM and run them.

    Steps to Configure N2HET in HALCoGen to generate PWM:

    1. Enable HETx driver in the “Driver Enable” tab.

    2. Select HETx pins in the “PINMUX” tab.

    3. Under the HETx module, make sure the “Enable Advanced Mode/Disable BlackBox Driver” check box is unselected.

    4. Eight PWMs can be configured with different time periods and duty cycles in the “PWM 0-7” tab and pins can be assigned to each PWM. Interrupts can be assigned in the “Pwm Interrupts” tab.

    The generated PWM instructions are in het1PROGRAM[..] in het.c

    static const hetINSTRUCTION_t het1PROGRAM[58U] = {....}

    The instruction 1 (PWCNT) is to define the PWM0's duty cycle, and the instruction 2 (DJZ) is to define the PWM0's period. Both instructions can toggle the pin. The instruction 41 (MOV64) is to update the duty cycle and instruction 42 is to update the PWM period. To modify the duty cycle, period, or pin number while the code is running, you can use the following APIs:

    1. pwmSetDuty(...) 

    2. pwmSetSignal(....)