Start debugging & break does not break

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using the latest Atmel Studio release, starting a debug session for Atmega168 device. It will not break on start.

Possible reasons?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post a small, complete example program that demos the problem, please!

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may want to show the code you are building (or at least a minimal example that demonstrates the problem).

 

Edit: Mid-America Jim beat me to the Post button.smiley

David (aka frog_jr)

Last Edited: Mon. Oct 2, 2017 - 07:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
// This version for ATMEGA168

#define F_CPU    16000000UL
#define SAMPLE_RATE 20000UL

#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/power.h>

// Drum triggers
#define DRUM_TRIGGER_DDR  DDRD
#define DRUM_TRIGGER_PORT PORTD
#define DRUM_TRIGGER_PIN  PIND
#define DRUM_TRIGGER_0    0
#define DRUM_TRIGGER_1    1
#define DRUM_TRIGGER_2    2
#define DRUM_TRIGGER_3    3
#define DRUM_TRIGGER_4    4
#define DRUM_TRIGGER_5    5
#define DRUM_TRIGGER_6    6 // SEE port init function
#define DRUM_TRIGGER_7    7

// Ring Buffer
uint8_t Ringbuffer[256];
uint8_t RingWrite=0;
volatile uint8_t RingRead=0;
volatile uint8_t RingCount=0;

uint16_t samplecnt1,samplecnt2,samplecnt3,samplecnt4,samplecnt5,samplecnt6,samplecnt7,samplecnt8;
uint16_t samplepnt1,samplepnt2,samplepnt3,samplepnt4,samplepnt5,samplepnt6,samplepnt7,samplepnt8;
uint8_t dread1,dread2,dread3,dread4,dread5,dread6,dread7,dread8;
uint8_t odread1,odread2,odread3,odread4,odread5,odread6,odread7,odread8;

uint8_t Accent;
uint8_t MUX;
int16_t total;

const uint8_t drum1[] PROGMEM =
{
	133,138,128,119,120,125,128,126,125,121,116,124,123,115,117,126,131,131,127,125,127,131,136,127,118,122,131,135,133,130,126,124,131,133,121,115,123,128,127,126,124,122,121,126,123,110,108,120,125,123,125,126,126,129,133,125,117,126,137,138,134,134,132,133,138,137,125,118,131,138,130,125,124,121,124,128,122,112,112,126,130,121,120,118,117,126,126,119,115,122,138,137,128,126,122,125,137,136,131,126,
	132,142,138,132,129,123,126,130,123,120,116,122,129,126,125,126,121,125,127,121,126,132,139,140,133,131,131,129,132,130,124,129,137,141,136,131,131,130,129,132,124,121,130,138,140,134,130,130,126,131,133,123,124,133,140,141,134,134,135,135,140,134,124,125,131,136,133,125,124,123,122,122,112,106,111,122,131,133,133,133,132,130,127,118,117,123,132,137,137,135,132,132,131,127,119,118,122,127,126,128,
	126,123,127,128,122,114,114,118,120,118,123,125,123,127,128,122,120,124,131,133,131,135,133,131,136,135,129,127,129,134,134,129,129,122,119,124,122,117,118,120,128,129,125,123,114,114,122,122,122,120,121,127,132,135,132,122,122,127,127,131,132,133,136,135,134,128,120,124,126,124,125,124,125,125,125,124,118,115,122,122,121,126,128,136,140,142,139,127,124,132,128,128,130,131,134,134,136,132,122,124,

};

const uint8_t drum2[] PROGMEM =
{
	128,164,168,168,163,142,145,75,24,39,25,39,51,76,78,90,103,129,149,163,194,207,213,177,181,178,194,185,231,220,227,225,210,161,150,151,133,119,110,87,75,62,49,22,20,10,35,18,16,21,19,21,31,60,66,73,87,108,117,134,155,169,234,237,255,242,238,243,240,231,222,175,182,163,147,122,104,96,87,78,58,37,13,26,20,27,18,25,18,31,44,88,111,109,114,152,
};

