SKPIC32 Video Game with Sound Generator Module

Works done? Proud of it? Show off here! Let's see what you've built can help inspire others.

SKPIC32 Video Game with Sound Generator Module

Postby Brian Griffin » Fri Aug 17, 2012 1:01 pm

Project Name: SKPIC32 Video Game with Sound Generator Module.

Author/Designer: YH

Project Description: A primitive video game set using SKPIC32 as the graphics processor, and the PIC32MX120F032B as the sound generator module. This final module is the combination of two projects which is the SKPIC32-based 256-color Video Experimental Game and a modified code of the 6-voice Polyphony Music Box based on SKPIC32.

The sound generator module is powered by the PIC32MX120F032B and uses Phase Modulation Synthesis to produce different sounds. To imitate the obsolete General Instruments/Microchip (Microchip Inc. was that division from that one) AY-3-8910 sound chip, the generator uses a specific ratio inside to form square-waves. Noise generation uses a wavetable which contains random numbers only. Random number generation is simply made by Excel. Other ratios can be used to create other different sounds like bell and clang, but in this game, generic square waves are used to make it more retro-like.

Sound effects are pre-programmed into the sound generator module as there are complexities involved in transferring sound data from the main processor. Future improvements including SPI microcontroller-to-microcontroller communication.

Take note that the sound generator has two channel square waves and one noise channel. The noise generation is in the third channel.

The tune from the start is from Action 52's "They came.../Beeps and Blips" theme. Action 52 is a 52-game compilation for the Nintendo Entertainment system and was very notorious for the poor design and atrocious game programming.

Sound Generator Hardware: PIC32MX120F032B with 8MHz crystal, operating at 40MHz. The single-bit DAC (using PWM) is at 78.125KHz and capable of three sound channels and one noise channel.

Noise wavetable is using random numbers generated in Excel, from 0~255. A high frequency noise will sound like a sharp buzz, and a medium frequency noise will hiss or "ssssh", and a low frequency noise will result in a deep "boom" or a "burning sound'.

Compiler: MPLAB C32 v1.00, MPLAB X IDE v1.10

Schematics:
schematic2.jpg
Schematic of the Project


Video:

All the codes for the respective modules are attached inside.

Note: A CRT monitor is best for this project if you have it. The graphics slightly tear in the LCD one.
Attachments
skpic32-snd.X.zip
Sound Generator Module Code and Hex
(63.27 KiB) Downloaded 544 times
skpic32-vga2.X.zip
SKPIC32 Game Main Module Code and Hex
(204.56 KiB) Downloaded 550 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32 Video Game with Sound Generator Module

Postby ABSF » Sun Aug 19, 2012 12:28 am

Wow, really well done 8-) The sound really add more excitements to the game play.

You can further improve the display by adding bunkers above the shooter, so you can hide the playing from being hit by the missiles. You can also add extra space ships travelling occasionally across the sky and add bonus points when they get hit. Were there any scoring for the gameplay? I think that would add more fun and challenge too.

BTW, how much flash memories still left after all you did with the program? :roll:

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: SKPIC32 Video Game with Sound Generator Module

Postby Brian Griffin » Sun Aug 19, 2012 1:18 am

ABSF WROTE:Wow, really well done 8-) The sound really add more excitements to the game play.

You can further improve the display by adding bunkers above the shooter, so you can hide the playing from being hit by the missiles. You can also add extra space ships travelling occasionally across the sky and add bonus points when they get hit. Were there any scoring for the gameplay? I think that would add more fun and challenge too.

BTW, how much flash memories still left after all you did with the program? :roll:

Allen


Thanks for the compliment.

Indeed I wanted to add the bunkers and the mystery saucer, but I need time to squeeze the algorithm. It's not easy working something in a time constraint.

There are scoring for the gameplay.

I only used 10-15% of the flash as this PIC32 is so huge. ;)
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32 Video Game with Sound Generator Module

Postby takao21203 » Tue Aug 21, 2012 11:42 am

Do you have any controller interface? Such as USB for PS3 controller, or Nintendo N64?
I hope to get Nintendo Gamecube interface working very soon.
http://ycprojects.wordpress.com/2012/08 ... ontroller/

The timing is difficult to use with PICs actually. I am now using a 16F chip + some assembler code.
Once it works I want to try if the timing can be "stretched" a little.
And maybe changed to C completely.
Or maybe it will be neccessary to overclock the PIC :D

NES or SNES controller is more easy but they are so old fashion...

Or maybe work out USB host for X-BOX controller. It is too difficult for me, however.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32 Video Game with Sound Generator Module

Postby Brian Griffin » Tue Aug 21, 2012 11:58 am

takao21203 WROTE:Do you have any controller interface? Such as USB for PS3 controller, or Nintendo N64?
I hope to get Nintendo Gamecube interface working very soon.
http://ycprojects.wordpress.com/2012/08 ... ontroller/

