Following, there is a description of the algorithms run by the 4 PICs of the board. The two TrapPics run the same code.
- ComPic algorithm (see Fig. C.10). The initialization of the PIC consists in setting up the ports and the variables. The main loop of the firmware (left scheme) continuously communicates with the USB transceiver, sending data and receiving orders from the host. A 4 kHz timer interrupt is enabled before entering the main loop. So, the interrupt is triggered every 250 s and the ComPic runs the instructions shown on the right scheme. The ComPic works as the master PIC that synchronizes the communication between the TrapPics and the MotorPic.
- TrapPic algorithm (see Fig. C.11). After initializing the code, the TrapPic sends the order to start a new conversion to the AD converter. The watchdog timer is a routine that reboots the PIC if it is not called, which automatically prevents possible code crashes. At this point, the TrapPic waits until the ComPic enters the interrupt subroutine and starts the interchange of data and orders. After processing the orders, the TrapPic performs the selected feedback. Other feedbacks allow to implement custom designed protocols such as oscillation or fast movement of the traps. Once the new position of the trap is calculated, it is written to the DAC and a new loop starts.
- MotorPic algorithm (see Fig. C.12). After setting up the 24-bit counter chips, the MotorPic enters the main loop. The MotorPic sends the value of the counter to the ComPic and receives the commands that it has to execute. The most relevant commands involve the movement of the motors. The control of the speed of the motor is also done by the MotorPic. The Time Out subroutine stops the motors in case a Goto command is not able to reach the target and prevents the everlasting movement of the motors. Finally, in the Goto check the motor is stopped if it has reached the desired position and the MotorPic starts another loop.