Control Box (part 4) Interrupts

stop sign

As was mentioned earlier, the rotational and vertical movement of our ROV will controlled via an interrupt that is triggered upon the pressing of the momentarily-closed push button switch found in the handle of the joystick. To help us to better understand how the directional movement of the joystick translates to directional movement of the ROV, consider the following diagram:

joystick diagram

The interrupt service routine can be found in the main.asm file. Aside from the joystick push-button switch, UART receptions containing any indicator/warning signals from the ROV can also trigger interrupts. After saving away our context variables, we determine the interrupt source with the following code:

code screen shot

Once determining the source of the interrupt, the appropriate sub-routine is called. These routines can be found in the interrupts.asm file.

Configuring the MCU for Interrupt

Now that we understand the general idea of what the interrupt is doing, let's take a look at how to configure our MCU so that it will trigger an interrupt upon the pushing of the joystick switch. This configuration (along with all of the MCU configuring) can be found in the init.asm file. In our case, the PB-switch will be connected to PORTB, 0. I configure this pin as a digital input (as well as all PORTB pins) with the following code:

movlw     b'11111111'

movwf   (TRISB ^ BANK1)

Peripheral, global and PORTB interrupts are enabled by setting the following bits in the INTCON and IOCB registers as seen below:

code screenshot

Recall that while INTCON, IOCIE is disabled here (for PORTB interrupt on change), it is enabled in our main loop upon reception of the ESC ready signal.

With all of the above completed, we have no effectively set up an interrupt service routine to handle rotational and vertical movement of our ROV. We will revisit the topic of interrupts when we discuss serial communication and the use of the UART module for both the control box and sub-surface vehicle.

Next up, Control Box (part 5/serial communication/UART)