Asteroids on Oscilloscope

The Joy of Tech - Anything and everything about all things shiny..
Post Reply
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Desoldered the regulator and put it on back on the right way. It still works!
Also modified the divider to increase its safe range to accomodate the 9v battery. It still works!

There was a bit of a dodgy moment when I felt the regulator getting hotter than I thought it ought to. The casing shouldn't have gotten as hot as it did just from my soldering. On top of that, the voltages I was reading were completely out of whack. It was almost as if there was a short somewhere. Gnerk! Turn it off, turn it off! Resolder it!
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Where's my PICkit, Farnell?

Four days ago, same day shipping: no gizmo.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

While I'm waiting for the remaining components, it's time to test out the joystick connector! Right now I'm waiting for the tantalum capacitor and the audio resistors. I ordered some more audio resistors when I finally decided (a month after drawing the thing out) that being able to have different volumes on each channel was probably a great idea after all. The resistors and the tant cap arrived prompty, the PIC kit not so much even though I ordered them at exactly the same time (AND Farnell said the PIC kit shipped first).

For the 9-pin header on the left, the theory is that I can connect it to a 9-pin connector, plug in an Amiga joystick or a Sega Mega Drive pad, and with the microcontroller in pull-up mode I can detect the switch pressings without any further external components. The Amiga joystick and Sega pad neatly overlay on one another in terms of pins, with the Sega pad only needing an extra voltage supply and 'Select' pin that are not connected to the Amiga joystick.

Does it work? Let's find out!

There's no code here, this is all just the physical connection from the pin header through the socket. Click the stick, a switch closes, completing a circuit to ground. So there's the joystick done, as far as my knackered old crappy scavenged cable and crappy soldering will allow.

At this point, I've got a grey ribbon cable connecting the D-sub connector the Ocelot. I manually soldered each of those nine wires to its place on a 10-gang pin socket piece. Never ever do that. It's a really crap idea. If you want wires with a pin socket piece on the end, buy a pin socket jumper cable, halve it and strip it. Do not take an old floppy drive cable and try to strip its cables. Soldering to a D-sub is bad enough, but having to do it twice because you made an idiotic choice the first time is lunacy. Scavenging and making do is a load of right-old bollocks and will get you nowhere and you will regret it. (Eagle eyed readers will notice that I did exactly the same thing to make the 3-pin cable that joins the Amp board to the motherboard. That was EVEN WORSE an idea.)

While still waiting for the PIC kit to arrive, I ordered some of those jumper socket cables from Hobby Electronics on Amazon. I picked them because they were the only seller I could find on the entire site that wasn't in CHINA (THANKS AMAZON FOR NOT LETTING ME SEARCH BY SELLER LOCATION THANKS), but just like Bitsbox they sent the cables by First Class Recorded even though I didn't ask for it. I suppose these tiny places run off reputation and like to always give 100% (or maybe they feel like they've gotta actually earn that postage fee), so good for them. I've got a 10% off code for them if anybody wants it.

Wednesday comes, and brings with it:

Image
No fuss, no half-measures. Brand new God-damned PIC kit 2. If this thing doesn't do the job, I'm going to go absolutely spare.

Finally, the final ultimate last piece of the Ocelot mainboard is installed: The dsPIC33FJ128GP802 is seated upon its throne, ready to command its assembled forces of Power, Interface, Audio and Video.

How does one program the Ocelot? The PICkit has a 5-pin connector that joins to five points on the board: it takes over the MCU's reset pin, requires two more pins for its debug data and clock, and wants to be connected to your board's power and ground pins. When it's installed, you can program the chip through the MPLAB X interface and do all the breakpointy debugging magic you want. If you're good enough at programming the UART, you can upload your image to the chip and then set the PIC kit to UART mode instead of debugging in order to receive a character/byte stream from the device. I haven't looked into that yet. I'd have thought that the debugging mode itself would have a character channel but it doesn't look like the case. You get debugging or UART but not both (unless you wire your dsPIC board to have UART and do it all externally, probably connecting a UART-serial interface to your PC through USB. OR you're bonkers enough to put a USB stack on your PIC, making it a bona-fide USB peripheral in its own right.)

