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.

TMS570LS1224: n2het instructions for using a hardware angle generator.

Part Number: TMS570LS1224
void vr_hwag_init(void) {

    hetREG1->HWAGCR0 = 0;
    hetREG1->HWAGCR0 |= 1; //HWAG module is not in reset.

    hetREG1->HWAPINSEL = 0;
    hetREG1->HWAPINSEL |= 2; //select input n2het[2].

    hetREG1->HWAGCR2 = 0;
    hetREG1->HWAGCR2 |= (1<<16); //Criteria is enabled.
    hetREG1->HWAGCR2 |= (1<<8); //Filter is enabled.

    hetREG1->HWAACNT = 128; //Start angle (Ticks period * start tooth)

                            //0h 4 ticks per period
                            //1h 8 ticks per period
                            //2h 16 ticks per period
                            //3h 32 ticks per period
    hetREG1->HWASTWD = 0x4; //4h 64 ticks per period

    hetREG1->HWATHNB = 57; //57 for a 60-2 toothed wheel

    hetREG1->HWATHVL = 2; //Start Tooth

    hetREG1->HWAFIL = 16; // Ticks * (1 - fil1%) Contains the value to be compared to the tick counter.

    hetREG1->HWAFIL2 = 48; // Ticks * 3 * (1 - fil2%) Contains the value to be compared to the tick counter during the singularity tooth.

    hetREG1->HETGCR = 0;
    hetREG1->HETGCR |= (1<<24); //Enables the pin output buffer structure
    hetREG1->HETGCR |= (2<<21); //The HTU and the arbiter output use a round robin scheme to access the N2HET RAM.
    hetREG1->HETGCR |= (1<<16); //N2HET is configured as a master.

    hetREG1->HETPFR = 0;
    hetREG1->HETPFR |= (0x5<<8); // /32 Loop-Resolution Pre-scale Factor.

    hetREG1->HETDIR |= (1<<1); //output n2het[1].
    hetREG1->HETPSL |= (1<<2); //pull-up input n2het[2].

    n2het_ram_init(hetRAM1,HET_INIT0_PST,3); //loading instructions in to n2het ram

    hetREG1->HETGCR |= 1; //N2HET is ON. The timer program execution starts synchronously to the Loop clock.

    hetREG1->HWAFLG = (1<<6)|(1<<2); //Clear Tooth Interrupt Flag and Gap Flag
    hetREG1->HWAENASET = (1<<6)|(1<<2); //Tooth Interrupt and Gap Flag enable;
}
L00   CNT { next=L01,angle_count=ON,reg=B,comp=GE,max=3839,data=128};
L01 ACMP { next = L02, en_pin_action = ON, pin = 1, action = SET, reg = B, data = 3712 };
L02 ACMP { next = L00, en_pin_action = ON, pin = 1, action = CLEAR, reg = B, data = 3776 };

N2HET and HWAG again.

https://youtu.be/QD1G8qWJAE4

