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.

TMS570LS1224: Controlling an N2HET PWM signal

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN,

Hi,

I am trying to control a PWM signal generated using the N2HET.

So far I am able to see a PWM signal with a fixed frequency and a duty cycle of 25%, but I don't seem able to control this on-the-fly. I am assuming that my HalCoGen settings are valid in order to see any output at all.

As a basic test (on a LaunchpadXL board) I am programming an ADC to obtain a modifiable value, scaled to 0-100%, and I am trying to feed this into a pwmSetSignal() function to control the duty cycle.

My very simple code is:

    adcData_t adc_data;
    adcData_t *adc_data_ptr = &adc_data;
    unsigned int value;
    unsigned int duty_cycle;
    hetSIGNAL_t het_sig;


    het_sig.duty=50;
    het_sig.period = 1.000;        /* 1us := 1MHz */

    hetInit();
    adcInit();
 
    pwmStart(hetRAM1, pwm0);

    while(1)
    {
        /* Get modifiable value from ADC */
        adcStartConversion(adcREG1, adcGROUP1);
        while(!adcIsConversionComplete(adcREG1, adcGROUP1));
        adcGetData(adcREG1, 1U, adc_data_ptr);
        value = (unsigned int)adc_data_ptr->value;

        /* Relate the value (0-4095) to a percentage (0-100) for the PWM duty cycle */
        /* The value/41 gives the duty cycle percentage, with a maximum of 99 */
        duty_cycle = value / 41;

        /* Update duty cycle with value from ADC */
        het_sig.duty=duty_cycle;
//        pwmSetSignal(hetRAM1, pwm4, het_sig);
    }

When I run this code I call see on a 'scope that there is a 175.7kHz PWM signal with a 25% duty cycle.

My HalCoGen settings for pwm0 are: Period = 0.1, Duty Cycle = 10. What I am seeing bears no relation to the HalCoGen settings.

When I uncomment the call to pwmSetSignal(), the PWM output is killed completely.

My ultimate objective is to produce a PWM signal at the highest possible frequency, but (most importantly) with a controllable duty cycle over the range 0 to 99%.

Questions:

1. Can you advise where my code is incorrect and/or inadequate, please, and what is required to acchieve my objective?

2. By stepping through the code I start seeing the PWM output as soon as pwmInit() has executed. Do I need to call pwmStart()? If so why?

3. I have trawled the web to find this information so would you also point me to where I can find this (for TMS570LS1224 and N2HET and PWM)?

4. What is the best result that I can expect, in terms of maximum PWM frequency and Duty Cycle?

TIA

  • Hi TIA,

    The HALCOGen generated code can only support your 5 duty-cycle settings for PWM freq=175KHz: 0, 15%,25%,50%,75%. The LR for HAL code is 64. If you need more duty-cycle settings, you need to write your own code. How many PWM signals do you need? Do you need ECAP, Edge detection etc features?

    1. Can you advise where my code is incorrect and/or inadequate, please, and what is required to acchieve my objective?

    expected behavior if PWM frequency=175KHz and LR=64 (default for HAL generated code). 

    2. By stepping through the code I start seeing the PWM output as soon as pwmInit() has executed. Do I need to call pwmStart()? If so why?

    Yes, you need to call pwmStart() to output PWM signal. The pin action of PWCNT instruction is not enabled by default. 

    3. I have trawled the web to find this information so would you also point me to where I can find this (for TMS570LS1224 and N2HET and PWM)?

    4. What is the best result that I can expect, in terms of maximum PWM frequency and Duty Cycle?

    If you only need 1 PWM output, 8 N2HET instructions are enough --> LR=8, so you will have more choices for duty-cycles.

    Please download HET IDE to simulate the NHET code.