The present invention generally relates to encoding and decoding, and, more particularly, to a codec system based on a minimum change code.
This disadvantage limits the application range of the Gray code and the Johnson counter. For example, if a circuit originally requires only 17 levels of first-in-first-out (FIFO) memory (i.e., the memory depth is 17), it is necessary to expand the FIFO memory to 32 levels (when using the Gray code) or 18 levels (when using the Johnson counter) to ensure that each level corresponds to a decoded value, which allows for read and write operations at each level. This memory expansion is necessitated by the inability of both the Gray code and the Johnson counter to generate a recurrent sequence of length 17, leading to increased circuit costs and power consumption.
In view of the issues of the prior art, an object of the present invention is to provide a codec system, and an encoding circuit and a decoding circuit thereof, so as to make an improvement to the prior art.
An embodiment of the present invention provides a codec system that includes a conventional minimum change code generation circuit (the generated codes guarantee that there is only one bit change for each count change under certain conditions, for example, if it is the Gray code, it is applicable only to recurrent sequences whose length is a power of 2; the Johnson counter is applicable only to recurrent sequences whose length is an even number), a flag generation circuit, and a decoding circuit. The minimum change code generation circuit is configured to generate a digital code. The flag generation circuit is coupled to the minimum change code generation circuit and configured to generate a flag according to the digital code. The decoding circuit is configured to decode the digital code according to a preset value and the flag to generate an output value. The invention combines the flag and the digital code into a new code, which is applicable to any recurrent sequence length and can ensure that there is only one bit change for each count change.
Another embodiment of the present invention provides an encoding circuit that includes a minimum change code generation circuit and a flag generation circuit. The minimum change code generation circuit is configured to generate a digital code. The flag generation circuit is coupled to the minimum change code generation circuit and configured to generate a flag according to the digital code. The digital code corresponds to an output value. The output value is one of a periodic sequence. The period of the periodic sequence contains N values. The Rth value of the first period of the periodic sequence and the (N−R+1)th value of the second period of the periodic sequence correspond to the same digital code, where R is greater than or equal to 1 and less than or equal to N, and the first period and the second period are consecutive periods. The flag is a first value in the first period, the flag is a second value in the second period, and the first value is not equal to the second value.
Another embodiment of the present invention provides a decoding circuit. The decoding circuit receives a digital code and a flag, and decodes the digital code and the flag to generate an output value. The decoding circuit includes a minimum change code-to-binary code conversion circuit, a subtraction circuit, and a selection circuit. The minimum change code-to-binary code conversion circuit is configured to convert the digital code into a binary code. The subtraction circuit is coupled to the minimum change code-to-binary code conversion circuit and configured to subtract the binary code from a preset value to generate a difference. The selection circuit is coupled to the minimum change code-to-binary code conversion circuit and the subtraction circuit and configured to receive the binary code and the difference, and to output the binary code or the difference as the output value according to the flag.
The technical means embodied in the embodiments of the present invention can solve at least one of the problems of the prior art. Therefore, compared to the prior art, the present invention can increase the flexibility of circuit design to save costs.
These and other objectives of the present invention no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiments with reference to the various figures and drawings.
The following description is written by referring to terms of this technical field. If any term is defined in this specification, such term should be interpreted accordingly. In addition, the connection between objects or events in the below-described embodiments can be direct or indirect provided that these embodiments are practicable under such connection. Said “indirect” means that an intermediate object or a physical space exists between the objects, or an intermediate event or a time interval exists between the events.
The disclosure herein includes a codec system and its encoding circuit and decoding circuit. On account of that some or all elements of the codec system could be known, the detail of such elements is omitted provided that such detail has little to do with the features of this disclosure, and that this omission nowhere dissatisfies the specification and enablement requirements. A person having ordinary skill in the art can choose components or steps equivalent to those described in this specification to carry out the present invention, which means that the scope of this invention is not limited to the embodiments in the specification.
Reference is made to
The minimum change code generation circuit 320 generates a digital code GC. Because the minimum change code is a type of digital code, the minimum change code generation circuit 320 can also be referred to as a digital code generation circuit. The flag generation circuit 310 generates a flag FLG according to the digital code GC. The flag FLG is transmitted to the decoding circuit 330 via the transmission line BS1 (e.g., a trace or a bus), and the digital code GC is transmitted to the decoding circuit 330 via the transmission line BS2 (e.g., traces or a bus). The digital code GC contains M bits (GC_0, GC_1, . . . , GC_M−1), where M is a positive integer greater than 1. The flag FLG and the digital code GC together form an output code GCf, in other words, the flag FLG is one of the bits of the output code GCf.
The decoding circuit 330 decodes the output code GCf according to a preset value Npre to generate an output value Nout, which is a decoded value corresponding to an output code GCf. More specifically, the decoding circuit 330 decodes the digital code GC according to the preset value Npre and the flag FLG of the output code GCf to obtain the output value Nout.
Reference is made to
As shown in
For the output value Nout, the length of the recurrent sequence is N (i.e., there are N values in one period Ts, and N=5 in the example of
The aforementioned preset value Npre is N−1+Nout[0]. Taking
For the flag FLG, the length of the recurrent sequence is 2N (i.e., there are 2N values in one period Tb), and the content of the recurrent sequence (i.e., FLG[0] to FLG[2N−1]) is “0, 0, 0, 0, 0, 1, 1, 1, 1, 1.” More specifically, in the first half of the period Tb (i.e., FLG[0] to FLG[N−1]), the flag FLG is a first value (which is 0 in the example of
For the digital code GC, the length of the recurrent sequence is 2N (i.e., there are 2N values in one period Tb), and the content of the recurrent sequence (i.e., GC[0] to GC[2N−1]) is “000, 001, 011, 010, 110, 110, 010, 011, 001, 000.”
For the decimal number DC, the length of the recurrent sequence is 2N (i.e., there are 2N values in one period Tb), and the content of the recurrent sequence (i.e., DC[0] to DC[2N−1]) is “0, 1, 2, 3, 4, 4, 3, 2, 1, 0.”
For the digital code GC and the decimal number DC, the first half of the recurrent sequence is the mirroring of the second half of the sequence, and vice versa. More specifically, the Kth value of the recurrent sequence is equal to the (2N+1−K)th value of the recurrent sequence (1≤K≤2N), that is, GC[K−1]=GC[2N−1−(K−1)] and DC[K−1]=DC[2N−1−(K−1)].
Continuing the previous paragraph, from the perspective of the output value Nout, the Rth value of the period Ts1 and the (N−R+1)th value of the period Ts2 correspond to the same digital code GC (1≤R≤N). For example (referring to
Please continue to refer to
Continuing the previous paragraph, in most cases (except for R=(N+1)/2, where Nis an odd number), the Rth output value Nout of the period Ts1 and the Rth output value Nout of the period Ts2 correspond to different digital codes GC. For example, the second output value Nout of the period Ts1 (Nout[1]=1) corresponds to the digital code GC[1]=001, while the second output value Nout of the period Ts2 (Nout[1]=1) corresponds to the digital code GC[6]=010.
In summary, the output code GCf is the minimum change code, the lengths of the recurrent sequences of the flag FLG and the digital code GC are both 2N, and the length of the recurrent sequence of the output value Nout is N. In other words, a value of the output value Nout may correspond to two values of the output code GCf. For example, the output value Nout=0 (Nout[0]) may correspond to the output code GCf=0000 (GCf[0]) or 1110 (GCf[5]). The output value Nout=1 (Nout[1]) may correspond to the output code GCf=0001 (GCf[1]) or 1010 (GCf[6]); and so on. It can be observed that the present invention generates the output value Nout based on the minimum change code, and the length (N) of the recurrent sequence of the output value Nout does not have to be a power of 2 or an even number, greatly enhancing the flexibility of circuit design.
Reference is made to
Reference is made to
Reference is made to both
It can be observed from
Reference is made to
Reference is made to
The selection circuit 810 receives the reference code GCR1 and the reference code GCR2 and inputs one of the two as the target reference code GCRt according to the flag FLG. The reference code GCR1 is the maximum value of the recurrent sequence of the digital code GC (i.e., GC[N−1] or GC[N]), and the reference code GCR2 is the minimum value of the recurrent sequence of the digital code GC (i.e., GC[0] or GC[2N−1]). More specifically, when the flag FLG is at the first level, the target reference code GCRt equals the reference code GCR1. When the flag FLG is at the second level, the target reference code GCRt equals the reference code GCR2. In one embodiment, the first level may be 0, and the second level may be 1.
The comparator 820 compares the current digital code GC[K] with the target reference code GCRt to generate the comparison result CR. More specifically, when the current digital code GC[K] is equal to (or not equal to) the target reference code GCRt, the comparison result CR is 1 (or 0).
The selection circuit 830 receives the flag FLG and the inverted signal #FLG of the flag FLG and outputs one of the two as the next flag FLG′ according to the comparison result CR. More specifically, when the comparison result CR is 0, the next flag FLG′ is equal to the flag FLG (i.e., the flag FLG is not updated). When the comparison result CR is 1, the next flag FLG′ is equal to the inverted signal #FLG (i.e., the flag FLG is updated).
The flip-flop 840 is used to temporarily store the flag FLG. More specifically, the flip-flop 840 outputs the next flag FLG′ according to the clock wclk to replace the current flag FLG. The flip-flop 840 is reset according to the reset signal rst.
Reference is made to
Based on the current digital code GC[K], the minimum change code counting circuit 910 and the minimum change code counting circuit 920 respectively generate a candidate digital code GCc1 and a candidate digital code GCc2 according to a first order (forward) and a second order (backward). Taking
The selection circuit 930 receives the current digital code GC[K], the candidate digital code GCc1, and the candidate digital code GCc2 and outputs one of the three as the next digital code GC[K+1] according to the flag FLG and the comparison result CR of
The flip-flops 940 are used to temporarily store the next digital code GC[K+1]. More specifically, the flip-flops 940 outputs the next digital code GC[K+1] according to the clock wclk to replace the current digital code GC[K]. The flip-flops 940 are reset according to the reset signal rst.
Reference is made to
The minimum change code-to-binary code conversion circuit 1060 is used to convert the current digital code GC[K] into the current binary code DC[K] (i.e., the binary code corresponding to the decimal number DC).
Based on the current binary code DC[K], the binary code counting circuit 1010 and the binary code counting circuit 1020 respectively generate the candidate binary code DCc1 and the candidate binary code DCc2 according to the first order (forward) and the second order (backward). Taking
The selection circuit 1030 receives the current binary code DC[K], the candidate binary code DCc1, and the candidate binary code DCc2 and outputs one of the three as the next binary code DC[K+1] according to the flag FLG and the comparison result CR of
The binary code-to-minimum change code conversion circuit 1040 is used to convert the next binary code DC[K+1] into the minimum change code (i.e., the next digital code GC[K+1]).
The flip-flops 1050 are used to temporarily store the next digital code GC[K+1]. More specifically, the flip-flops 1050 outputs the next digital code GC[K+1] according to the clock wclk to replace the current digital code GC[K]. The flip-flops 1050 are reset according to the reset signal rst.
Reference is made to
The minimum change code-to-binary code conversion circuit 1110 is used to convert the current digital code GC[K] into the current binary code DC[K].
The subtraction circuit 1120 is used to subtract the current binary code DC[K] from the preset value Npre to obtain the difference Ndif (Ndif=Npre−DC[K]).
The selection circuit 1130 receives the current binary code DC[K] and the difference Ndif and outputs one of the two as the output value Nout according to the flag FLG. For example (referring to
The selection circuits 810, 830, 930, 1030, and 1130 may be embodied by a multiplexer.
The present invention can significantly improve the flexibility of circuit design. For example, the present invention may be applied to an asynchronous FIFO design. Reference is made to
The decoding end 1202 includes a clock domain crossing (CDC) synchronizer 1210 and a decoding circuit 330. The CDC synchronizer 1210 and the decoding circuit 330 are coupled to each other. The CDC synchronizer 1210 is used to synchronize the output code GCf to generate the synchronized output code GCf_s. Since the design and operating principles of the CDC synchronizer 1210 are well known to people having ordinary skill in the art, further elaboration is omitted for brevity. The decoding circuit 330 is substantially the same as the decoding circuit 330 in
When the codec system 1200 is applied to an asynchronous FIFO design, the encoding end 301 may be a part of the read (write) address generation circuit and configured to generate the read (write) pointer, and the decoding end 1202 may be a part of the write (read) circuit and configured to write (read) the FIFO memory according to the write (read) pointer. For example, when the output value Nout (=R) is used as the write pointer, it indicates data have been written to the FIFO memory at an address R, and the read circuit can determine whether there is data to be read in the FIFO memory according to the output value Nout. The depth of the FIFO memory is the length of the recurrent sequence of the output value Nout (i.e., N) (0≤R≤(N−1)).
In other embodiments, the encoding end and the decoding end of the codec circuit of the present invention may be on different devices. Reference is made to
Various functional components or blocks have been described herein. As appreciated by persons skilled in the art, in some embodiments, the functional blocks can preferably be implemented through circuits (either dedicated circuits, or general purpose circuits, which operate under the control of one or more processors and coded instructions), which typically comprise transistors or other circuit elements that are configured in such a way as to control the operation of the circuitry in accordance with the functions and operations described herein. As further appreciated by persons skilled in the art, the specific structure or interconnections of the circuit elements can typically be determined by a compiler, such as a register transfer language (RTL) compiler. RTL compilers operate upon scripts that closely resemble assembly language code, to compile the script into a form that is used for the layout or fabrication of the ultimate circuitry. Indeed, RTL is well known for its role and use in the facilitation of the design process of electronic and digital systems.
Note that the shape, size, and ratio of any element in the disclosed figures are exemplary for understanding, not for limiting the scope of this invention.
The aforementioned descriptions represent merely the preferred embodiments of the present invention, without any intention to limit the scope of the present invention thereto. Various equivalent changes, alterations, or modifications based on the claims of the present invention are all consequently viewed as being embraced by the scope of the present invention.
Number | Date | Country | Kind |
---|---|---|---|
112147534 | Dec 2023 | TW | national |