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.

switching PWM signal with ON/OFF delay time in RM48

Other Parts Discussed in Thread: HALCOGEN

Hi,

I am using PWM signal with different duty cycle in my application.

I need to switch ON the PWM signal for 2 second  and to switch OFF the same signal for 3 seconds. it is to be repeatedly done.

I have attached the code i have developed so for. Need support to proceed further

5488.m.rar

 

  • Manjunathan.

    You can accomplish this by calling pwmStop() and pwmStart() but I think a far better way is to make the N2HET do this for you.


    There is an option called 'AND-SHARE' and you can select this option on the Pin X-Y tab.


    So try this:

      a) set your high frequency PWM to output on pin 'N'.   Say N=8 for example which is the default for the first PWM in HalCoGen.

      b) set the adjacent (N+1) pin to output a PWM that is on for 2seconds / off for 3 seconds  (Period = 5,000,000 us and Duty = 2,000,000 us)

    Build the project like this (without turning on AND share).

    Test and with an oscilloscope make sure you see  the fast PWM on pin N and the slower PWM on pin N+1.


    Now, if you are using CCS without even rebuilding the code you can set bit 4 in the "HETAND" register at address 0xFFF7B82C (N2HET1) or 0xFFF7B92C (N2HET2).

    You should see the result change so that pin 9 stays flat,  and pin 8 now shows your fast PWM modulated by the 5s, 40% duty cycle slow PWM.


    To change the code for this, just go to the PIN8-15 tab in HalCoGen and check the 'AND-SHARE' box that connects pins 8 and 9.

    -anthony

  • Thank you Mr.Anthony F. Seely

    I clearly understood what you have explained Sir.

    But the switching ON/OFF is to be done only for the below logic.

    hetInit();
    Set_Duty_Period1.duty = 75;
    Set_Duty_Period1.period = 2000;
    pwmSetSignal(hetRAM1, pwm1, Set_Duty_Period1);
    pwmStart(hetRAM1, pwm1);
    while(1);

    I just need to switch ON/OFF the 75%duty with 2000 us( 2 Khz signal) for 2seconds ON and 3 seconds OFF in PWM1 pin Sir. 

    I have modified and attached the project file please look at it once Sir. I have tried but some errors occurred.0552.m.rar  

    Thanks and regards

    K.Manjunathan

    PSGIAS

  • You can use pwmStop() as well if you want to switch on / off through C code.
  • Thank you Sir,

    How to define Delay time for ON time and OFF time sir.

    one of my task is completed by using the AND share option sir.It is working fine Sir.,


    Regards
    K.Manjunathan

  • Manjunathan,

    Well, this is a difficult question in the sense that how I would do this is to use the FreeRTOS port, which will give you the ability to 'sleep()' for a certain amount of time. This time will be 'accurate' (with some tolerance for interrupt latency but that will be small compared to 1s or 3s...) because it will use the RTI.

    This is a lot of extra steps though based on your simple project.

    Another way for your simple project would simply to be to insert a delay loop ... for (i=0; i<TIME_VALUE; i++);
    that does nothing but pause the CPU until the delay times out. Start with a TIME_VALUE of say 30,000,000, measure, and adjust as needed. This method will not be good because a change in compiler settings, link address (as flash wait states depend on location within the flash 256-bit wide line..) etc. But it is quick and dirty. Just expect it to :
    a) break all the time
    b) use all of the CPU doing nothing ...

    The RTOS solves these two problems, but if you have never used it before and you are only doing something for an experiment you may not want to delve into the RTOS yet. Up to you.
  • Thank you Sir,

    I will try it and come back to you Sir.

    Regards

    K.Manjunathan