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.

HET: Cannot set duty cycle to 0% if the duty cycle was set before to 100%

Other Parts Discussed in Thread: HALCOGEN

Hello,

I am using the RM48 MCU HDK (Hercules Development Kit) for rapid prototyping.

I cannot set the pwm duty cycle to 0% if the pwm duty cycle was set before to 100%.

Calling first "pwmSetDuty(hetRAM1, pwm5, 1);" and immediately thereafter (i.e. in the next line) "pwmSetDuty(hetRAM1, pwm5, 0);" does not work.

How can I switch from 100% duty cycle to 0% duty cycle?

How can I explicitely set the pin to low?

Thanks and regards

Pascal

  • Hi Pascal,

    The HalCoGen PWM code has a limitation and I think this may be it. Its either the 0% -> 100% or the 100% to 0% back to back transition that fails. There were some posts about this before. Has something to do with the way the underlying HET code is written.

    Two options for you:
    a) avoid switching directly from 100% to 0% ... do something like 100% 1% 0% instead by putting in a check for this corner case in your software.

    b) use a custom HET program that can handle 100% to 0% and 0% to 100%.

    Note that the HET can definitely handle these cases .. it's just that the very generic HET program built into HalCoGen doesn't.
    For (b) you need the HET IDE which you can download http://www.ti.com/tool/het_ide
    It includes templates for common functions including PWMs.

    When you create your own HET with the HET IDE you can check the 'disable black box driver / use custom driver' box in the HET tab on HalCoGen, then use the selection boxes to point to the .c and .h files that you generated with the HET IDE.

    This will cause HalCoGen to load your own HET program instead of the one that is the default.

    You still will need to write your own host side driver functions to update the PWM duty as the ones that come with HalCoGen apply to the HalCoGen HET program - not your custom one. This is usually no big deal - the header file generates a structure for you that represents your code, and to update a duty cycle you put a 'label' on the instruction that represents your duty cycle and use the structure to modify the 'data' field of that instruction.

    This application report explains the program that is the 'black box' driver from HalCoGen so you can understand it and perhaps modify it to suite your purposes:
    www.ti.com/.../getliterature.tsp

    This app report might be a good example for you to look at to see how Charles has written host side driver code that
    reads and writes to the 'control registers' (usually the data field of critical HET instructions) of a custom HET program:
    www.ti.com/.../getliterature.tsp

    -Anthony
  • Hi Antony,

    I have tried option a) using one of the two following functions:

    SetDutyCycleFrom100To0Version1()
    {
    pwmSetDuty(hetRAM1, pwm5, 5);
    pwmSetDuty(hetRAM1, pwm5, 0);
    }

    SetDutyCycleFrom100To0Version2()
    {
    pwmStop(hetRAM1, pwm5);
    pwmStart(hetRAM1, pwm5);
    pwmSetDuty(hetRAM1, pwm5, 5);

    pwmStop(hetRAM1, pwm5);
    pwmStart(hetRAM1, pwm5);
    pwmSetDuty(hetRAM1, pwm5, 0);
    }

    It does not work!

    Can you give me a verified code example for option a)?

    Best Regards,

    Pascal
  • Pascal,

    I don't have anything I can point you to -- there should be a post on this forum as the topic has come up but would need to do some searching for that post. I think the first time we analyzed the issue we had some example like this.

    The result of that analysis was to make the app-report explaining the blackbox driver - which is the first one I sent the link to in the previous reply.

    Now ... The problem is that you're writing to the MOV64 instruction back to back without allowing for a period where the duty is 1%.

    The MOV64 instruction .. the target of 'pwmSetDuty()' acts like a double-buffer to the 'output compare' function.

    If you update this double-buffer back to back then you likely miss the first value and it's the second value that will match - so you are essentially still implementing a 100%->0% change in one step.

    You need to delay the updates by the period match -- so that first the 1% gets processed then the 0%.

    The issue is in the way that the PWCNT instruction works and takes conditional branches I think ... so if you don't let that PWCNT actully process the 1% then you'll still see the same problem.

    For grins just try sticking in a long delay (for (); loop longer than a PWM period) between the 1% and 0% and you should see it work.

    You'll then want to synchonize your writes of duty cycle to the end of period event.

    Also I do not believe you need to start/stop the PWM to change the duty. Only the period.

    The first appnote I pointed you to in the previous post actually has the code used for the blackbox driver so if you want to get a better understanding of what I mean by MOV64 and PWCNT please look at this appnote.

    You can also take the code from this appnote and simulate it in the HET IDE - that will give you a very clear
    understanding of what is going on.

    Best Regards,
    Anthony