The timing is difficult to use with PICs actually. I am now using a 16F chip + some assembler code.
Once it works I want to try if the timing can be "stretched" a little.
And maybe changed to C completely.
Or maybe it will be neccessary to overclock the PIC :D

NES or SNES controller is more easy but they are so old fashion...

Or maybe work out USB host for X-BOX controller. It is too difficult for me, however.


I'm planning to add interfaces later as this project is a proof of concept that driving video signals work in PIC32 (and also to do other things).

The NES or SNES controllers are easier to implement - I'd go and try that but I don't have these on my hands right now.

Have you planned to use AVRs or PIC24? The assembly might be much more easier to handle than the PIC16Fs. :)
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32 Video Game with Sound Generator Module

Postby takao21203 » Tue Aug 21, 2012 12:53 pm

Brian Griffin WROTE:...
Have you planned to use AVRs or PIC24? The assembly might be much more easier to handle than the PIC16Fs. :)


AVR no- too much effort to learn new instruction set + software IDE. But all projects I saw on the net actually use ATMEL chips + assembler for Nintendo Gamecube interface.

24F? I have one chip here (TFQP44). Never used! Is the assembler easier?

Basically the timing is critical, I need 1us LOW, 3 uS HIGH, or, 3uS LOW, 1uS HIGH. Both for sender and receiver code. I don't know how much and if it can be "stretched". So at first I wrote it now, as close as possible in terms of timing, using 16F assembler. Once it works, I will try to convert it to C as far as possible.

The C code I wrote on the 18F board did not work at all actually. I also think there is something wrong with the controller, so I have ordered 2 more. One arrived very fast from the UK, within 2 days.

NES controller contains 8-bit shifting register actually. SNES contains a 16bit shifting register.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32 Video Game with Sound Generator Module

Postby takao21203 » Tue Aug 21, 2012 1:17 pm

I have taken a look at the source code for the sound generator.

Do you think it is possible to run this on 18F PIC?
What pheripherals do you use exactly? 2 Timers? And PWM?
I would like to try to run this on 18F if I find the time.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32 Video Game with Sound Generator Module

Postby Brian Griffin » Tue Aug 21, 2012 6:15 pm

takao21203 WROTE:I have taken a look at the source code for the sound generator.

Do you think it is possible to run this on 18F PIC?
What pheripherals do you use exactly? 2 Timers? And PWM?
I would like to try to run this on 18F if I find the time.


You can run this on 18F PIC but you need to write these in assembler and the channels will be limited to one or two as it is a FM/PM synthesis generator.

I used one PWM and one timer for the sound generation. The other timer is for timing the duration of the sound (or note) itself.

If multipliers/dividers are difficult to handle, you can try using log tables. I haven't tried any of these yet.

Assembly on PIC24/30 is easier due to the memory being all linear and not banked unlike the PIC16F.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32 Video Game with Sound Generator Module

Postby takao21203 » Wed Aug 22, 2012 10:25 am

Yes I will take concrete action about this soon. But I need to make the Nintendo controller working first.

I don't fully understand how your program works, and will have to go through it a few times.
For instance, what is the serial interface used for? Could I remove it somehow for testing?

What is the sample rate? I mean how many Kbytes data are generated each second, or what is the required cycle time?
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32 Video Game with Sound Generator Module

Postby Brian Griffin » Wed Aug 22, 2012 10:54 am

takao21203 WROTE:Yes I will take concrete action about this soon. But I need to make the Nintendo controller working first.

I don't fully understand how your program works, and will have to go through it a few times.
For instance, what is the serial interface used for? Could I remove it somehow for testing?

What is the sample rate? I mean how many Kbytes data are generated each second, or what is the required cycle time?


The serial interface (UART) in the sound module is to receive sound commands from the main processor. Due to the complexities of the SPI master-slave communication between two processors, I simplify the design into having the sound processor preloaded with the effects instead. So, each time the main system sends like example, sound code '01', it'll sound up a "kaboom", sound code '02' is theme music, et cetera.

Apologies for not mentioning the sample rate. The sample rate is 78.125kHz. I do not know about the data generated, and the cycle time is always a problem to calculate in PIC32 systems due to the instruction cache. Like other processors with instruction cache, calculating the cycle times are often a futile task. The instruction cache can be an advantage, but is also a disadvantage at the same time.

The sound generation system is using Phase/Frequency (there is a slight difference on these, but I prefer saying 'phase' because of the nature of the DDS deals with it) Modulation Synthesis. The sine-waves are generated by DDS (digital direct synthesis), and one sine wave have to modulate the other sine wave, creating a new kind of sound. To learn how DDS work it's easier to read it on Elm-chan Wavetable Melody Generator.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Next

Return to Project Showcase

Who is online

Users browsing this forum: No registered users and 10 guests

cron