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.

TMS570LS3137 n2het pwcnt instruction

Hi,

I want to generate a PWM with varying duty cycle. I have tried it using PWCNT instruction but i am not able to understand how to reload the counter. I know it is a little complex prcedure but can someone explain me the procedure or any other way to generate PWM with varying duty cycle.

Thanks.

  • Gobind,

    I would suggest looking at this thread:  http://e2e.ti.com/support/microcontrollers/hercules/f/312/p/287386/1016623.aspx#1016623

    for PWM examples. The ECMP instruction works better in most cases than PWCNT.

     

  • Anthony,

    Thanks for the reply. Since I am a beginner in N2HET, it is very difficult for me to understand the code given in the link you provided. I will explain my requirement and please tell me if there is a simple solution for that. My requirement is like:

    START COUNTER STOP COUNTER OUTPUT
    0 9 0
    10 27 1
    28 49 0
    50 55 1
    56 61 0
    62 80

    1

    The logic which I am trying to implement using PWCNT is:

    1. Load the counter parameter of PWCNT with a value to get desired pulse width

    2. Give delay to get the desired 0-time

    3. Reload the counter parameter of PWCNT with ADCNST instruction

    and repeat the process for different pulse widths. For example, my code looks like this:

    P00   ADCNST { remote=0x2,min_off=0,data=5}  ;reload the counter with 5

    P10   ADCNST { remote=0x3,min_off=0,data=15}  ;loading the counter of DJZ instruction for delay

     L00   PWCNT { next=L02,hr_lr=HIGH,cond_addr=L02,en_pin_action=ON,pin=0,action=PULSEHI,reg=NONE,irq=OFF,data=2,hr_data=1};

     L02   DJZ { next=L00,cond_addr=P00,reg=A};

    When i run this code, i see that counter value decrements by 1 each time PWCNT instruction is executed. When this counter reaches zero, there is a wait because the counter of DJZ (=15) is more than PWCNT counter (=5). And when DJZ counter reaches zero, both the counters get reloaded with the values given in ADCNST instruction and the same thing is repeated again. But when i see the waveform, i see only one transition from 0 to 1. This never become zero again. Can you please tell me what is wrong in this logic/code? or is there any other way to implement this?

    Thanks.

  • Gobind,

    The PWCNT with PULSHI action will set the pin low when it is executed with the Z (zero) flag set.
    (This is called the 'opposite pin action').

    The DJZ instruction doesn't set the Z flag -- which may not be obvious but you can see this by looking at the psuedo-code for DJZ in the technical reference manual.

    So, if you want to have the opposite pin action you should use an instruction that does set the Z flag.
    The CNT instruction in this case would be a good alternative.