Explorer 16 will be used.

Question 1.
To set up the interrupt mechanism for Timer1, mention the name of the specific registers and the specific bits that need to be configured.

Question 2.
The primary oscillator is used as the clock source and its frequency is 7.648 GHz. The PLL is used. In that case, what is Fcy (Internal instruction cycle frequency)? Also, what is Tcy? You must show your calculation. Failing to do so will result zero mark for this question.

Question 3.
We want to send a character B (ASCII CODE 42H) through UART2 with 1 stop bit and using odd parity.
Q1. Write the packet. (3 Marks)
Q2. If baud rate is 9600, then, to transmit this packet, UART2 will take how much time? (3 Marks)

Question 4.
In Project#2, you are using TMR1 of Explorer 16 board. Say, we are going to use TMR1 to generate interrupt (with priority 5) at 200uSec interval. We will be using Tcy as the clock source for TMR1 with a Prescaler value of 1:8. Write an TMR1Init() to configure all the related registers for TMR1.

Question 1.

To set up the interrupt mechanism for Timer1, the specific registers that need to be configured are:

- T1CON (Timer1 Control Register)
- TMR1IE (Timer1 Interrupt Enable bit) in IEC0 (Interrupt Enable Control Register 0)
- TMR1IP (Timer1 Interrupt Priority bit) in IPC0 (Interrupt Priority Control Register 0)
- PR1 (Timer1 Period Register)

The specific bits that need to be configured are:

- Set T1CON.TON bit to enable Timer1
- Set T1CON.TCS bit to select the internal clock source for Timer1
- Set T1CON.TCKPS bits to configure the prescaler value for Timer1
- Set T1CON.TSIDL bit to continue Timer1 operation during idle mode if required
- Set TMR1IE bit in IEC0 to enable Timer1 interrupt
- Set TMR1IP bit in IPC0 to set the interrupt priority level for Timer1
- Configure the value in PR1 to set the period of Timer1 interrupt

Question 2.
To calculate Fcy (Internal instruction cycle frequency) and Tcy, we need to know the PLL multiplier used. Please provide the PLL multiplier value.

Question 3:
Q1. The packet to send the character B (ASCII CODE 42H) through UART2 with 1 stop bit and odd parity is:

Start bit (0) - Data bits (01000010) - Parity bit (O) - Stop bit (1)

Q2. To calculate the time taken to transmit this packet with a baud rate of 9600, we need to know the number of bits in the packet.

Answer 1:

To set up the interrupt mechanism for Timer1 in Explorer 16, the following specific registers and bits need to be configured:

1. PR1 (Timer1 Period Register): This register sets the value to which Timer1 will count. The interrupt will be generated when Timer1 reaches this value.

2. T1CON (Timer1 Control Register): The specific bits to be configured in this register are:
- TON (Timer1 ON bit): Set this bit to enable Timer1.
- TCKPS<1:0> (Timer1 Input Clock Prescale Select bits): Configure these bits to set the desired prescaler value for the input clock source of Timer1.
- TCS (Timer1 Clock Source Select bit): Set this bit to select the internal clock source for Timer1.

3. IEC0 (Interrupt Enable Control Register 0): The specific bit to be configured in this register is:
- T1IE (Timer1 Interrupt Enable bit): Set this bit to enable the Timer1 interrupt.

4. IPC0 (Interrupt Priority Control Register 0): The specific bits to be configured in this register are:
- T1IP<2:0> (Timer1 Interrupt Priority bits): Configure these bits to set the desired interrupt priority level for Timer1.

Answer 2:
To calculate Fcy (Internal instruction cycle frequency) and Tcy, we need the formula provided:

Fcy = Fosc / (PLLIDIV * (PLLODIV * 2))

Given:
Fosc = 7.648 GHz (oscillator frequency)
PLLIDIV = 2 (PLL Input Divider)
PLLODIV = 256 (PLL Output Divider)

Substituting the values into the formula:

Fcy = 7.648 GHz / (2 * (256 * 2))
= 7.648 GHz / (2 * 512)
= 7.648 GHz / 1.024
= 7.484 GHz

Therefore, Fcy (Internal instruction cycle frequency) is 7.484 GHz.

To find Tcy (Internal instruction cycle time):

Tcy = 1 / Fcy
= 1 / 7.484 GHz
≈ 133.486 ps

Therefore, Tcy is approximately 133.486 picoseconds.

Answer 3:
Q1. The packet to send a character B (ASCII CODE 42H) through UART2 with 1 stop bit and odd parity is:
START BIT - 0 - 1 - 0 - 1 - 0 - 1 - 0 - PARITY BIT (odd) - STOP BIT

So, the packet is: 0 1 0 1 0 1 0 1 (odd parity) (1 stop bit)

Q2. To transmit this packet at a baud rate of 9600, the UART2 will take the following time:
1 start bit + 8 data bits + 1 parity bit + 1 stop bit = 11 bits

Time per bit = 1 / 9600 = 104.166 μs

Total time for 11 bits = 11 * 104.166 μs ≈ 1.146 ms

Therefore, UART2 will take approximately 1.146 milliseconds to transmit this packet.

Answer 4:
Here is an example TMR1Init() function to configure all the related registers for TMR1 in Project#2:

