Instruction Set
1119
SPNU563A – March 2018
Copyright © 2018, Texas Instruments Incorporated
High-End Timer (N2HET) Module
An example N2HET program that makes use of the RCNT instruction is:
L0: MOV32 { remote=dummy,type=IMTOREG,reg=T,data=0x8,hr_data=0};
L1: PCNT { hr_lr=HIGH,brk=OFF,type=FALL2FALL,pin=0};
L2: RCNT { divisor=320,data=0x4};
L3: BR {cond_addr=L5, event = Z}
L4: ADC { src1=ZERO,src2=IMM,dest=IMM,next=L0,data=0,hr_data=0};
L5: ADD { src1=REM,src2=ZERO,dest=IMM,remote=L4,data=0,hr_data=0};
L6: ADD { src1=ZERO,src2=ZERO,dest=NONE,rdest=REM,
next=L0,remote=L4,data=0,hr_data=0};
dummy
In this small program an input signal on pin 0 is measured both in terms of absolute cycles by the PCNT
instruction at L1 and as in 1/10ths of the reference period by the RCNT instruction at L2. In this example
the reference period is a constant 0x400 cycles; this value is loaded into register T by the MOV32
instruction at L0. (0x400 is data=8, hr_data=0)
RCNT follows PCNT and is initialized to a working count of T/2 (0x200) whenever the PCNT instruction
detects a falling edge on pin 0. Between falling edges on pin0, RCNT accumulates counts 10x faster than
PCNT; so that the working data field of RCNT will reach the reference value of 0x400 in 1/10th the time
that a PCNT instruction would. Each time the RCNT instruction passes the reference value, it sets the
carry out flag and subtracts the reference value from the working count. By accumulating carry-outs from
RCNT, the add with carry instruction at L4 effectively counts in increments of 1/10th of the reference
period. Note that the divisor value 320 is 10 times 32; this assumes lr=32.
When the next falling edge is detected on pin 0, PCNT sets the Z flag and the RCNT instruction resets
again to the initial data field of T/2. RCNT does not modify the Z flag, so that the branch instruction at L3
can execute instructions at L5, L6 instead of L4. The instructions at L5 and L6 capture the final result from
L4 and reset the ADC instruction at L4 to zero for the start of the next period measurement.
Execution
If (register T[31:0] != 00000000h)
{
C = 0;
If (Z == 0)
{
Data Field[31:0] = Data Field[31:0] + Divisor[24:0];
If (Data Field[31:0] >= Reg T[31:0])
{
Data Field[31:0]=Data Field[31:0] - Reg T[31:0];
C = 1;
}
}
else
{
Data Field[31:0] = T[31:0] >> 1; /* T/2 */
}
}
Jump to Next Program Address;