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.

Counting steps for step by step motor.

Other Parts Discussed in Thread: HALCOGEN


Hello,
I am driving a step by step motor from two N2HET signals in RM48 microcontroller.
I want to up/down count the pulses sent to the step by step motor.
I tried to use the ECNT instruction of N2HET on the output signal but this does not work.
I see it’s not possible to share an output signal with the input on the associated pin.
Do you know a simple solution to count the emitted pulses on output N2HET signal ?
Thank a lot for your help

  • one of our timer experts will help you with this.
  • Hi Jerome,

     

    You can use Analog Loopback to achieve this. You can use the Loopback Registers (Pair Select and Pair Direction registers) to configure the type of loopback, pins to be connected and the direction of the connected pins. You can read more about it in the TRM (N2HET Module > N2HET Functional Description > I/O Control > Loop Back Mode).

    Also, when I tested the case you mentioned with my setup, I was able to share the output signal with the input on the same pin. I think you can share the output pin with the input instruction as long as you are not using HR instructions for this(I haven't seen any documentation which clarifies this though).

     

    Thanks and Regards,

    Vineeth

  • Hi Vineeth
    Thank a lot for your help.
    Yes, you are right, I can count the pulses on the output pin. I made a mistake.
    So the N2HET program is the following:

    Per .equ 40
    Per4 .equ Per/4
    Per2 .equ Per/2
    Per34 .equ Per4*3

    L00 CNT { reg=A, irq=OFF, max = Per};
    ECMP { cond_addr= L00, hr_lr=LOW, en_pin_action=ON, pin=24, action=SET, reg=A, irq=OFF, data= Per4, hr_data = 0x0 };
    ECMP { cond_addr= L00, hr_lr=LOW, en_pin_action=ON, pin=15, action=SET, reg=A, irq=OFF, data= Per2, hr_data = 0x0 };
    ECMP { cond_addr= L00, hr_lr=LOW, en_pin_action=ON, pin=24, action=CLEAR, reg=A, irq=OFF, data= Per34, hr_data = 0x0 };
    ECMP { cond_addr= L00, hr_lr=LOW, en_pin_action=ON, pin=15, action=CLEAR, reg=A, irq=OFF, data= Per, hr_data = 0x0 };
    ECNT { pin= 24, event=RISE, reg=B, data=0};
    ECMP { pin=0, en_pin_action=OFF, reg=B, irq=ON, data=1000 }

    The last instruction generates an interrupt when the step count reach 1000.
    I have a difficulty to find the address vector of this interrupt. With HCG I just find this 2 V.I.M. entry points:

    het1HighLevelInterrupt
    het1LowLevelInterrupt

    If you have any information on that, thank a lot by advance.
  • Hi Jerome,

     

    The pending interrupt with highest priority can be seen in the Offset register(HETOFF) and all pending interrupts can be seen in the Interrupt Flag register(HETFLG).

    In the N2HET, the interrupts are tied to the instruction numbers. There are only 32 interrupts available for the instructions. But there can be 160 instructions on the N2HET. So every instruction will share its interrupt with the “32nd“ instruction coming after it on the RAM. This is done as in the table below which shows corresponding Offset value for each instruction.

     

     

    If you are using HALCoGen you can find the implementation under the tab (HET1 > HET1 Global Timing Configuration > Interrupt Enable settings) if you are not using the black-box driver already provided.

     

    So in your case, the last instruction corresponds to the offset value 7. So you can enable the 7th interrupt by setting the 7th bit in the Interrupt Enable Set register(HETINTENAS).

    The het1HighLevelInterrupt and het1LowLevelInterrupt that you mentioned are related to the priority setting of the particular interrupt. The priority can be set in the Interrupt Priority Register(HETPRY). If the priority is “high”, your interrupt offset will be loaded to the HETOFF1 register. If it is “low”, it is loaded to the HETOFF2 register. This will be “Low” by default.

     

    You can find more info in the TRM (N2HET Module > N2HET Functional Description > Interrupts and Exceptions).

     

    Thanks and Regards,

    Vineeth