const uint8_t drum3[] PROGMEM =
{
	128,187,132,118,145,112,103,172,95,106,37,137,114,109,133,148,103,148,107,135,58,154,114,117,92,174,181,119,152,175,122,130,146,108,96,121,110,107,66,74,111,61,110,105,134,85,121,141,125,136,203,130,141,124,159,165,171,149,110,153,99,108,104,184,115,28,87,94,27,43,115,130,148,94,137,148,97,134,150,127,83,180,107,200,115,112,87,159,97,144,44,148,84,128,70,136,
};

const uint8_t drum4[] PROGMEM =
{
	128,142,62,59,95,60,79,91,166,123,135,161,238,246,165,189,136,154,183,89,63,96,94,45,83,59,59,78,74,84,99,95,111,108,139,130,130,176,182,186,218,222,249,158,162,214,237,214,223,201,174,178,106,156,131,108,84,119,30,21,38,17,40,44,98,40,49,57,71,86,93,110,103,145,157,162,143,176,161,182,200,214,198,206,178,159,169,145,135,116,129,88,101,81,54,15,
	26,18,10,29,41,30,47,62,64,87,88,94,105,120,122,162,162,243,186,195,190,209,196,191,172,173,165,159,146,130,111,88,96,122,76,34,39,49,26,28,31,36,44,58,66,83,94,101,125,135,130,161,183,186,190,192,219,197,190,185,189,185,177,166,160,145,141,108,107,95,73,59,23,42,50,38,41,42,56,65,71,87,102,101,118,136,146,142,166,177,188,220,242,212,232,233,194,187,184,176,
	169,156,147,138,120,111,58,68,59,46,37,31,42,38,49,53,64,71,83,96,97,114,130,136,143,159,166,181,182,198,221,218,228,215,190,186,179,173,159,150,141,124,108,92,90,65,54,48,46,39,41,43,52,59,68,73,85,94,108,112,125,134,144,148,163,183,184,183,189,214,194,200,199,186,178,172,161,153,139,124,123,104,76,76,67,47,44,45,45,44,50,59,64,74,82,90,100,106,117,130,
	143,148,157,168,184,186,183,187,209,191,188,184,183,173,168,156,144,133,122,113,87,71,74,66,59,50,53,52,55,58,67,72,83,90,98,110,116,122,133,148,149,166,171,165,181,182,183,196,190,186,185,184,179,171,158,143,141,124,110,100,91,79,72,77,67,59,59,57,62,68,73,83,88,100,105,114,124,131,136,143,151,162,171,178,181,186,189,197,188,184,187,182,173,163,155,150,140,126,111,106,
	93,89,75,71,64,65,63,66,66,73,80,83,93,103,112,118,123,130,142,147,155,160,168,178,184,181,194,190,192,182,182,178,174,165,160,148,144,129,115,105,102,94,88,76,81,71,67,68,70,71,78,84,92,100,108,116,124,135,138,145,155,161,165,168,176,176,187,188,185,185,179,180,178,170,160,155,147,137,132,119,108,100,95,85,75,75,71,79,72,73,77,84,91,96,104,112,116,124,132,140,
	147,152,156,161,172,170,175,178,179,181,181,181,179,175,170,158,156,149,143,134,123,113,104,100,93,81,85,78,76,77,78,80,86,89,95,100,108,116,125,128,138,143,145,152,154,160,166,171,172,176,180,174,176,176,170,168,165,156,153,144,138,130,123,113,111,101,96,90,87,88,83,82,83,83,85,90,98,104,110,116,122,127,134,140,146,148,153,162,164,165,171,168,171,173,172,171,170,169,165,161,
	152,147,137,136,128,119,111,103,101,96,91,88,86,86,86,85,88,91,97,102,107,113,119,123,130,136,140,148,152,155,157,161,166,167,168,168,168,169,167,163,164,160,157,151,144,139,133,126,122,116,104,100,101,92,93,89,88,87,84,88,92,97,103,108,112,117,122,132,134,136,144,148,153,155,159,160,162,166,166,165,164,164,163,160,158,153,150,145,139,134,127,122,118,114,107,108,104,97,98,96,
	95,97,96,98,102,104,109,112,118,120,125,129,135,139,142,144,147,151,152,153,152,156,158,157,158,156,154,152,152,149,145,140,136,134,130,124,121,118,112,109,105,104,105,105,102,103,104,104,107,108,111,114,119,123,125,129,134,136,139,141,142,144,145,148,149,148,148,149,148,147,147,148,146,144,142,140,137,133,130,128,124,122,119,116,112,111,111,110,110,109,109,109,112,113,114,117,120,123,125,127,
	129,131,134,134,139,139,140,141,142,143,143,144,143,142,142,142,141,141,140,139,136,134,132,129,127,125,122,120,118,118,116,116,116,116,117,116,116,116,117,118,120,122,124,125,126,128,130,131,133,134,136,136,136,138,137,138,137,138,138,137,137,137,136,136,135,134,132,131,130,128,126,126,125,124,123,122,121,122,120,121,121,121,121,122,122,123,124,125,126,127,128,129,129,130,131,131,131,132,132,132,
	133,133,133,133,133,133,132,132,132,132,131,131,130,129,129,128,128,127,126,126,126,126,125,125,125,125,125,125,125,125,125,126,126,127,127,127,128,128,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
};

