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.

TMS570LS1114: C programming of the N2HET module

Part Number: TMS570LS1114
Other Parts Discussed in Thread: HALCOGEN

Hi

Hello

A friend of mine posted this information last year but never got his answer. He asked me to do so

I'm working with the Hercules TMS570LS1114 and I need to connect 9 quadrature encoders with the N2HET. I saw the application note http://www.ti.com/lit/an/spna228/spna228.pdf with the state machine, which I could not tell if it worked because some problems with the simulated signals. I also read this post: http://e2e.ti.com/support/microcontrollers/hercules/f/312/p/536444/2021979 and found it quite helpful but today I was using Halcogen and on the het.h file I saw some functions for edge detection and also counters. I attach the image of that code. 

I was wondering if, even when Halcogen only supports 7 captures or 7 interrupts per HET and I need 14 on HET1 and 4 in HET2, if I could use those C functions to do the code or if there is another code for the module to be able to do the task since I tried to replicate the post I added here and had some problems. 

The N2HET module can be programmed in C? or it needs to be done with the N2HET IDE? 

There is also the option of the EDGE INTERFACE FUNCTIONS but since the encoders signals can be occurring at any time, this looks like will cause an interrupt on the CPU and I don't want that... 

Also how can I get the information about the encoders back to the CPU to use them? Do you have a C code for 1 quadrature encoder I could replicate to get the amount of quadrature readings I need?

Not too sure if the question is clear... 

Thanks and best regards!

  • Hello Miguel,

    The HALCoGen can generate code for very simple PWM, ECAP, Edge detection etc. For edge detection, it uses ECNT instruction. For ECAP, it uses PCNT instruction. This code is not able to implement the QEP (quadrature encoder) mentioned in SPNA228.

    NHET uses the instruction sets (30 instructions) defined in the TRM. It can not be programmed with C code. HET IDE is the best tool for debugging/simulating the NHET code.

    What is "Edge Interface Functions"? Sorry, I don't have any C code for quadrature encoder.
  • oh okok

    So the best way is using NHET ide. 

    QJ Wang said:
    What is "Edge Interface Functions"? Sorry, I don't have any C code for quadrature encoder.

    is un the image, as a title for some of the functions. 

    thanks!!

  • Hello guys

    I would really appreciate some help here...

  • Hi Miguel,

    As you have already knew, one QEP requires 3 NHET pins and at least 15 NHET instructions. If you only need one QEP, for example, copy the 15 instructions in the appnote to HET IDE and do a simulation to make sure it meets your requirements.

    1. Assemble the NHET code, a *.c and *.h will be generated

    2. In you C code (for example nhet.c), copy the c file into NHET RAM:

       memcpy((void*)hetRAM1, (void*)HET_INIT0_PST, sizeof(HET_INIT0_PST));

    3. NHET executes the code when NHET is enable (GCR register)

    4. You can change the control field, data field of any instruction of the code, for example change the data filed of the first instruction:

         hetRAM1->Instruction[0].Data = 0x0000;

         or hetRAM1->Instruction[pHET_START_0].Data = 0x0000;  where pHET_START_0 is defined din the *.h file (generated by HET IDE)

         or read the data field of a instruction 0:

         abc = hetRAM1->Instruction[pHET_START_0].Data

  • Thanks Wang

    Sorry for my late response. I had been out of the office. I will check that. 

    I alredy have a code using only two pins since i'm not interested in the index pin.

    What is this for??

    QJ Wang said:

    4. You can change the control field, data field of any instruction of the code, for example change the data filed of the first instruction:

         hetRAM1->Instruction[0].Data = 0x0000;

         or hetRAM1->Instruction[pHET_START_0].Data = 0x0000;  where pHET_START_0 is defined din the *.h file (generated by HET IDE)

         or read the data field of a instruction 0:

         abc = hetRAM1->Instruction[pHET_START_0].Data

    Best regards!

  • Hello Wang

    About the Edge interface functions

    What is "Edge Interface Functions"? Sorry, I don't have any C code for quadrature encoder.

    Are this instructions like... for recovering the data from the N2HET module??? or like to get an interrupt request everytime an edge is detected like to get the counter??

    Best regards

  • So... I could use those functions generated by HALCOGEN to recover the data from the N2HET? or is not like that?

  • Hello,

    For edge detection, the ECNT(event count) instruction is used to count the edges of the pulse. The event can be one of the following events:
    1. Falling edge
    2. Rising edge
    3. Both edges
    4. While the pin is HIGH
    5. while the pin is LOW
    6. NAF flag is set

    When an event occurs, the counter value (ECNT data field) is incremented.

    If the ECNT instruction is the 2nd instruction in your code, the ECNT is placed in 0xFF460010 (NHET1 RAM base address is 0xFF460000, and each instruction takes four 32-bit words). Each instructions consists of 3 sections: program, control, and data, and reserved (4th word). Data field is at 0xFF460018

    If the ECNT instruction is the 3rd instruction in your code, the ECNT is placed in 0xFF460020 (=base address + 0x10*(num-1)).

    edgeGetCounter is to read the value from 0xFF460018
    edgeResetCounter is to write 0 to 0xFF460018
  • Ok. Got it.
    So just to be clear. If I upload the code from the HET IDE to the MCU, I could get the data from the encoders with the edgeGetCounter??
    Thanks
  • Hello Miguel,

    You can use HET IDE to generate *.c code (an array), *.h file in which the label name is mapped to # of the instruction.

    you use memcpy to copy *.c data into NHET RAM.

    But you also need to modify the function of edgeGetCounter() to get the counter (ECNT) in your code. For example, this is your code:

    L00 CNT....

    L01 ECMP...

    L03 MOV32...

    L04 PCNT...

    L05 ECNT...

    L06 BR...

    The ECNT is the number #5 instruction in your code, the edgeGetCounter() should be changed to:

    uint32 edgeGetCounter(hetRAMBASE_t * hetRAM, uint32 edge)

    {

       return hetRAM->Instruction[5].Data >> 7U;

    }