I was in two minds about whether to solder the chip directly to the board or get a socket for it. If it had arrived a little later in the day, I'd have used it as an excuse to go to the city centre and look in Maplin, but instead I was ill and my awesome mum kindly looked out for the Fedex package for me. I decided to just solder the chip, I'd done it before with the amp board and it seemed to work out fine. There was really no reason not to, unless I somehow installed the chip the wrong way around.
The dsPIC33's modules are mostly pin remappable (mostly the various intercommunication busses). The inbuilt audio DAC wasn't though, it was fixed at the upper right. When it's disabled, the pins act like any other: they can be used for analogue in, remappable modules or GPIO. It was a puzzle to fit the chip on top of the holes I'd gouged in the traces on the board. Eerily, the four holes I'd gouged in the board so I could mount resistors between DAC out and the pin headers were in exactly the right place to mount the 8-pin DIP DAC chip across. All I had to do is route power and ground, make REF, and figure out a way to put the two output channels beside each other for the pin header.
The DAC chip has the data interface (DATA, CLOCK, CHIP SELECT) on the left together with the primary out channel (why is it on that side, WHY). The other side has VDD, OUT B, REF, GND. I was thankful I ordered all the spare resistors I did, because I had to make 1V from 3.3V at the REF pin.
After installing it, and praying I hadn't blown the poor guy up, I then had to figure out how to communicate with it. I've never done SPI before, but it looked like I had the choice of triggering each word write manually by writing to a memory mapped register, or setting up an asynchronous DMA channel that would spew out words from a double buffered array in memory and raise interrupts whenever it was switching buffers.
I spent about an hour going between the two datasheets, trying to find a pair of settings that correlated. The DAC datasheet was really vague about whether or not it wanted you to toggle the chip select line up and down every time you transmit a word. A lot of SPI related guides say you should just hold the chip select line low always, but I kept it connected to the PICs GPIOs anyway in case I needed it. I reckoned the DAC chip did need a toggle, because there's a 'minimum chip select line held high between words' time given in a table somewhere else in the document. It's not shown on the timing diagram, and the timing diagram only shows the transmission of a single word. The dsPIC has a mode called 'framed SPI' which pulses the chip select between words, so after I matched up what I needed with what I could supply it all looked good to go.
It didn't work at first. The examples in the data sheets only give you parts of the final answer.
The final problem would have had me stumped for weeks if I hadn't been lucky enough to stumble on both how to identify the problem and solve it. The Ocelot has a LED on the front that I can control in software. Without the screen, it's the only visible feedback I can get from the machine while it's running. After noticing I wasn't getting anything on the scope, I decided to put an infinite loop in all my interrupt routines to see which ones were firing. If the interrupt fired, it would hit the loop and the light would get stuck. The DMA interrupt wasn't firing. This one is supposed to fire every time a block of 128 bytes (64 SPI words, or 32 pairs of stereo DAC instructions) has been transferred. For some reason, the dsPIC wasn't spewing out the data. The pin assignments were correct, and I was seeing the clock in the correct place (framed SPI runs the clock all the time, unlike normal SPI which stops the clock when not transmitting), but nothing was happening.
So I went online and looked for everybody who used PICs whose DMA interrupts ceased to function for unknown reasons.
It turns out that the solution to this is due to what I consider an oversight in the design of the dsPIC's SPI configuration. SPI is always bidirectional according to the PIC's model. If you have two sister chips communicating through SPI, each will be shifting bits out while at the same time receiving bits in. If you want to receive bits without transmitting them, the recommended way to do this is to enable a 'dummy write' in the DMA, where it'll pretend to be outputting data through SPI when it actually isn't.
There's no analogous configuration for just transmitting data though. The datasheet and the programming SPI guides don't mention this. They say you can have a just transmitting configuration if you follow the normal routine of enabling SPI, assigning pins, and setting up a DMA channel to ferry the data. But what it doesn't tell you is that that won't work. You're not receiving bits. Or rather, you're not handling the bits you're receiving, even if you're receiving phantom bits because you haven't assigned a physical pin to the DATA IN line. If you don't handle the bits you're receiving, that's an overflow event. The overflow event will raise a flag, and that will halt the entire SPI module until you clear it manually.
The recommended solution goes a bit like this: you either have to set up a second DMA channel (wasting it) to write the phantom bits to DMA-accessible memory (wasting it), and have stub interrupt routines that do nothing but waste time...
Or you can simply manually read from the SPI buffer in the SPI interrupt you already have that fires every time you receive a word. You'll be servicing that interrupt every time you transmit a word anyway, so there's nothing to be wasted by using it to also acknowledge the word you 'received'. unsigned int x = SPI1BUF;, and every problem simply disappears. I like my solution. :3
Once that was in place, it was GLORIOUS. Unlike the dsPIC's DAC, this TI chip gets your instructions and FRIGGIN' NAILS the voltage straight off. None of this 'oh, I'll give it a go, but I'll probably miss and it'll be a bit shaky'. No! You want 0.458 volts? BAM. DONE. NEXT. You want 0.2583V there and 1.564V over there at the same time? DOUBLE BAM.

You can barely see it on the right, but the DAC chip has some resistors to the right that make the 1V REF it needs (the DAC outputs between 0v and double your REF, as long as the max result is 1.2V lower than supply.).
It's done. I can't believe it's actually done. This is the final Ocelot mainboard, barring any oversights. (And there will have been some. There's been plenty so far.)
It's got Zipstick and Mega Drive input, four channel square wave sound, drives an oscilloscope in XY mode, runs off 3xAA batteries and gives you 40 magnificent MIPS of gaming goodness.
The improved regulator means there's low enough drop out for it to actually function off batteries, and there should be plenty of spare juice to support the Amiga mouse after all (provided it can be run off 3.3V not 5V).

The only things left to do now are to write some kick-ass software for the beast and make a case for it! The DoES guys keep saying I should pop down and make a nice laser cut case, but I didn't want to get carried before I'd made it functional in case I had to change the physical part of it for some reason (like the phono jacks being wrong or too capacitancy or too mushy or something I couldn't have possibly accounted for).
For software, first up I have to write a library to help me draw stuff to the screen. I have two approaches in mind, I can either write all my instructions and value directly into the final value buffers and have the DMA interrupt basically do nothing. Or I can build an array of simplified primitives and have the DMA interrupt parse them and expand them into full instructions in real time (Line xyxy, line xyxy, spline abcdefgh, point xy, point xy... could even have macro 'sprites' commands... useful for text maybe?). The former is more straightforward, but the latter would help if I wanted to have obscured line removal for 3D objects.




