Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VHDL code needed using modelism Use 100 MHz input clock, generate the following

ID: 3787381 • Letter: V

Question

VHDL code needed using modelism

Use 100 MHz input clock, generate the following frequencies: 5 MHz with 50% duty cycle 5 MHz with 75 % duty cycle 5 MHz with 25% duty cycle 10 MHz with 50% duty cycle The user should be able to select between the 4 frequencies at any time. Your entity should look like: entity freq_generator is port {i_clk: in std_logic; -- Your clock input I_sel: in std_logic_vector (2 downto 0); -- Your input mux o_freq: out std_logic -- Your output frequency); end freq_generator;

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;
const char BLANK = '.';
const char RED = 'R';
const char BLUE = 'B';
const char GREEN = 'G';
const char YELLOW = 'Y';
const char ROWS = 11;
const char COLUMNS = 4;
const char PLAYER1 = 0;
const char PLAYER2 = 1;
void initBoard(char board[][ROWS]);
void displayBoard(char board[][ROWS], char playerToColor[][2]);
int colorToPlayer(char color, char playerToColor[][2]);
int score(int player, char board[][ROWS], char playerToColor[][2]);
int main()
{
    char board[COLUMNS][ROWS];
    char playerToColor[2][2]; // first index = player number, second index = slot for color
    playerToColor[PLAYER1][0] = RED; // P1 = RED, BLUE
    playerToColor[PLAYER1][1] = BLUE;
    playerToColor[PLAYER2][0] = YELLOW; // P2 = YELLOW, GREEN
    playerToColor[PLAYER2][1] = GREEN;
    initBoard(board);
    displayBoard(board, playerToColor);
    cout << "Player 1 " << score(PLAYER1, board, playerToColor) << endl;
    cout << "Player 2 " << score(PLAYER2, board, playerToColor) << endl;
    system("pause");
}
void initBoard(char board[][ROWS])
{
    for (int x = 0; x < COLUMNS; x++)
        for (int y = 0; y < ROWS; y++)
            board[x][y] = BLANK;
    board[0][0] = YELLOW; board[1][0] = GREEN; board[2][0] = RED; board[3][0] = BLUE;
    board[0][1] = BLUE; board[1][1] = YELLOW; board[2][1] = GREEN; board[3][1] = RED;
    board[0][2] = RED; board[1][2] = BLUE; board[2][2] = YELLOW; board[3][2] = GREEN;
    board[0][3] = GREEN; board[1][3] = RED; board[2][3] = BLUE; board[3][3] = YELLOW;
    return;
}
void displayBoard(char board[][ROWS], char playerToColor[][2])
{
    for (int y = ROWS - 1; y >= 0; y--)
    {
        cout << setw(2) << y << ":" << " ";
        for (int x = 0; x < COLUMNS; x++)
        {
            cout << " ";
            if (colorToPlayer(board[x][y], playerToColor) == PLAYER1)
                cout << static_cast<char>(tolower(board[x][y]));
            else
                cout << board[x][y];
            cout << " ";
        }
        if (y == 10) cout << " 60";
        if (y == 9) cout << " 40";
        if (y == 8) cout << " 30";
        if (y == 7) cout << " 20";
        if (y == 6) cout << " 10";
        cout << endl;
    }
    cout << "     0 1 2 3" << endl;
}
int colorToPlayer(char color, char playerToColor[][2])
{
    if (playerToColor[PLAYER1][0] == color)
        return PLAYER1;
    if (playerToColor[PLAYER1][1] == color)
        return PLAYER1;
    // If it wasn't player 1 then it must belong to player 2
    return PLAYER2;
}
int score(int player, char board[][ROWS], char playerToColor[][2])
{
    int total = 0;
    int rowValue = 10;
    for (int y = 6; y <= 10; y++)
    {
        for (int x = 0; x < COLUMNS; x++)
        {
            if (board[x][y] != BLANK)
                if (colorToPlayer(board[x][y], playerToColor) == player)
                    total += rowValue;
        }
        rowValue += 10;
        if (y == 9)
            rowValue += 10;
    }
    return total;
}