Does it work? Of course it... uh... It works for about a minute and then goes into an upsetting infinite loop of resetting and blinking all its lights madly.

There's so many things that could be going wrong, I don't know where to begin. Foremost, it's either because I'm drawing too much current into the MCU and it's straining the regulator to its limit, or a board assembly problem. At 40 MIPS, the MCU draws 70mA typical and the regulator is limited to 100mA. Add on the LEDs (3/4mA each), peripherals (not the amp board: that's powered by unregulated power), subtract a few dozen percent for the stripboard and my lousy soldering, and it could easily be hitting the limit. Alternatively, my precious tantalum capacitor could be dead on arrival, dead by misinstallation, installed backwards, installed on the wrong pins, or any number of other problems.

I underclocked the chip in software (underclocked relative to the target MIPS I wanted anyway, the chip is designed for 6-40 MIPS operation) and it seemed a lot more stable. Stable as I could tell anyway. Hmm...

Image
While musing on that, I chopped up all my lousy joystick and amp board cables. My awesome gizmo is not going to be messed up by substandard cabling. I had it all nicely neatened up in a few hours. I soldered together the leads for the power and reset switches, the phono output sockets, and realised that I didn't even need to do anything to the LEDs... so the Ocelot is actually complete!

What does the Ocelot look like when it's fully assembled?
Image
Like a mazing, of course.

Image
I hadn't really put too much thought into what shape the final system would be if I were to make a brand new box for it, but by the way the boards lie together, it seems pretty obvious that it should be roughly the size of a large book: deeper than it is wide, and very flat.

To fix the reset problem, I decided to do the most straightforward thing I could. Assuming that the current draw into the MCU is not constant (it'll vary with the clock and logic and all that), the lurches of current into the MCU are going to be the main thing that makes the power rails drop down to the point where it brown-out-resets. I'm going to stick the juiciest capacitor I can right across the power rails right next to the chip and see if that makes everything a lot more stable. The original drawing of the Ocelot had one there anyway, but I figured that the Big Juicy Cap that's already next to the regulator in the top left would be sufficient. It wasn't.

One 220uF electrolytic later, and lets see if the Ocelot works. You know what? You bet your ass it does! It now detects my joystick just fine and blinks with the correct frequency. Next up, let's see if my newly assembled audio resistor network works.

If you check back a few pages, you'll recall that my plan was to simply toggle the outputs of four GPIO pins with the correct frequency in order to output square waves. In code, I'm dedicating one hardware timer each to a GPIO pin, and when the timer expires it toggles its GPIO pin. I've written an abstraction that lets me handle the pins in software as if they have an on-off flag and a period in clock cycles*: a really basic 4-channel square wave PSG interface. (*two periods really. I can alter the duty cycle of the square wave to change its character without changing its pitch. When the interrupt triggers, it switches to the alternate period.)

To test it, all I need to do is enable the interrupts for each channel and put in some period numbers. Will it blend?

https://www.youtube.com/watch?v=P2Dt4V1VTO8

Clear as a bell, loud as hell. The Ocelot sings!

I had a bit of a scare with the reset switch, it didn't have any effect at all when pushed. I spent a while rummaging through the diagrams trying to find a logical mistake, when I decided to inspect the system itself and found that I'd just missed slightly when putting the jumper lead on, so it was just lying disconnected but snug between two components rather than securely installed on its pin. That was a nice piece of luck. :)
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

I put a meter on the Vdd and Vss rails and it looks like the weak-ass voltage regulator simply can't hack jack when you ask it to give anywhere near 70mA (3.3v unloaded going down to 2.6v when the PIC's active). Couple that with a horrible cheap 9v battery and you've got a recipe for a weak supply. That's why it was popping on and off.

Doesn't solve the problem I'm having with the slew rates on these DACs though...
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

I love it when a plan comes together.

https://www.youtube.com/watch?v=T5NInrLf0WE

