cat

Robocat Software Description

cat


The Robocat Computer Is Very Busy

A real cat can do many things simultaneously. But the computer in Robocat can only do one thing at a time. Software can make it appear that a computer can perform multiple tasks concurrently. This is done by rapidly switching between tasks. Computers have hardware to facilitate task switching. It's called an interrupt system. The PIC32MK1024 is particularly good at this. The PIC32MK1024 has a "7 level vectored, prioritized, preemptive interrupt system." (The Nicolet 1280 interrupt system is very similiar.)

The idea of an interrupt in a computer is very intuitive. You are having dinner and the phone rings. You know not to go to the front door because the door bell sounds differently. That's the idea of a vector. You may elect to ignore the phone while answering the door bell. That's the idea of priority. You may interrupt a phone call to answer the front door. That's the idea of preemption.

If you are not doing any of these things, you are in the uninterrupted state. I call this the foreground. I call the interrupted state the background. (The analogy is breaking down a little.)

Interrupts Solve The Concurrency Problem

Here is a list of tasks Robocat must perform concurrently. Timers cause interrupts. Interrupts perform tasks. This happens continuously.

1) A variable width pulse is sent to the neck servo 100 times per second.
2) Data is sent to the DAC (to make sound) at 11025 times per second.
3) Data from the ears are sampled at 250000 times per second.
Here is a list of tasks performed in the foreground.
1) Determination of significance of data coming from the ears.
2) Reacting to data coming from the serial ports.

The Ring Buffers

A ring buffer is a block of memory that has no beginning and no end. You can write to it forever. The old data disappears to make room for new. Data from the ears is written into ring buffers. This is a background activity.

The Peak Detector

You are in a room where several people are talking quietly. You hear sounds, but nothing attracts your attention. But then, somebody bangs on the table and starts shouting. That is significant and that does attract your attention. Robocat has software that does something similiar. It's called the peak detector.

Two criteria are used to identify a peak. They have more high frequencies. They are louder.

Peaks can only be identified retroactively. A peak is a peak only if another bigger peak is not found. Once a peak is identified, the ring buffer is frozen. There is another name for this process. It's called "mid signal triggering." If you have a digital oscilloscope, you know all about this.

Peak significance also depends on context. For example, Robocat will ignore a faint sound if it is preceded by a loud sound. It takes several minutes before Robocat responds to very faint sounds.

Computing the Correlogram

The data frozen in the ring buffers is ready to be used to compute the correlogram. It takes a massive amount of computing to compute a correlogram. That is because it is an "n squared" problem which means Robocat's computer could be overwhelmed.

It may be possible to use the Fast Fourier Transform (FFT) to reduce the computational effort. That would turn the problem into an "n log n" problem. A different trick was actually used. There is no need to compute the entire correlogram. Only the part near zero delay needs to be computed. The delays in the data can't exceed the delays between the ears. So, you only need to compute the pink data. Robocat would be twenty times slower without the trick. Whether this beats the FFT trick is not known.

cat



The Integrated Design Environment (IDE)

Microchip provides software for writing code for the PIC32MK1024. It's called MPLAB. You will also need the compiler. Even when compressed, you will download a gigabyte. More than three hundred chips are targetted by the IDE. All of this is free, but if you want all of the compiler optimizations to actually work, you will pay $40 per month. The "PRO" version of the compiler costs $1395. That gives you "priority access."

The PIC32MK1024 is a marriage of convenience. On one side, there is the processor, or computer. It comes from MIPS Technologies. On the other side, there are the peripherals. They come from Microchip. Verilog is a language that is used to describe hardware. Both the MIPs processor and the peripherals can exist in this form. The marriage was consummated by compiling the Verilog files together to create one piece of silicon. I have used Verilog to create a UART in a FPGA. It is a lot of fun.

You have the MIPs core processor surrounded by dozens of peripherals. Standing between the MIPs processor and the peripherals are the Special Function Registers (SFRs.) To make things happen, you read and write to SFRs. The manual for the PIC32MK1024 explains how to do this. The IDE knows the names of the registers and even the bits within the SFRs. Documentation for the PIC32MK1024 runs to 700 pages. It seems to be the bedrock truth, but it is intimidating.

I am familiar with MPLAB. I have used it professionally. It was used to develop a data system for an FTIR spectrometer. It had three PIC32 processors. I can tell you about several adventures and misadventures.

There are other IDEs. Mikroe, a German company, looks attractive. It costs $319 for a lifetime license. It includes a library of examples of working code. A good idea.

Permission to Rant Requested

The PIC32MK1024 is a complex beast. Microchip's attempts to hide this fact has created a mess. An early attempt at this involved the Peripheral Library (PLib.) The software written for the spectrometer utilized PLib. The current version of the IDE does not support PLib. It's been deprecated. You can get old IDEs from the archives, but they don't support the newer, faster chips. So it's rewrite time.

The MIPS processor won't perform very well unless it is configured. You have to set wait states. The pipeline defaults off. There is a mechanism to save the machine state that has to be activated. That speeds up interrupts. If configured correctly, the MIPS processor runs 6 times faster which is huge. Microchip promotes a code generator called "Harmony" which is supposed to solve problems like this. My attempts to use Harmony have not gone well. To be fair, newer versions might be better. What I would like to see is examples of functioning code.

There is more to rant about, but this rant is over.

^TOP^



cat