const uint8_t drum5[] PROGMEM =
{
	128,122,164,121,123,49,34,101,250,246,152,60,49,111,58,167,243,126,103,68,138,107,113,121,135,96,147,138,114,110,115,90,125,85,53,91,165,246,143,91,89,70,97,54,129,241,102,103,167,113,90,131,147,149,117,81,111,112,35,94,196,103,158,168,112,44,120,56,138,226,108,107,61,99,147,82,54,129,13,101,250,184,82,140,81,179,56,81,80,147,198,98,141,18,46,56,
	189,254,168,36,66,79,53,144,253,192,89,10,140,167,53,77,163,202,164,73,29,98,165,119,18,91,84,89,98,209,192,61,73,25,142,237,166,219,135,97,74,22,152,180,84,79,18,108,145,178,100,41,146,158,198,133,92,93,131,73,58,131,142,158,70,82,91,188,156,136,81,54,175,172,64,165,89,15,71,219,174,86,127,159,67,84,121,151,250,145,96,44,75,132,128,74,133,184,107,138,
	209,148,138,62,135,120,24,69,192,204,112,29,122,86,128,134,172,133,145,122,85,108,151,111,72,82,88,200,163,106,52,120,196,196,130,46,103,187,156,56,110,116,180,116,99,118,142,140,110,102,162,175,128,62,104,183,143,61,154,175,142,51,160,151,123,71,118,126,176,110,144,170,153,149,127,49,53,165,172,102,158,159,118,115,98,140,88,94,124,143,109,231,146,52,104,157,172,153,100,89,
	127,143,147,110,153,130,87,127,107,139,182,117,126,118,126,122,114,132,128,121,131,147,121,123,115,170,121,78,130,117,122,128,158,132,113,142,135,154,122,101,102,120,101,99,154,178,147,108,125,125,142,140,109,122,137,137,132,93,117,163,135,124,93,126,145,162,106,123,100,146,138,123,134,155,133,130,115,139,135,130,98,138,152,102,120,129,126,153,127,120,125,136,133,136,138,147,132,138,134,124,
	100,123,135,137,125,137,146,149,138,122,115,116,125,136,136,147,121,126,136,143,144,131,110,132,120,130,142,170,127,112,114,120,136,143,136,140,136,110,121,152,141,149,115,115,129,137,144,156,124,113,132,134,146,127,124,131,127,136,135,133,137,123,123,146,144,142,129,117,127,119,138,150,129,124,131,126,129,150,129,128,121,116,127,146,145,132,129,134,149,136,130,123,130,132,121,126,142,137,130,128,
	133,140,127,124,126,125,136,136,124,123,139,138,137,129,139,131,112,124,138,132,129,125,137,139,125,125,135,122,126,135,135,132,132,132,128,134,133,126,127,129,127,129,131,132,122,126,133,133,125,124,135,136,133,129,126,131,130,130,130,128,129,130,130,130,128,128,131,130,129,129,128,128,127,128,129,131,130,128,129,128,130,129,129,130,129,129,127,129,129,128,127,128,128,129,128,128,129,129,129,129,
	129,128,128,128,128,129,128,128,128,128,128,128,128,128
};

