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.

RM48L952 PWM generation

Other Parts Discussed in Thread: HALCOGEN, RM48L952

Hi, I have few doubts. How to generate pwm signal of 20khz in particular. What are the facts I should take care of ?. If i wanted to generate pwm signal at PIN 10 what should be the hex value.

Thanks in advance.

  • Hi Shafina,

      I will suggest that you start with the HalCoGen. What do you mean by pin 10? Do you have a ZWT BGA package or a PGE QFP package. In BGA package there is no pin 10. In the QFP package pin 10 is actually the VCCIO. Or you mean generating PWM on the NHET module's channel 10.

      If you want to generate a 20kHz PWM on NHET's channel 10 see below instructions.

    1. In HalCoGen go to the HET1 tab and in the Pwm 0-7 sub tab. Configure the desire frequency of the PWM. For example, in the below sreenshot, I have 20KHz (50us) and 50% duty cycle configured for NHET's channel/pin 10. HalcoGen will automatically figure the proper hex value to enter into the NHET program for the period and the duty cycle based on your device VCLK2 frequency.  Make sure you enable connection as shown in the screenshot.

     2. Go to the HET1 Pin 8-15 sub tab, click on the DIR box to make the pin an output pin.

      I will suggest that you also read the below application note on how to use the HalCoGen to generate PWM. See below link.

  • Hello Charles,
    Thank you for your reply.

    I am using rm48l952 zwt, i wanted to generate 20khz pwm Signal and Display it in a oscilloscope. i have already did it what u have mentioned above. I am trying to implement it in C++ program. I dont get any Output from PIN 10 pwm 0

    #include "sys_common.h"
    #include "system.h"
    #include "gio.h"
    #include "esm.h"
    #include "het.h"
    #include "dcc.h"

    extern "C" void pwm_main(void)
    {
    uint32 i;
    gioInit(); // initialise GIO
    gioSetDirection(hetPORT1, 0xFFFFFFFF); // Set the direction of HET1
    gioSetBit(hetPORT1, 10, 1);


    hetInit(); // initialise high end timer

    for(i=0; i<=0x10000; i++)
    {
    pwmStart(hetRAM1, pwm0);
    }

    for(i=0; i<=0x10000; i++)
    {
    pwmStop(hetRAM1, pwm0);
    }

    }
    this is the program i have written, could please tell me what mistake i have made
  • Hi Shafina,

      Let me give you a few comments on your code. 

      1. You wrote gioSetBit(hetPORT1, 10, 1); This is fine. You are actually driving a logic 1 onto NHET1[10] which is mapped to the device ball D19. If you probe D19 you should see a high on this pin. Do you see it high?

      2. You wrote the below:

    for(i=0; i<=0x10000; i++)
    {
    pwmStart(hetRAM1, pwm0);
    }

      If you setup the HalCoGen properly, the PWM generation will start after the hetInit() is called. The above code is not really needed. You use pwmStart() to start the PWM for the specified pin only if you had stopped it earlier. For example, if you had stopped pwm0 using pwmStart() then to restart pwm0 you will need pwmStart(). The second comment is that you don't need to put the pwmStart()  or pwmStop() in a for loop for 10000 times. What is the purpose of this? Once the PWM is started using pwmStart on the specified pin then it is already started and will continue forever. There is no need to restart it over and over. The for loop is redundant. 

      So the first thing I will suggest you do is to check pin D19 on the device. Repeating gioSetBit(hetPORT1, 10, 1) and gioSetBit(hetPORT1, 10, 0) to toggle D19(which is NHET1[10]) to see if it even toggles. If it toggles then the PWM generation should work after hetInit(). Note that you can toggle NHET1[10] directly in the CCS register window under the Nhet1 module. It will be easier to debug than to write the code and recompile/reflash the program. 

  • Thank you charles,

    I will do as you say and try it out.
  • Hi Shafina,
    You need to use a scope to see the PWM. If you use the LED then 20kHz is too fast for your eyes.