How to flash ATmega8, ATmega48, ATmega88, ATmega168 or ATmega328 - Kyuchumimo/Micro-Joy-Home-Video-Computer GitHub Wiki

This part is a microcontroller, but can be reprogrammed to function as a sound chip thanks to the AVR-AY project.

AVR-AY has 4 diferent versions and 3 configuration files.

Firmware:

  • 2 channel with AY-3-8910 volume table
  • 2 channel with YM2149F volume table
  • 3 channel with AY-3-8910 volume table
  • 3 channel with YM2149F volume table

Configuration files:

  • standard -> parallel + serial
  • parallel -> for using in real hardware (e.g. ZX-Spectrum)
  • serial -> UART RX pin @ 57600 baud rate

The latest version of AVR-AY supports the following crystal clock frequencies:

  • 20 MHz (recommended)
  • 24 MHz
  • 25 MHz
  • 27 MHz
  • 28 MHz
  • 28.332 MHz
  • 30 MHz
  • 32 MHz
  • 40 MHz

Note: The latest version does not work on stock Arduino UNO or Arduino Nano development boards due to clock requirements. However, there are older versions that do support 8 Mhz internal RC or 16 MHz XTAL. If you wish to go this route, consider that the sound experience and mode of operation may not be optimal.

To flash the microcontroller, you need to have a USBasp USB programmer for Atmel AVR controllers.

In order for the PC to recognize your USBasp, a driver installation is required.
Go to https://zadig.akeo.ie/ and download the latest version of Zadig. Zadig does not require installation to run.

zadig

I recommend that you install libusbK (v3.1.0.0) as driver for your USBasp. If it does not work, try another driver.

There are a multitude of programs for flashing this series of microcontrollers. Some of the most popular options are listed below:

For this example we will use Khazama AVR Programmer.

2

The connections to flash the ATmega8, ATmega48, ATmega88, ATmega168 or ATmega328 microcontroller are as follows:

microcontrollers_atmegaxx8_ISP_637w

Note: To use the ATmega8, ATmega48, ATmega88, ATmega168 or ATmega328 TQFP32 microcontroller on a breadboard requires a TQFP32 to DIP28 adapter.

Note: If you rescue a microcontroller from a circuit board, do not forget to place the crystal on terminals XTAL1 and XTAL2 before programming.
By default from factory the ATmega8, ATmega48, ATmega88, ATmega168 and ATmega328 are shipped with internal RC oscillator at 8.0MHz and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock. You will need to change the fuse configuration so that the microcontroller can support an external crystal oscilator. See the data sheet for more information. These fuses can also be changed with Khazama AVR Programmer

  1. In the Khazama AVR Programmer software select your device.

Note: To check that your microcontroller is alive and responding to communications, go to Command > Read Chip Signature, if all goes well, you should get a window showing your microcontroller Chip Signature. If there is a Chip Signature mismatch, check that you have selected the correct microcontroller model and that the circuit connections are well done.

  1. Make sure the microcontroller is clean by going to Command > Erase Chip.

  2. Go to File > Load FLASH file to Buffer and load the .hex file containing AVR-AY firmware.
    This .hex file has the following format:

AY_Emul_XXX_Nch_KK_MM.hex  
	XXX - version number
	N - number of channels 2 or 3
	KK - MCU type (m8 - Atmega8, m48 - Atmega48, etc...)
	MM - volume table type ay or ym
Examples:
AY_Emul_XXX_2ch_m8_ay.hex 	- firmware HEX file to flash (2 channel version with AY volume table for Atmega8)
AY_Emul_XXX_3ch_m328_ym.hex 	- firmware HEX file to flash (3 channel version with YM volume table for Atmega328)
  1. Go to File > Load EEPROM file to Buffer and load the .hex file containing AVR-AY configuration.
    This .hex file has the following format:
Conf_XXX_YYMHz_ZZMhz.hex	- configuration file for emulator to write to EEPROM
	where XXX - standard, parallel or serial
		standard - use both types of connection parallel and serial
		parallel - use only parallel mode connection for using in real hardware (e.g. ZX-Spectrum)
		serial - use only serial mode connection (use RX pin on atmega8 with USB->TTL converter and AYPlayer or other software)
	YY - Atmega oscillator frequency
	ZZ - AY/YM chip oscillator frequency emulation 1_75 = 1.75MHz, 2 - 2MHz

I recommend that you use the 1.75 MHz version for AY-3-8910/YM2149F clock. This is the clock frequency used by the ZX spectrum, 2 MHz is the frequency used by the Atari ST. Also use the serial version to reduce the pin count to just one via UART.

  1. Click on Auto Program and you are done.