const uint8_t drum6[] PROGMEM =
{
	128,149,117,85,141,185,112,43,133,218,116,10,125,251,128,2,109,237,143,15,101,223,148,25,94,211,163,31,88,205,164,53,74,198,177,55,71,183,183,74,62,167,191,93,48,164,193,94,63,145,195,113,53,137,199,117,59,126,188,139,59,106,196,148,63,97,186,166,75,75,180,184,83,62,163,193,96,55,156,192,103,67,138,191,119,66,133,188,123,68,124,185,131,71,118,181,
	142,72,111,180,142,80,110,170,145,88,107,163,149,95,103,155,154,98,102,153,150,106,106,144,145,113,112,135,145,118,111,137,143,120,114,134,139,122,115,132,140,124,116,129,138,127,118,129,136,127,121,125,135,131,121,126,133,130,124,126,132,129,127,128,130,129
};

const uint8_t drum7[] PROGMEM =
{
	128,129,112,108,86,114,157,124,159,206,159,121,96,93,46,41,167,172,164,178,227,178,165,116,38,8,79,124,133,148,186,255,230,163,96,39,8,18,59,85,125,241,248,243,201,128,83,4,6,38,52,92,172,243,247,229,165,76,13,8,7,29,66,142,238,247,242,194,123,48,6,11,9,33,103,164,247,244,238,160,92,49,13,9,17,58,134,216,246,241,194,139,73,35,12,12,
	29,91,163,242,237,227,162,122,79,16,13,17,67,126,175,230,236,183,157,104,72,21,19,41,95,148,178,219,212,169,150,108,52,34,40,80,110,146,172,182,185,166,127,97,60,52,71,93,127,140,166,174,176,153,117,87,76,75,90,99,125,142,159,175,154,139,114,97,88,92,96,107,118,145,156,160,148,127,118,110,104,94,97,108,126,143,153,144,143,131,126,116,104,102,98,114,129,136,143,141,
	137,140,129,120,103,103,107,116,127,129,136,142,143,140,130,118,109,105,115,116,123,128,134,144,146,139,127,116,115,113,112,116,117,130,138,145,142,135,128,120,117,115,111,114,121,131,143,142,141,130,129,125,118,113,110,116,127,134,140,140,137,136,128,125,114,112,112,120,129,136,138,139,137,136,130,120,115,111,118,123,131,134,137,140,140,134,128,117,115,116,119,126,128,136,137,141,139,131,124,118,
	116,120,121,126,129,135,141,139,137,128,123,121,121,121,123,125,132,135,138,136,131,128,125,124,122,123,123,127,132,135,134,134,129,129,127,125,124,123,126,129,131,132,132,131,130,128,128,125,125,125,127,129,130,130,130,130,130,128,127,126,126,127,128,129,129,129,130,130,129,128,127,127,127,128,128,128,129,129,129,129,129,128,128,128,128,128,128,128,128,129,128,128,128,128,128,128,128,128
};

