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.

Stop CNT count on NHET

Hi,

i'am using CNT-instructions in my program. I have a function, which needs to stop/start the incrementation of the CNT-Instruction.

There is no bit in the CNT-Instruction which can be set in order to stop Incrementation.. And there is no "No-Op"-Instruction, which i could use by converting the CNT-Instruction into it.

Now, there is the bit angle_count, which can convert the CNT instruction into angle mode. In this mode (with NAF_global flag being 0), the data-field wouldn't be incremented. This would solve the problem. However, the User Manual says, that this mode needs 2 Cycles, but i need a CNT-Instr. with only 1 Cycle.

Does angle mode also need 2 instructions, when NAF_global flag = 0?
The user manual doesn't help me at all.

I have simulated this case in the HET IDE, and I need only 1 cycle.

But the user manual says "It takes two cycles in this mode." - Thats all. So does angle mode ALWAYS take 2 cycles?

Thx, RK

  • Hi RK,

    In order to help you get the answer quickly, I have forwarded you post to our NHET experts. They will reply you shortly.

    Thanks and regards,

    Ken Wang

  • Hi RK,

         I think you can put a DJZ instruction in front of the CNT. Such as: 

    L1:          DJZ {next = L2, cond_addr = L3, data = 0}

    L2:          CNT {…}

    L3:          …  next opcode in your program

     So

    If you write to the L1 data field a nonzero value, then this will enable

    The CNT instructions for that many loops.    So if you write a ‘4’ it will enable

    The CNT for the next 4 loops.


    You can always write a big number like 1FFFFFh and 0h to simulate ON/OFF for a long time too…  

     

    Alternatively, you could add a

     

    L1:     SUB {src1=ZERO, src2 = IMM, dest=NONE, data=0, hr_data=0}

    L1A:  BR {cond_addr = L2, next=L3, event=N}

    L2:    CNT{…}

    L3  rest of program…

     

    This will branch to L2 whenever the data field of L1 is zero;  or skip L2 and go to L3 Whenever the data filed is nonzero.

     

    You should not write to the program field of the N2HET when the N2HET is running. 

    Thanks,

    Ken Wang

  • Hi Ken Wang,

    my problem is, that I use 64 instructions in my HET program. So it is a big program and I dont want to put the LR up on 128. 8 of my 64 instructions are CNT-Instructions. And I don't have space for any other instruction like in your examples.
    At the moment, I have solved my problem by complicate functions, switching the "next-program-adress" of the previous instructions in order to skip the CNT instruction. I don't like that, so I wanted to find another way. That's why I asked the question about the angle_count bit.

    Now, you have mentioned that I shouldn't write to the program field of the HET, when it is running. In my solution, changing the "next-program-adress"-bitfield, I didn't have any problems (yet). Can you explain, why it is not recommended to write in the program field?

    Thx,

    RK

  • RK,

    It could cause undefined behavior if CPU modifies the program field while NHET is executing this instruction.

    Thanks and regards,

    Zhaohong

  • Zhaohong,

    thx for your answer...

    But this is so stupid... There is really no way to simply stop that counter while running, without using an additional dummy-instruction...? Seriously?
    I mean, would that have been so much trouble to make a simple "enable_count" - bit in the CNT-Instruction's bitfield? 

    RK



  • Hi again,

    sorry for my questions, but i'm still not happy with this solution, because I am trying to implement the HET in an Autosar Architecture, which is not easy... 

    Does it really make a difference, if I change the Program Field while the HET  is running or  Control/Data-Field? Just look at following example:

    - PWCNT-Instr. got the bitfield "pin_select" in the Control-Field. So i may change it during runtime. --> no problem.

    - PCNT-Instr. got the bitfield "pin_select" in the Program-Field. So i may NOT change it during runtime. --> undefined behaviour?

    Thx a lot, RK

  • RK,

    As I explained earlier, you should NOT change the instruction field at run time. NHET is actually a small uP. You cannot change the program while CPU is running from the same address.

    Thanks and regards,

    Zhaohong

  • RK,

    You can safely update the REMOTE NEXT field of an instruction through the new 'REMP' destination that is available on the

    ADD, SUB, etc.. instruction.   Don't know if this will solve your problem because it adds instructions.    You can't write directly to the program field from the CPU and do this robustly.

    Are you using the MAXCOUNT field of the CNT instruction to automatically reset the counter back to zero?  If not then maybe some other opcode would work better.

    The Angle flag would be harder to manage than the BR or DJZ that we suggested.

    Best Regards,

    Anthony

    Correction: 9/23/2013 - the REMOTE field is able to be updated, not the NEXT field. 

  • Thx for your answers.

    Yes, I am using the Max Count Field.

    I guess i will have to kick out some of my other instructions, in order to add the recommended DJZ-Instr...

    RK