Arduino on atmega16 TQFP package

I’ve been playing around with uploading arduino sketches to an atmega16 microcontroller with some success. I followed the instructions here - http://www.subtours.com/ralph/theory/atmega16witharduino.html and changed the preferences.txt file to:

build.mcu=atmega16

to compile for atmega16 and

build.f_cpu=12000000L

for the 12mhz crystal I’m using. I also edited pins_arduino.c and pins_atmega8.c as outlined on the site.
I uploaded the sketch using avrdude and the BSD parallel port programmer. So far so good for the PDIP package :slight_smile:

However, I’m having trouble with using the TQFP package. It has more pins and they are in a different order to the PDIP package so I re-edited pins_atmega8.c to this:

/*
  pin_atmega8.c - pin definitions for the atmega8
  Part of Arduino / Wiring Lite

  Copyright (c) 2005 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: pins_atmega8.c 85 2006-01-12 23:24:12Z mellis $
*/

#include <avr/io.h>
#include "wiring.h"

// We map the pin numbers passed to digitalRead() or
// analogRead() directly to the corresponding pin 
// numbers on the Atmega8.  No distinction is made
// between analog and digital pins.

// ATMEL ATMEGA8
//
//       +-\/-+
// PC6  1|    |28  PC5
// PD0  2|    |27  PC4      
// PD1  3|    |26  PC3
// PD2  4|    |25  PC2
// PD3  5|    |24  PC1
// PD4  6|    |23  PC0
// VCC  7|    |22  GND
// GND  8|    |21  AREF
// PB6  9|    |20  AVCC
// PB7 10|    |19  PB5
// PD5 11|    |18  PB4
// PD6 12|    |17  PB3
// PD7 13|    |16  PB2
// PB0 14|    |15  PB1
//       +----+

#define NUM_PINS 44
#define NUM_PORTS 5

#define PA 1
#define PB 2
#define PC 3
#define PD 4

int port_to_mode[NUM_PORTS + 1] = {
      NOT_A_PORT,
      _SFR_IO_ADDR(DDRA),
      _SFR_IO_ADDR(DDRB),
      _SFR_IO_ADDR(DDRC),
      _SFR_IO_ADDR(DDRD),
};

int port_to_output[NUM_PORTS + 1] = {
      NOT_A_PORT,
      _SFR_IO_ADDR(PORTA),
      _SFR_IO_ADDR(PORTB),
      _SFR_IO_ADDR(PORTC),
      _SFR_IO_ADDR(PORTD),
};

int port_to_input[NUM_PORTS + 1] = {
      NOT_A_PORT,
      _SFR_IO_ADDR(PINA),
      _SFR_IO_ADDR(PINB),
      _SFR_IO_ADDR(PINC),
      _SFR_IO_ADDR(PIND),
};

pin_t digital_pin_to_port_array[] = {
      { NOT_A_PIN, NOT_A_PIN },
      
      { PB, 5 },
      { PB, 6 },
      { PB, 7 },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { PD, 0 },
      { PD, 1 },
      { PD, 2 },
      { PD, 3 },
      { PD, 4 },
      { PD, 5 },
      { PD, 6 },
      { PD, 7 },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { PC, 0 },
      { PC, 1 },
      { PC, 2 },
      { PC, 3 },
      { PC, 4 },
      { PC, 5 },
      { PC, 6 },
      { PC, 7 },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { PA, 7 },
      { PA, 6 },
      { PA, 5 },
      { PA, 4 },
      { PA, 3 },
      { PA, 2 },
      { PA, 1 },
      { PA, 0 },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { PB, 0 },
      { PB, 1 },
      { PB, 2 },
      { PB, 3 },
      { PB, 4 },
};

pin_t *digital_pin_to_port = digital_pin_to_port_array;
pin_t *analog_in_pin_to_port = digital_pin_to_port_array;
pin_t *analog_out_pin_to_port = digital_pin_to_port_array;

The hex file uploads ok, but the crystal doesn’t seem to be oscillating, and there is no signal on the output pin!

Any suggestions?!

Are you sure you set the fuses correctly (external crystal)?

How do you know the crystal isn't oscillating?

Do you have decoupling capacitors at all power pins?

Yep that's it! Thanks.

I knew the crystal wasn't oscillating from monitoring XTAL1 and XTAL2 with the oscilloscope. Setting the fuses sorted that.

I now have PWM out - now to check the ADC!