FastPrepClocked Counter with Reset and Enable
Problems/Clocked Counter with Reset and Enable

Clocked Counter with Reset and Enable

Xilinx logoXilinx● EasyINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The phone interview asked for a counter design and a rough explanation of its states and code. Width, counting direction, reset, enable and timing were not disclosed. This exercise assumes a rising-edge up counter with synchronous reset, reset priority and unsigned wraparound. Software tests cover the state model, not Verilog synthesis. Approximate source match: 65%.

Model an unsigned width-bit up counter, starting at initial. Each row of cycles is [reset, enable] and describes one rising clock edge.

  • If reset is 1, set the count to 0, even when enable is also 1.
  • Otherwise, if enable is 1, add 1 and wrap from 2^width - 1 to 0.
  • Otherwise, hold the current count.

Return the count after every edge. This exercise grades the counter state transitions; it does not compile RTL or check circuit timing.

Function

counterValues(width: int, initial: int, cycles: int[][]) → int[]

Examples

Example 1

width = 2initial = 2cycles = [[0,1],[0,1],[0,1]]return = [3,0,1]

A 2-bit count ranges from 0 to 3. The three enabled edges produce 3, wrap to 0, then produce 1.

Example 2

width = 3initial = 7cycles = [[1,1],[0,0],[0,1]]return = [0,0,1]

Reset wins over enable, the next edge holds 0, and the last edge increments to 1.

Example 3

width = 1initial = 1cycles = []return = []

No clock edges means no output counts.

Constraints

  • 1 <= width <= 30.
  • 0 <= initial < 2^width.
  • 0 <= cycles.length <= 10000.
  • Each cycle has exactly two integers, both 0 or 1.

More Xilinx problems

  • Count Ones in a 16-bit WordONSITE INTERVIEW · Seen Feb 2019
  • Delete a Given Linked-list NodeONSITE INTERVIEW · Seen Feb 2019
  • Reservation-station Tag MatchONSITE INTERVIEW · Seen Feb 2019
All Xilinx interview questionsSee Xilinx hiring insights
Saved
public int[] counterValues(int width, int initial, int[][] cycles) {
    return new int[0];
}
Checking account…