const uint8_t drum8[] PROGMEM =
{
	128,128,129,129,129,128,128,128,129,128,128,128,128,127,128,127,130,129,129,130,128,128,128,127,129,129,129,123,130,127,127,126,131,128,127,128,130,125,129,127,125,131,124,126,126,128,124,124,128,125,129,133,130,121,130,122,135,126,120,127,123,117,137,129,119,138,122,125,135,129,142,113,140,121,112,148,107,142,135,108,151,105,137,124,114,141,142,114,130,138,113,126,127,150,118,127,
	110,143,115,137,124,130,122,126,121,120,124,123,120,129,117,127,133,138,130,130,104,133,135,119,148,129,119,142,126,126,128,143,117,132,119,128,138,128,122,134,126,138,142,124,156,106,112,150,132,118,189,101,118,127,106,150,117,118,131,113,140,128,131,115,103,171,103,146,116,148,104,111,124,163,75,127,144,148,124,118,101,170,124,143,133,133,129,128,125,143,152,116,98,153,140,100,115,111,160,93,
	111,157,157,138,168,97,158,113,116,157,143,184,99,132,183,70,155,133,118,111,109,100,88,111,134,125,163,79,134,112,60,174,128,123,144,116,166,114,147,132,31,144,57,120,166,121,114,127,77,171,118,48,191,62,147,143,159,105,134,132,208,84,90,221,88,157,156,67,99,179,83,177,139,150,107,103,181,78,122,162,106,214,135,122,88,123,179,79,143,178,55,169,115,132,159,66,133,224,88,175,
	95,162,124,57,177,120,125,151,140,70,224,95,246,98,60,130,110,88,150,102,118,69,134,118,108,152,106,70,91,144,106,213,138,88,89,150,170,179,85,144,96,90,106,124,177,84,168,110,145,148,69,183,75,126,137,127,113,90,78,174,73,92,193,87,131,161,97,146,158,124,139,157,86,158,120,93,80,105,104,152,81,177,41,164,178,143,91,128,143,111,56,126,137,106,114,123,132,143,107,152,
	129,159,137,88,79,114,177,61,168,116,128,76,123,149,171,83,160,160,115,140,101,113,144,154,147,134,97,135,120,134,113,121,112,181,77,159,124,155,73,168,155,137,112,135,95,152,158,100,143,132,123,128,150,117,116,127,141,102,113,158,121,121,145,104,100,112,138,123,133,132,120,125,126,127,118,121,119,135,93,129,120,128,133,127,118,127,128,131,131,133,116,127,140,120,130,122,132,122,128,128,
	128,127,123,130,125,124,122,136,121,130,130,127,120,123,133,126,122,125,132,123,130,125,129,123,133,125,126,127,130,125,127,129,127,127,124,126,126,129,125,127,121,135,128,123,130,123,128,126,125,125,128,121,130,123,123,126,125,128,123,126,124,127,122,129,123,125,129,125,126,124,129,126,128,126,130,123,128,127,127,128,127,129,127,127,128,127,126,130,125,128,127,129,125,128,126,127,128,129,127,127,
	129,125,129,128,128,126,127,127,127,127,127,126,128,126,125,127,125,128,126,125,127,128,125,126,127,127,125,127,126,126,127,126,126,127,127,126,126,126,127,127,127,127,127,127,126,128,128,126,128,128,127,127,127,129,127,127,128,127,128,128,127,128,128,127,128,129,127,127,128,127,127,128,127,128,127,128,128,126,127,127,127,127,127,127,126,127,127,127,128,127,127,127,127,128,127,128,127,127,127,127,
	127,128,128,127,127,127,127,128,127,128,128,128,128,127,128,128,127,128,128,127,127,128,128,127,128,127,128,128,128,128,127,128,128,128,127,127,128,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
};

void ADCInit(void);
void portInit(void);
void timer0Init(void);
void timer1Init(void);

