A N 3 7 0
62
Rev. 1.0
If the user is using only 20 or 24-bit counters which require only 3 bytes of MTP storage then it is possible to have
5 such counters in the system with one byte to spare for independent user usage.
It is not possible to decrement any of the counters, but it is possible to initialize the counter with a customer chosen
value at any time.
The counters are manipulated in XDATA RAM, so the following flow must be followed when updating any counter
value(s):
1. Copy the read only array abMTP_RDATA[16] to XDATA RAM memory by calling pbMtp_Read() function. The
function returns a pointer to the 16 byte array in XDATA, which is known to all the counter manipulation
functions. Therefore, if working with balanced counters only, the return value of the pbMtp_Read() function can
be ignored.
2. Manipulate the selected counter or counters by vMtp_SetDecCount(), lMtp_GetDecCount(), and/or
vMtp_IncCount(). Those functions take biIndex indicating the starting byte index of the counter in the 16-byte
array and the biNibbleCnt to determine the counter width. Note that the biNibbleCnt has different meaning than
how many bytes each counter occupies in the MTP. See the table above.
3. Call the bMtp_Write() function to write the modified counter data to MPT.
It is up to the application to determine at what 16-byte array index, value 0 to 15, each counter begins. The only
requirement is that the counter bytes in the MTP must not overlap. The value of the byte index, biIndex, is then
passed to all the functions manipulating the particular counter. It is recommended, but not required, that the index
values are 0, 4, 8, and 12 for uniformly spaced counters in the MTP.
7.8.4. MTP Write Function and Interrupts
Very important:
The main MTP programming function bMtp_Write()
is time sensitive. In general, the MTP
programming process will produce unpredictable results if interrupted, even possibly damaging the MTP memory.
The function stores the original EA bit value upon entry and disables all the interrupts by setting EA = 0 around
critical parts of the code. Since the programming of the MTP takes about 9 ms, and can go up to 40 ms in some
cases, for some application having interrupts completely disabled during that period might be too disruptive. The
user can specify the maximum programming time after which, if the MTP programming is not finished, the
bMtp_Write() function will return with an error.
To allow for some critical interrupts to be serviced when executing the bMtp_Write() function, the global interrupts
are disabled only during critical parts of the MTP timing generation within bMtp_Write(). Therefore, for all practical
purposes, the global interrupts are enabled within the bMtp_Write() function.
If the interrupts are enabled when calling bMtp_Write() function it is the responsibility of the user application that in
every 1 ms sliding time window the compound time spent in all ISR routines is less than 120 µs.
Be advised that when the interrupt is invoked from within the bMtp_Write() function the device internal system clock
might be forcibly running at 24 MHz. If in any 1ms sliding time window the ISR interrupt time is more than 120 µs
the MTP proper functionality is no longer guaranteed and MTP hardware damage may occur.
It is highly recommended, if at all possible, that the interrupts are disabled by EA = 0 in the user application before
calling the bMtp_Write() function and enabled afterwards to avoid any problems, if at all possible. If not possible
then at least keep only critical interrupts, which really have to be serviced urgently, enabled during the
bMtp_Write() call and make the ISR for those really short.
Counter Width
MTP Bytes
Max Value
biNibbleCnt
20 bits
3
550k
3
24 bits
3
730k
4
28 bits
4
915k
5
32 bits
4
1040k
6