```c
void TMR1Init() {
T1CONbits.TON = 0; // Disable Timer1 during configuration
T1CONbits.TCKPS = 0b10; // Set Timer1 input clock prescaler to 1:8
T1CONbits.TCS = 0; // Select internal clock source for Timer1

PR1 = 4000; // Set Timer1 period register for generating interrupt at 200uSec

IFS0bits.T1IF = 0; // Clear Timer1 interrupt flag
IEC0bits.T1IE = 1; // Enable Timer1 interrupt
IPC0bits.T1IP = 5; // Set Timer1 interrupt priority to 5

T1CONbits.TON = 1; // Enable Timer1 after configuration
}
```

Note: This is just an example implementation. The actual register names and their bits may differ depending on the specific microcontroller being used. Please refer to the datasheet or reference manual of your specific microcontroller for accurate register and bit names.

Question 1:

To set up the interrupt mechanism for Timer1 on the Explorer 16 board, the specific registers and bits that need to be configured are:

1. T1CON register: The Timer1 control register is used to configure Timer1 for interrupts. The specific bits to be configured are:
- TON (Timer1 ON bit): Set this bit to enable Timer1.
- TCKPS (Timer1 Input Clock Prescale Select bits): Set the appropriate prescaler value to divide the input clock for Timer1.
- TCS (Timer1 Clock Source Select bit): Set this bit to select the internal clock source for Timer1.
- TSYNC (Timer1 External Clock Input Synchronization Select bit): Set this bit if using an external clock source for Timer1.

2. PR1 register: The Timer1 Period Register is used to set the period or time interval for generating Timer1 interrupts. This register determines how long it takes for Timer1 to overflow and generate an interrupt. Configure this register with the appropriate value based on the desired time interval.

3. IEC0 register: The Interrupt Enable Control register 0 is used to enable individual interrupt sources. Configure the specific bit corresponding to Timer1 interrupt to enable Timer1 interrupts.

4. IPC0 register: The Interrupt Priority Control register 0 is used to set the priority of the Timer1 interrupt. Set the specific bits corresponding to the Timer1 interrupt to assign a priority level.

Question 2:
To calculate the Fcy (Internal instruction cycle frequency) and Tcy for a system using the primary oscillator as the clock source with a frequency of 7.648 GHz and using the PLL, follow these steps:

1. Determine the PLL multiplier and divider values:
- Check the datasheet for the microcontroller being used to find the PLL configuration settings.
- Determine the PLL multiplier (N) and PLL divider (M) values used in the configuration.

2. Calculate the PLL output frequency (Fosc) using the formula:
Fosc = (Primary oscillator frequency) * N / M

3. Determine the divide by 2 for the PLL (ODIV2) if applicable. If ODIV2 is enabled, divide Fosc by 2.

4. Calculate the Internal Instruction Cycle Frequency (Fcy) using the formula:
Fcy = Fosc / 4

5. Calculate the Internal Instruction Cycle Time (Tcy) using the formula:
Tcy = 1 / Fcy

Make sure to substitute the actual values for the primary oscillator frequency, PLL multiplier, PLL divider, and ODIV2 if applicable, in the above calculations to get the final values of Fcy and Tcy.

Question 3:
To send a character 'B' (ASCII CODE 42H) through UART2 with 1 stop bit and using odd parity, the packet can be constructed as follows:

1. Start Bit: UART always starts transmission with a low (0V) start bit for synchronization.

2. Data Bits: The ASCII code for character 'B' is 42H, which is represented by the binary value 01000010. The data bits are transmitted LSB (Least Significant Bit) first, followed by the parity bit.

3. Parity Bit: Since odd parity is used, the parity bit is set to ensure that the total number of 1s in the data bits and the parity bit is odd.

4. Stop Bit: Set to 1 to indicate the end of the transmission.

The complete packet for transmitting character 'B' through UART2 with 1 stop bit and odd parity would look like this:
0 | 01000010 | 1

To calculate the time taken to transmit this packet with a baud rate of 9600, you need to know the number of bits in the packet (start bit, data bits, parity bit, and stop bit). In this case, the packet has a total of 10 bits.

Time taken to transmit = (Number of bits) / (Baud rate)
= 10 / 9600
= 1.042 ms

Therefore, it will take approximately 1.042 milliseconds to transmit this packet using UART2 with a baud rate of 9600.

Question 4:
To configure all the related registers for TMR1 in Project#2 on the Explorer 16 board to generate interrupts at a 200uSec interval with priority 5, using Tcy as the clock source and a prescaler value of 1:8, you can write a function named TMR1Init() with the following code:

void TMR1Init() {
T1CONbits.TON = 0; // Disable Timer1

// Configure Timer1 control register (T1CON)
T1CONbits.TCKPS = 0b10; // Set the prescaler value to 1:8
T1CONbits.TCS = 0; // Set the internal clock source for Timer1
T1CONbits.TSYNC = 0; // Set the Timer1 external clock input synchronization

// Configure Timer1 period register (PR1)
PR1 = 200; // Set the period value for Timer1 to 200

// Configure Timer1 interrupt priority and enable
IPC0bits.T1IP = 5; // Set priority 5 for Timer1 interrupt
IEC0bits.T1IE = 1; // Enable Timer1 interrupt

TMR1 = 0; // Reset Timer1 counter

T1CONbits.TON = 1; // Enable Timer1 and start counting
}

This function initializes all the necessary registers for Timer1 to generate interrupts at a 200uSec interval with priority 5 using Tcy as the clock source and a prescaler value of 1:8.