PIC Firmware


The PIC actively interfaces with both the hardware and the computer. Its tasks can be broken down into three parts. The control path, shown in Figure 1, summarizes firmware activity.

PIC Control Path
Figure 1: The diagram represents the major parts of the PIC's control path.

First, the PIC must perform initialization. It makes sure it has a connection with the computer and that the hardware is in a ready state. Second, it samples voltage heights and sorts the digital values into an on-board histogram. Third, the PIC periodically sends the histogram over USB to the computer.

Handling Pulse Events

The PIC uses the D flip-flop, or event latch, to detect whether or not a pulse has occurred. The PIC uses an internal comparator to determine when the pulse has finished and therefore when to start ADC sampling. Once the 10-bit ADC finishes sampling, it increments one of 1024 histogram locations, or energy bins on the PIC. Figure 2 represents this firmware histogramming process.

On-board PIC Histogram
Figure 2: The diagram illustrates how on-board PIC histogramming occurs. The histogram has 1024 bins, corresponding to the 10 bits of ADC resolution. If the ADC reads a pulse height value of '347', then the PIC increments bin 347.

Making a histogram on the PIC allows our MCA to count quickly without having to send data quickly. Without an on-board histogram, our MCA would have to send every 10-bit pulse to the computer, straining the limits of our USB data transfer rates.

Once the PIC has finished incrementing a histogram location, it resets the event latch and the PH circuit, allowing a new sampling cycle to begin.

Handling USB

The PIC sends its histogram using full-speed bulk transfer via endpoint 1. It sends packets of 64 bytes. Each packet consists of 1 byte protocol and 63 bytes data. The protocol is a code to make sure the PIC and the computer understand each other.

We want the PIC to send the histogram over USB at constant intervals. To do this, the host sends a vendor request every second or so, asking for data. This vendor request will flip hist_ready high, making the PIC send the histogram and the count. Once the PIC has finished sending all its data, it will restore hist_ready low. Since sending the entire histogram only takes a fraction of a second, the PIC spends most of its time waiting for pulses.