int main(void)
{
	portInit();
	timer0Init();
	//timer1Init();
	//ADCInit();
	sei();
	
	//ADCSRA |= _BV(ADSC); // Start 1st conversation
	
	while(1)
	{
		if (RingCount<32)
		{
			total=0;
			
			if (samplecnt1)
			{
				total+=(pgm_read_byte_near(drum1 + samplepnt1++)-128);
				samplecnt1--;
			}
			if (samplecnt2)
			{
				total+=(pgm_read_byte_near(drum2 + samplepnt2++)-128);
				samplecnt2--;
			}
			if (samplecnt3)
			{
				total+=(pgm_read_byte_near(drum3 + samplepnt3++)-128);
				samplecnt3--;
			}
			if (samplecnt4)
			{
				total+=(pgm_read_byte_near(drum4 + samplepnt4++)-128);
				samplecnt4--;
			}
			if (samplecnt5)
			{
				total+=(pgm_read_byte_near(drum5 + samplepnt5++)-128);
				samplecnt5--;
			}
			if (samplecnt6)
			{
				total+=(pgm_read_byte_near(drum6 + samplepnt6++)-128);
				samplecnt6--;
			}
			if (samplecnt7)
			{
				total+=(pgm_read_byte_near(drum7 + samplepnt7++)-128);
				samplecnt7--;
			}
			if (samplecnt8)
			{
				total+=(pgm_read_byte_near(drum8 + samplepnt8++)-128);
				samplecnt8--;
			}
			
			total>>=1;
			total>>=Accent;
			total+=128;
			if(total>255)
				total=255;
			cli();
			Ringbuffer[RingWrite]=total;
			RingWrite++;
			RingCount++;
			sei();
		}

		dread1 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_0);
		dread2 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_1);
		dread3 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_2);
		dread4 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_3);
		dread5 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_4);
		dread6 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_5);
		//dread7 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_6); <-- adjusted for atmega168
		dread7 = PINC & _BV(DRUM_TRIGGER_6);
		dread8 = DRUM_TRIGGER_PIN & _BV(DRUM_TRIGGER_7);
		
		if (dread1!=odread1)
		{
			odread1=dread1;
			if (odread1)
			{
				samplepnt1=0;
				samplecnt1=sizeof(drum1);
			}
		}
		if (dread2!=odread2)
		{
			odread2=dread2;
			if (odread2)
			{
				samplepnt2=0;
				samplecnt2=sizeof(drum2);
			}
		}
		if (dread3!=odread3)
		{
			odread3=dread3;
			if (odread3)
			{
				samplepnt3=0;
				samplecnt3=sizeof(drum3);
			}
		}
		if (dread4!=odread4) 
		{
			odread4=dread4;
			if (odread4) 
			{
				samplepnt4=0;
				samplecnt4=sizeof(drum4);
			}
		}
		if (dread5!=odread5) 
		{
			odread5=dread5;
			if (odread5) 
			{
				samplepnt5=0;
				samplecnt5=sizeof(drum5);
			}
		}
		if (dread6!=odread6) 
		{
			odread6=dread6;
			if (odread6) 
			{
				samplepnt6=0;
				samplecnt6=sizeof(drum6);
			}
		}
		if (dread7!=odread7) 
		{
			odread7=dread7;
			if (odread7) 
			{
				samplepnt7=0;
				samplecnt7=sizeof(drum7);
			}
		}
		if (dread8!=odread8) 
		{
			odread8=dread8;
			if (odread8) 
			{
				samplepnt8=0;
				samplecnt8=sizeof(drum8);
			}
		}
		/*
		if (ADCSRA & (1<<ADIF))
		{			
			if ((ADMUX & 0x0F) == 0)
			{
				OCR1A = 800+((1023-(ADCL+(ADCH<<8)))<<2);
				ADMUX |= _BV(MUX0); // Change over to ADC1
			}
			else
			{
				Accent = 7-((ADCL+(ADCH<<8))>>7);
				ADMUX &= ~(1<<MUX0); // Clear MUX bits
			}
			
			//ADCSRA |= _BV(ADSC); // Start next conversation
		}
		*/
	}
}

