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.

Standard project demo for hercules PWM

Other Parts Discussed in Thread: HALCOGEN

Hi,

I  have been trying to get nhet[1]0 runing as a PWM output and failing miserably.

I can drive the pin as GPI (Leds); but HalCogen genrated HET code does not seem to start the HET.

Does anyone have a simple hercules demo using the nets as PWM?

I also when I look to the HalcoGen generated PWM uCode I cannot relate the generated opcodes to the opcodes in the reference manual. EG.

Halcogen code snipit....

/* CNT: Timebase
* - Instruction = 0
* - Next instruction = 1
* - Conditional next instruction = na
* - Interrupt = na
* - Pin = na
* - Reg = T
*/
{
/* Program */
0x00002C80U,
/* Control */
0x01FFFFFFU,
/* Data */
0xFFFFFF80U,
/* Reserved */
0x00000000U
},

using debugger this is the code thats landed at hetRAM1.

but looking at  SPNU503B–November 2012–Revised August 2013, NET Instruction definitions....

Opcode for CNT is 0x06; I can't relate to 0x00002C80 generated by the halcogen. So I don't feel confident to rely on that manual to set breakpoints in the uCode.

20.5.3.8 CNT (Count)
Syntax CNT {
[brk={OFF | ON}]
[next={label | 9-bit unsigned integer}]
[reqnum={3-bit unsigned integer}]
[request={NOREQ | GENREQ | QUIET}]
[angle_count={OFF | ON}]
[reg={A | B | T | NONE}]
[comp ={EQ | GE}]
[irq={OFF | ON}]
[control={OFF | ON}]
max={25-bit unsigned integer}
[data={25-bit unsigned integer]
}
Figure 20-93. CNT Program Field (P31:P0)
31 26 25 23 22 21 13 12 9 8 7 6 5 4 1 0
0 Request BRK Next program address 0110 Angle Register Comp. Res. Int. ena
Number count select
6 3 1 9 4 1 2 1 4 1
Figure 20-94. CNT Control Field (C31:C0)

I would be grateful for any pointers.

Kind Regards,

Owain

  • Hi Owain,

    Pls refer to the below document which clearly explains every step involved in creating a PWM.

    http://www.ti.com/lit/an/spraba0b/spraba0b.pdf

    Hope this helps.

  • I found this video from TI useful for PWM with NHET:

    Hercules Tutorial: Using the NHET to generate a PWM
    http://youtu.be/O1BlOvi8Sn0

    If you follow it step by step, you have a NHET driven PWM example.

    Regards, Jan

  • Owian,

    I can see where the issue is in the CNT instruction comment v.s. TRM chapter.
    Will need to figure out which is right and we'll get back to you.

    EDIT: actually i checked it again on paper and it came out ok so I put it in a table:

    6740.cnt_opcode.xlsx

  • Thanks for the many suggestions.

    I built a standard project using HalcoGen 4 and see the PWM 0 running after the hetInit().

    I then moved on to using the various pwm api calls including; this one which I believe is wrong.
    Is the line I highlighted in RED a bug.... 

    comment says "period in uS"; yet hetSIGNAL_t structure defines period as a float; so I assumed that is in seconds. Obviously the cast on this line is such that any fractional value will be lost. Should thine actually be something like.

    pwmPeriod = (uint32)(temp << 7U);

     

    or 

    temp = temp << 7;
    pmPeriod = (uint32)temp;

     

     

    ???????

    void pwmSetSignal(hetRAMBASE_t * hetRAM, uint32 pwm, hetSIGNAL_t signal)
    {
    uint32 action;
    uint32 pwmPeriod = 0U;
    uint32 pwmPolarity = 0U;
    float32 temp = 0.0F;

    if(hetRAM == hetRAM1)
    {
    temp = ((float32)signal.period * 1000.0F) / 1163.636F;
    pwmPeriod = (uint32)temp << 7U;
    pwmPolarity = s_het1pwmPolarity[pwm];
    }
    else
    {
    temp = ((float32)signal.period * 1000.0F) / 1163.636F;
    pwmPeriod = (uint32)temp << 7U;
    pwmPolarity = s_het2pwmPolarity[pwm];
    }
    if (signal.duty == 0U)
    {
    action = (pwmPolarity == 3U) ? 0U : 2U;
    }
    else if (signal.duty >= 100U)
    {
    action = (pwmPolarity == 3U) ? 2U : 0U;
    }
    else
    {
    action = pwmPolarity;
    }

    hetRAM->Instruction[(pwm << 1U) + 41U].Control = ((hetRAM->Instruction[(pwm << 1U) + 41U].Control) & (~(uint32)(0x00000018U))) | (action << 3U);
    hetRAM->Instruction[(pwm << 1U) + 41U].Data = (uint32)((pwmPeriod * signal.duty) / (uint32)100U) + 128U;
    hetRAM->Instruction[(pwm << 1U) + 42U].Data = pwmPeriod - 128U;
    }

  • Thanks Anthony; I missed that shift; my decode was off by a bit. The opcode is 0x6 << 1.

  • I think I have another Halcogen bug.

    Staticly configuring PWM' and them being started via hetInit() seems to generate correct frequencies.

    Using the HalcoGen pwmSetSignal call does not seem to configure for correct frequencies.

    signal.period = 0.010 should be 10mS period, but get 780uS

    signal.period = 0.100 should be 100mS, but get 7.8mS

    ????

  • I have reverted back to standard halcogen generated driver.

    Passing period in in uS. period is correct.

    At a 1Hz frequency trying to set duty cycle of 50%; duty cycle is wrong, but frequency is correct.
    At 10Hz, 125Hz and 250Hz the 50% duty cycle is correct.

    At 1Hz and 90% duty again the duty cycle is wrong.
    At 10Hz, 125Hz and 250Hz 90% duty cycle is correct.

    I am running 8PWM's off Het1.

    Looks like most of my issues were my own.
    Although I think the documentation and use of floats in Halcogen; makes things a little confusing. IE use a float to pass an integral number of uS for the period into pwmSetSignal.

    Thanks for all your help.

    Regards,

    Owain