https://www.youtube.com/watch?v=Yauc9QBC4fM

Near the end of the second video, you can hear the Ocelot start to go into it reset fit. It's running off the 9v zinc carbon battery, which droops down to THREE FREAKIN' VOLTS when the PIC is on. Yeah.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Another problem squished: I was following inaccurate advice when setting up the initial environment of the PIC so I was seeing clock output on a pin I was using for joystick input, instead of the internal pull-up I was expecting.

Now I have up, down, left, right and fire! Yay! Not having a full logic high 7 megahertz signal shooting out of its backside is probably going to be a good thing for its power usage too.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Added the 8000kHz 3-bit PCM player* so it can now announce "OCELOT" when you turn it on. (Or if you're feeling nostalgic "GHOSTBUSTERS WHAHAHAHAHAHAH".)

*well it was already there, but now I have a program to convert waves to 3-bit format. I had a look at the range of output levels the resistor network was capable of producing and reasoned that the extra resolution was in all the wrong places to get a better sound out of the system. 3-bit is smaller, so that was that.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

You doing the full noise shaping thing on the device, or what?
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

I'm afraid I don't know what you mean by 'noise shaping'.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Kamineko wrote:I'm afraid I don't know what you mean by 'noise shaping'.
Trying to find time to write a blog post about it, actually.

Cheap solution. if you have a 16-bit sample and only a 3-bit output:
1. Take the next sample.
2. Add to it the value carried forward from the previous iteration of step 7 (or zero if this is your first iteration).
3. Remember this value.
4. Compute a random value between 0 and 0x1FFF and add it to your sample.
5. Compute another random value between 0 and 0x1FFF and subtract it from your sample.
6. and the result with 0xE000 -- this is your output value.
7. subtract the output value from the value saved at step 3 -- use the result in the next step 2.
8. Go to step 1

Dithered and shaped.

You probably need to think about clipping and biasing, but whatever.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Wait, sorry. I just noticed that's either a fairly low or extremely high sample rate. Basic noise shaping like that pushes all the noise towards the nyquist frequency, which at 8kHz is pretty much right on human peak sensitivity.

If you meant 8kHz then do not noise-shape; just add and subtract the random values and forget about the error.

If you meant 8MHz then there's no problem.
User avatar
venusian
Baaaaaaa!
Baaaaaaa!
Posts: 6653
Joined: Wed Nov 06, 2002 2:22 pm 0
Location: South Gloucestershire

Re: Asteroids on Oscilloscope

Post by venusian »

That's alot like doing pulse width modulation at each of the 8 "real" output levels isn't it? But with a randomly driven stochastic duty cycle thing going on.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

venusian wrote:That's alot like doing pulse width modulation at each of the 8 "real" output levels isn't it? But with a randomly driven stochastic duty cycle thing going on.
I have a lot of trouble visualising it that way. I think it's not strictly the same thing, but if the dither were a true gaussian distribution then it might be. The random duty cycle takes away a lot of the low-frequency noise.

I guess if I try to visualise it as an ordered sawtooth dither rather than random dither it'd look a lot more like PWM; but still only at the LSB.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

gumboot wrote:Wait, sorry. I just noticed that's either a fairly low or extremely high sample rate. Basic noise shaping like that pushes all the noise towards the nyquist frequency, which at 8kHz is pretty much right on human peak sensitivity.

If you meant 8kHz then do not noise-shape; just add and subtract the random values and forget about the error.

If you meant 8MHz then there's no problem.
Definitely kHz; I'm pushing uncompressed values from an array of (triples of) bits onto the four GPIO pins to use them as a DAC.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Kamineko wrote:Definitely kHz; I'm pushing uncompressed values from an array of (triples of) bits onto the four GPIO pins to use them as a DAC.
Ok, well a quick test shows that you can economically take about 5dB off of the most critical band with noise shaping, but that doesn't really seem worth the hassle.

You got a link to the audio samples you're working with? I might have a wee play around to see if they can't be pre-cooked for optimum 8kHz 3-bit fidelity.
Post Reply