What instructions do I need to use to work with hwag and what is the minimum set for working with it?
I did not find examples for working with a hardware angle generator.

  • Hello Ruslan,

    HWAG functionality is described in chapter 23.3.2 of TRM (  ) and HWAG registers are in chapter 23.5.

    I don't have any example regarding HWAG. There are some questions/answers regarding HWAG in the forum as well.

    Best regards,
    MIro

    Best regards,
    Miro

  • the image shows synchronization with the crankshaft position sensor. the yellow line is the second and third line of the timer program and they work correctly after the start, but after each revolution they are shifted due to an incorrect count of the angle counter - this is just an assumption.

    "In angle mode (angle count bit [P8] = 1), CNT needs data from the software angle generator (SWAG)."

    "The NHET can then implement its own angle counter (using a CNT instruction in angle mode) which will
    be incremented once per resolution by the value given by the angle increment."

    However, the instruction receives an increment from hwag, but as if not all.

    The top signal on the oscilloscope (link in first post) must be stationary.

  • Hello,

    The angle functions in NHET are for a combustion engine with toothed wheel. The assumptions in the angle generation are that the motor turns in one direction only, and that the RPM isn't changing very rapidly compared to the NHET loop resolution. What kind of motor are you working with?

  • at the moment I working with emulator(fpga based) signal of the crankshaft position sensor with 60-2 tooths.

        _hwag->acnt[het->HWATHVL] = het->HWAACNT;
        _hwag->pcnt[het->HWATHVL] = het->HWAPCNT1;
    	acnt unsigned int[58]	[0,64,128,192,256...]	0x08001300	
    		[0]	unsigned int	0	0x08001300	
    		[1]	unsigned int	64	0x08001304	
    		[2]	unsigned int	128	0x08001308	
    		[3]	unsigned int	192	0x0800130C	
    		[4]	unsigned int	256	0x08001310	
    		[5]	unsigned int	320	0x08001314	
    		[6]	unsigned int	384	0x08001318	
    		[7]	unsigned int	448	0x0800131C	
    		[8]	unsigned int	512	0x08001320	
    		[9]	unsigned int	576	0x08001324	
    		[10]	unsigned int	640	0x08001328	
    		[11]	unsigned int	704	0x0800132C	
    		[12]	unsigned int	768	0x08001330	
    		[13]	unsigned int	832	0x08001334	
    		[14]	unsigned int	896	0x08001338	
    		[15]	unsigned int	960	0x0800133C	
    		[16]	unsigned int	1024	0x08001340	
    		[17]	unsigned int	1088	0x08001344	
    		[18]	unsigned int	1152	0x08001348	
    		[19]	unsigned int	1216	0x0800134C	
    		[20]	unsigned int	1280	0x08001350	
    		[21]	unsigned int	1344	0x08001354	
    		[22]	unsigned int	1408	0x08001358	
    		[23]	unsigned int	1472	0x0800135C	
    		[24]	unsigned int	1536	0x08001360	
    		[25]	unsigned int	1600	0x08001364	
    		[26]	unsigned int	1664	0x08001368	
    		[27]	unsigned int	1728	0x0800136C	
    		[28]	unsigned int	1792	0x08001370	
    		[29]	unsigned int	1856	0x08001374	
    		[30]	unsigned int	1920	0x08001378	
    		[31]	unsigned int	1984	0x0800137C	
    		[32]	unsigned int	2048	0x08001380	
    		[33]	unsigned int	2112	0x08001384	
    		[34]	unsigned int	2176	0x08001388	
    		[35]	unsigned int	2240	0x0800138C	
    		[36]	unsigned int	2304	0x08001390	
    		[37]	unsigned int	2368	0x08001394	
    		[38]	unsigned int	2432	0x08001398	
    		[39]	unsigned int	2496	0x0800139C	
    		[40]	unsigned int	2560	0x080013A0	
    		[41]	unsigned int	2624	0x080013A4	
    		[42]	unsigned int	2688	0x080013A8	
    		[43]	unsigned int	2752	0x080013AC	
    		[44]	unsigned int	2816	0x080013B0	
    		[45]	unsigned int	2880	0x080013B4	
    		[46]	unsigned int	2944	0x080013B8	
    		[47]	unsigned int	3008	0x080013BC	
    		[48]	unsigned int	3072	0x080013C0	
    		[49]	unsigned int	3136	0x080013C4	
    		[50]	unsigned int	3200	0x080013C8	
    		[51]	unsigned int	3264	0x080013CC	
    		[52]	unsigned int	3328	0x080013D0	
    		[53]	unsigned int	3392	0x080013D4	
    		[54]	unsigned int	3456	0x080013D8	
    		[55]	unsigned int	3520	0x080013DC	
    		[56]	unsigned int	3584	0x080013E0	
    		[57]	unsigned int	3648	0x080013E4	
    	pcnt unsigned int[58]	[167725,167724,167725,167724,167724...]	0x080013E8	
    		[0]	unsigned int	167725	0x080013E8	
    		[1]	unsigned int	167724	0x080013EC	
    		[2]	unsigned int	167725	0x080013F0	
    		[3]	unsigned int	167724	0x080013F4	
    		[4]	unsigned int	167724	0x080013F8	
    		[5]	unsigned int	167724	0x080013FC	
    		[6]	unsigned int	167725	0x08001400	
    		[7]	unsigned int	167724	0x08001404	
    		[8]	unsigned int	168032	0x08001408	
    		[9]	unsigned int	167724	0x0800140C	
    		[10]	unsigned int	167724	0x08001410	
    		[11]	unsigned int	167725	0x08001414	
    		[12]	unsigned int	167724	0x08001418	
    		[13]	unsigned int	167724	0x0800141C	
    		[14]	unsigned int	167725	0x08001420	
    		[15]	unsigned int	168031	0x08001424	
    		[16]	unsigned int	167724	0x08001428	
    		[17]	unsigned int	167725	0x0800142C	
    		[18]	unsigned int	167724	0x08001430	
    		[19]	unsigned int	167724	0x08001434	
    		[20]	unsigned int	167725	0x08001438	
    		[21]	unsigned int	167724	0x0800143C	
    		[22]	unsigned int	167724	0x08001440	
    		[23]	unsigned int	168032	0x08001444	
    		[24]	unsigned int	167724	0x08001448	
    		[25]	unsigned int	167724	0x0800144C	
    		[26]	unsigned int	167725	0x08001450	
    		[27]	unsigned int	167724	0x08001454	
    		[28]	unsigned int	167724	0x08001458	
    		[29]	unsigned int	167725	0x0800145C	
    		[30]	unsigned int	168031	0x08001460	
    		[31]	unsigned int	167724	0x08001464	
    		[32]	unsigned int	167724	0x08001468	
    		[33]	unsigned int	167725	0x0800146C	
    		[34]	unsigned int	167724	0x08001470	
    		[35]	unsigned int	167724	0x08001474	
    		[36]	unsigned int	167724	0x08001478	
    		[37]	unsigned int	167725	0x0800147C	
    		[38]	unsigned int	168031	0x08001480	
    		[39]	unsigned int	167725	0x08001484	
    		[40]	unsigned int	167724	0x08001488	
    		[41]	unsigned int	167724	0x0800148C	
    		[42]	unsigned int	167725	0x08001490	
    		[43]	unsigned int	167724	0x08001494	
    		[44]	unsigned int	167724	0x08001498	
    		[45]	unsigned int	168032	0x0800149C	
    		[46]	unsigned int	167724	0x080014A0	
    		[47]	unsigned int	167724	0x080014A4	
    		[48]	unsigned int	167725	0x080014A8	
    		[49]	unsigned int	167724	0x080014AC	
    		[50]	unsigned int	167724	0x080014B0	
    		[51]	unsigned int	167725	0x080014B4	
    		[52]	unsigned int	167724	0x080014B8	
    		[53]	unsigned int	168032	0x080014BC	
    		[54]	unsigned int	167724	0x080014C0	
    		[55]	unsigned int	167724	0x080014C4	
    		[56]	unsigned int	167724	0x080014C8	
    		[57]	unsigned int	167725	0x080014CC
    	pcnt1	unsigned int	167724	0x080014D4	
    	pcnt2	unsigned int	503481	0x080014D8	
    	pcnt3	unsigned int	167724	0x080014DC

    Of course, I should check the values inside n2het, but for me it is not easy yet.
    Аnd I didn't get the angle increment overflow interrupt.

  • I don't have any tool to test HWAG.

  • Hello Ruslan,

    I'd like to test your code and investigate the issue. But I am sorry don't have tool to perform this kind of test.

  • I put a break point in the interrupt gap flag and that's what I got:

    CNT instruction data in n2het 3541 at first time and 3538 at second time.

    Gap flag rising on 57 tooth.

    [55] 3520

    [56] 3584

    [57] 3648

    L00 CNT {angle_count = ON,reg=B,comp=GE,max=3839,control=ON,data=128}

    L01 ACMP {control=OFF,en_pin_action=ON,pin=1,action=SET,reg=B,data=192}

    L02 ACMP {next=L00,control=OFF,en_pin_action=ON,pin=1,action=CLEAR,reg=B,data=256}

    interesting. the number of skipped angles(CNT) depends on HETPFR.

    at the first revolution on the gap I got a CNT value of 3645, which is 3 less than expected, instead of 110.

    Either the n2het examples are kept secret, or the microcontrollers turned out to be useless to anyone and therefore there are no examples after many years. Or maybe I'm so stupid that I can not understand the work of timers without examples or a minimal configuration.

    input signal 4.23kHz or 4230rpm

    Roland has the same problem:

    And the problem has not been resolved since 2015.