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.

Recollecting the data from N2HET every X time

Other Parts Discussed in Thread: TMS570LS1115

Hi

I'm doing a quadrature encoder interface (for 12 encoders) using the N2HET on the TMS570LS1115. I wanted to know which instruction on the IDLE I have to use to send the data to the CPU every sampling period of the motor controller (PI)

I have already see some posts about the code for the counting but I'm not sure about something... I need to make the counting and depending which channel rises first, the count can go up or can go down... which condition would be the if??

I have this code for one encoder: 

A1_edge_detect ECNT { prv=ON,pin=0,event=RISE,reg=A,irq=OFF,data=0};
A1_count CNT { reg=A,comp=EQ,irq=OFF,max=360,data=0};

B1_edge_detect ECNT { prv=ON,pin=0,event=RISE,reg=A,irq=OFF,data=0};
B1_count CNT { reg=A,comp=EQ,irq=OFF,max=360,data=0};

I'm not sure if it is ok...

But, as you can see on the CNT, I dont have an irq, because I need the data to be send to the CPU every X time...

I hope you can help me...

Best regards!

Mike

  • Miguel,

    Hi.  If you want to interrupt the CPU every 'X time' then you need a counter that counts periodically to "X" and then is followed by an interrupt generating instruction or includes interrupt generation in the same instruction, like CNT does.


    What isn't clear to me is what you want to do - how to determine 'every X time'. 

    If by time you just mean clock time then you can simply add a CNT instruction into your HET program at the end, before the branch back to address 0, and have this interrupt the CPU periodically.


    If by 'X times' you mean every so many edges of the encoder, then the encoder state machine analyzes the input signal and when there are edges decides when to count and whether to count up or down.  But you would keep a separate count which could be a CNT instruction to count edges regardless of direction.  So you would just make sure that every path through the encoder state machine that results in an encoder 'count' also goes to your 'X times' counter so that this is updated whenever there is an encoder tick regardless of direction.

    Hope that helped.  Note that there is nothing that special about the CNT instruction that you can only have 1 per HET loop so adding additional CNT instructions to count different things is perfectly fine.

  • The X time is basically as you said. is clock time. You then recommend me to use a CNT instruction at the end of the loop so I have to adapt the sampling time of the PI to the loop time? 

    And ammm what about the code I propose? I know I need also add the if for the direction but... I think I can do that with the BR function no??

    best regards 

  • Hi Miguel,

    For the QEP code - have you looked at: this forum post?

    I would start with the code on that forum post since it's got some history behind it. 


    Sorry I don't understand the point about adapting the sampling time to the PI loop time.
    Just that if you want to periodically interrupt the CPU from the N2HET then a CNT that executes every loop resolution period is how you would do this.

    If you need to you can change the CNT maximum value to match some other rate.   What is the PI rate that you are trying to match?  Hopefully the HET Loop resolution period will be much faster (a few microseconds) than this rate and you will be able to get close enough for your purposes. 

  • Thanks Anthony

    About the QEP I have been reading that post (thanks for remember me the existence of that post). About the Sampling time... I need the transfer function to know the time but... lets say its about.... 324ms. So.. I could have count for the ticks of the timer or directly use a timer from the MCU, lets say the VCL4 and every N cycles from the timer, create an interrupt to the CPU to grab the data from the N2HET and then continue, without resetting the data.

    I dont know if that explain myself...

    best regards

  • Hi Miguel,

    If the time is about 324ms and the HET loop resolution period is in the range of 1-2us which it would be if you have a 128-word program that runs at 10ns clock (it would be 1.28us)  then I would think you could be within 1% or so of your target sample rate just using the N2HET to generate an interrupt to the CPU every N cycles. 

    You could also do the same with another counter like the RTI.  The advantage to using N2HET though might be that you would have some ability to coordinate the interrupt generation with the counting activity whereas they are decoupled if you use the RTI.   I think you will be ok though if that's your time-scale.