void timer0Init(void)
{
	// Set up Timer/Counter0 for PWM output
	power_timer0_enable();
	OCR0A  = 128;                                // 125 KHz
	TCCR0A |= _BV(WGM01)|_BV(WGM00)|_BV(COM0A1); // Fast PWM, Set OC0A set on Compare
	TIMSK0 = 0;                                  // No interrupts
	TCCR0B |= _BV(CS00);                         // No pre-scaling
}

void timer1Init(void)
{
	TCCR1B |= _BV(WGM12);  // Set CTC mode
	TCCR1B |= _BV(CS10);   // No prescaler
	TIMSK1 |= _BV(OCIE1A); // Enable interrupt when TCNT1 == OCR1A
	OCR1A   = 800;
}

void portInit(void)
{
	DRUM_TRIGGER_PORT = 0xBF; // without pin 6
	PORTC |= _BV(PC2); // Trigger 6 pullup on
	DDRD |= _BV(PD6);  // OC0A output
}

void ADCInit(void)
{
	ADCSRA |= _BV(ADEN);
	ADMUX |= _BV(REFS0); // Vref = Avcc
	ADMUX &= ~((1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0)); // ADC0
	ADCSRA |= (1<<ADPS2)|(1<<ADPS1); // Clk = 125KHz
}
/*
ISR(TIMER1_COMPA_vect)
{
	if(RingCount)
	{
		OCR0A = Ringbuffer[RingRead++];          //Output LSB of 16-bit DAC
		RingCount--;
	}
}
*/

This was ported from an ATmega128A where it worked fine. In addition to the debug issue, I also see that timer0 is not running. If I insert a while(1) loop just after the init function it will work as should.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What tool are you using for the debug session?  Simulator?

 

Have you rebuilt using the new target device?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using Atmel ICE. Yes, the project was rebuild with target device set.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

slow_rider wrote:
TIMSK1 |= _BV(OCIE1A); // Enable interrupt when TCNT1 == OCR1A

 

Timer 1 interrupts have been enabled, but the ISR has been commented out, so does not exist!

 

Bad things happen when an interrupt fires and no ISR exists, results will depend on toolchain.

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But Jim,

void timer1Init(void) is commented out, so it is not called and the ISR is commented out as well. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It works for me:

...using more-or-less bog-standard options.

 

Your next question may be about not stopping at port_init().  Inlined, perhaps?  [edit:  Yes.]   In any case it is past your question, as it does break.  The build looked pretty clean.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. Oct 2, 2017 - 08:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

port_init() is not ordered to be inline, is that optimized like that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

slow_rider wrote:
port_init() is not ordered to be inline, is that optimized like that?

It probably depends on the optimization that >>you<< have chosen to apply, along with the inline settings in >>your<< project.

 

In this case, it eminently makes sense, as it comes out ahead in both size and space.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll post the settings I am using later today but I have tried changing optimization and did not see any effect. In addition I can not understand what would cause timer0 fast PWM to stop running.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the past, when we've seen this "failure to break" thing using debugWire it's turned out to be dodgy electrical connections.

 

Your link to _Reset is reasonably short and there is NO other electronics connected to that pin apart from the ICE?

 

Oh and the usual point about the chip being properly decoupled - you have plenty of 100n dotted around close to supply rails? (and maybe a big electrolytic across the PSU?)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My optimization settings:

-O3 & -g2

 

All options:

-x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include"  -O3 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega168 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega168" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" 

 

The board I'm using is called BTE13-010 

Schematic

 

Here is how the minimal setup I'm running looks like (47uF cap on the power, 100n cap between Atmel ICE VCC + GND.