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.

Basic / Sample program for updating duty cycle (HET -> HalCogen -> CCS )

Other Parts Discussed in Thread: HALCOGEN, TMS570LC4357

Hello, 

I'm new to the world of microcontrollers. I am working on HET IDE for my MCBTMS570 Development Kit.  

I had generated code on HET and successfully imported to CCS. Furthermore, I want to program the code updating duty cycle when I'm pressing the switch.   I am getting problem in setting  the register values in main function (CCS). In particular, I'm looking for how to set  the values in hetRAM and hetREG bitwise.   

Is there any guide / sample program  where I can find in the detail ?

 

Regards,

Suyog

  • Hi,

      Here is a simple project I created. The HET program is generating a simple PWM with a 50% duty cycle PWM. In the application I try to change the duty cycle to 60% and then to 70%. See below.

    ; PWM with synchronous duty cycle update at compare match event
    L00 CNT     {  reg=A, irq=OFF, max= 100 }
    L01 ECMP   {  next=L03, cond_addr=L02, en_pin_action=ON, pin=0, action=PULSELO, reg=A, data= 50, hr_data=0}
    L02 MOV32 { remote=L01, type=IMTOREG&REM, reg=NONE, data=50, hr_data=0} ; CPU to write to this data field
    L03 BR        { next= L00, cond_addr=L00, event= NOCOND }





    void main(void)
    {
    /* USER CODE BEGIN (3) */
    
    	int i = 0;
    
    	hetInit();
    
    	hetRAM1->Instruction[L02].Data = 60 << 7; // Change the duty cycle to 60%
    
    	for (i=0; i<10000000;i++);
    
    	hetRAM1->Instruction[L02].Data = 70 << 7; // Change the duty cycle to 70%
    
    	while(1);
    
    
    /* USER CODE END */
    }
    

    You can use the scope to see the PWM on NHET[0] pin.

    Here is the project.

    3021.simple_PWM.zip

  • Hello,

    I'm going though your program. I need more time to understand it well.

    I wanted to execute same program with only 1 change - I changed  the o/p pin to '1' instead of pin '0' . I'm getting declaration problem in het.c file.This is my error  - 

    Description Resource Path Location Type
    #148 declaration is incompatible with "void edgeDisableNotification(uint32)" (declared at line 657 of "C:/myWorkspace/duty/include/het.h") het.c /duty/source line 738 C/C++ Problem 

    for many kind of these functions

    Regards,

    Suyog

    5228.duty.rar

  • Hi Suyog,
    How did you create the project? Did you use the HalCoGen to generate the project? Did you somehow mix some files from the HalCoGen generated .h files with the het.c files in the project I sent you? Please generate your project from HalCoGen.

    Below is just one example of your problems. They are not compatible with each other.

    in het.c
    void capGetSignal(hetRAMBASE_t * hetRAM, uint32 cap, hetSIGNAL_t *signal)

    in het.h
    hetSIGNAL_t capGetSignal(uint32 cap);
  • Hello, 

    Yes,  I had  made lots of changes and didn't go well. Here again, I am creating the project from scratch and  facing few issues

    1. Without  writing a single line of code, I'm getting error -

      error #10056: symbol "HET_INIT0_PST" redefined: first defined in "./duty1.obj"; redefined in "./source/duty1.obj"

    2. Declaration part - I found in reg_het.h your case while in case of mine it is in het.h
      Do I have to do this explicitly?
    typedef volatile struct hetInstructionBase
    {
        uint32 Program;
        uint32 Control;
        uint32 Data;
        uint32   rsvd1;
    } hetINSTRUCTION_t;
    
    
    /** @struct hetRamBase
    *   @brief HET RAM Definition
    *
    *   This structure is used to access the HET RAM.
    */
    /** @typedef hetRAMBASE_t
    *   @brief HET RAM Type Definition
    *
    *   This type is used to access the HET RAM.
    */
    typedef volatile struct het1RamBase
    {
        hetINSTRUCTION_t Instruction[160U];
    } hetRAMBASE_t;

     3.   As per my  generated code -

        hetSIGNAL_t capGetSignal(uint32 cap);

      As  per your code 

        void capGetSignal(hetRAMBASE_t * hetRAM, uint32 cap, hetSIGNAL_t *signal);

    Again is it explicit declaration ?

    4. Is there any tutorial to work from scratch  ? Its been problematic for me to understand it well. I am going through section 3 of  this doc   .

    Regards,

    Suyog

    1682.duty1.rar

  • Hi,

    1. The reason that you have redefinition of the obj is because you have two duty1.c files. You need to exclude one of the from build. Select one of the duty1.c files and right-click to select Resource configurations->exclude from build... Once I do that everything compiles file. I see one duty1.c under the source folder and another duty1.c at the top level. I excluded the duty1.c at the top level and everything compiles fine.

    2 & 3. You should use what is generated from HalCoGen per your device. Earlier I generated the code using a different device. I didn't know what device you were using. There is some differences in the generated code between different devices. But stick with the generated code from HalCoGen per your device. Don't mix between devices. This is when you can get compilation errors.

    4. Not sure what you are looking for. Here is a HET IDE Tutorial on how to use the HET IDE. Hope this is useful to you. www.ti.com/.../spnu485c.pdf
  • Hello Suyog,

    I have uploaded a project that I made to do the same using TMS570LC4357 development kit. The project generates an initial PWM of 4.00% Duty cycle with a period of 2ms. The Duty cycle can be changed in the increments of 0.01 by pressing the user SWITCH A, B.

    The Project is made using CCS and HALCoGen.7723.BUTTON_PWM_HET.7z Please note that I am generating the PWM on HET PORT1 PIN 8.

  • Hello,

    1. I'm cleared with all Errors. No problem, Now !!

    2. I'm generating the code through HalCoGen 4.6.0. In my include folder, It's generating only 32 header files while in case of you I noticed its 80+. Do I have to copy those files externally?

    Regards,
    Suyog
  • Hello, 

    Finally sorted out with the issue with debugging. 

    I am few queries stated in comments-

    When I executing the code -

    ; PWM with synchronous duty cycle update at compare match event
    L00 CNT     {  reg=A, irq=OFF, max= 100 }
    L01 ECMP   {  next=L03, cond_addr=L02, en_pin_action=ON, pin=0, action=PULSELO, reg=A, data= 50, hr_data=0}; after comleting 1 PWM it will allow to change the duty cycle 
    L02 MOV32 { remote=L01, type=IMTOREG&REM, reg=NONE, data=50, hr_data=0} ; CPU to write to this data field
    L03 BR        { next= L00, cond_addr=L00, event= NOCOND }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    void main(void)
    {
    /* USER CODE BEGIN (3) */
        int i = 0;
        hetInit();
        hetRAM1->Instruction[L02].Data = 60 << 7; // Change the duty cycle to 60%
        for (i=0; i<10000000;i++); delay till 60% duty cycle (1 complete cycle ) is finished ? 
        hetRAM1->Instruction[L02].Data = 70 << 7; // Change the duty cycle to 70%
        while(1); // all above code should be in while loop , i think it will only run last written duty cycle 
    }

    I thought, it will run in alternate fashion 60%-70%-60%-70%.

    fig : duty cycle not appearing in alternate order

    But it isn't because of 

    1. Last written is not read, and new data is already written ?

    2. No sufficient delay, causing next data to write before earlier data is read?

    or any other reason.

    Regards,

    Suyog

  • Hi Suyog,

      That is not how the code was written on the application side. I simply change from 60% to 70% and then end. You can easily modify the code to repeat between 60-70% by putting the them in a loop.