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.

TMS570LC4357: N2HET SWAG - SCNT not counting correctly, missing teeth

Part Number: TMS570LC4357


Hello,

I'm working with the N2HET SWAG (APCNT, SCNT, ACNT) and I'm having some issues. It seems like the SWAG will completely miss teeth. I did some debugging and found the following:

First, the way my N2HET code is set up is that I find the gap (missing teeth/singularity) and then I start the SWAG. You can see in the picture below where I find the gap and when I start the SWAG:

Here is my SWAG code:

You can see in the first picture that there are SCNT counts missing. You can see it more clear here:

You can see that the SCNT correctly counts 8 steps in the first period (I have SCNT step=8). However, in the next period it completely stops. And then it starts again. This causes the SWAG to be wildly inaccurate.

Can anyone shed any light on this? Thanks. 

  • Just to clarify my issues more, you can see here that ACNT stops counting completely every other tooth.

  • What are the value for GAP_START and GAP_END?

    The step size is 8, the gap start is 8*(teeth-1)+1, and the gap end is 8*(teeth+1)-1 (assume 1 missing teeth).

  • Hi QJ,

    The gear has 60 total teeth with 2 missing (58 actual teeth). 

    Below is my calculation for GAP_START and GAP_END

  • Thanks Mark,

    Your code and parameters looks perfect. The output should be fine theoretically.

    Did you check the APCNT under flow flag? At the end of first period, the APCNT has under flow, the period and T register are cleared to zero, and the SCNT data field will not incremented as usual.

  • Hi QJ,

    I've enabled the APCNT underflow flag. When I run my code, it is never set. Should it be? 

  • Hello Mark,

    When the DCF or ACF are set, SCNT data field will decreased to zero and keeps zero until next event occurs. Those flags are set in ACNT instruction. ACNT detects period variations of the input signal measured by APCNT and compensates related counting errors. A period increase is flagged in DCF, and a period decreases is flagged in ACF.

    BTW. the APCNT and ACNT supports the input signal only on HET[2] pin.

    My test shows that SCNT works as expected, it counts for all the event (rise-to-rise). I monitored the data field of SCNT and ACNT manually. 

  • Hey QJ,

    That makes sense that either ACF or DCF = 1. Looking at the datasheet for the SCNT instruction, I see no other reason for SCNT to not increment (I checked to make sure T != 0)

    However, I don't understand why ACF or DCF are being set. Right now I'm simulating a toothed gear through software and there is very little variance between each period. It seems odd that those flags would be set every other tooth. 

    Also, I'm still stumped on my overall question, which is: why does ACNT take two cycles to reset and why does it miss teeth eventually?

    You can see here that it takes two full 360 degree turns of the gear for ACNT to reset:

    And this picture shows how ACNT will eventually start missing teeth. The first capture is from the start of the program. The second is from after it ran for a couple seconds:

    Is there by chance example code for using the software angle generator? I feel like I'm missing something.

  • Hello Mark,

    May I know what tool you are using to display the waveform of SCNT and ACNT?

  • Hi QJ,

    I don't have the paid version of wave viewer, so I can't really debug the HET code. Instead I run C code, flip GPIO lines, and use a logic analyzer to see when counters reset. Below is my C code. 

    That produces this result on the logic analyzer:

    Zoomed in:

    I've attached my HET code. Lines 1 - 16 are just finding the gap(missing teeth). After that the software angle generator is started. 3755.HET_gear.zip

  • Thanks Mark.

    I am doing the test, and come bac to you later.

  • Hi QJ,

    I believe I recently solved my issue. For some reason I had to modify the HR Prescale and the LR Prescale. I believe the default was HR = 0, LR = 8. I changed it to this:

    Now SCNT counts correctly:

    I'm still not sure why my default HR & LR values were causing an issue. I was checking to see if I had a program overflow exception before and there was none. 

    Now I just have a couple kinks to work out and I should have it working. Thanks.