Forum: Mikrocontroller und Digitale Elektronik ATMega 16 tut nichts


von Berni (Gast)


Angehängte Dateien:

Lesenswert?

Hallo zusammen,

Ich bin gerade an meinem Schulprojekt und habe die Schaltung von einem 
led cube nachgebaut.

http://www.instructables.com/id/LED-Cube-4x4x4/step10/Program-the-microcontroller/

nun habe ich mit einem AVR Dragon die hex datei auf den Mega16 
geschrieben und das quarz fuse auf extmedxtalres_64kck_64ms gestellt.

nun habe ich einmal einen Layer an port A angeschlossen und an den GND 
Layer 0 Angeschlossen. Aber es tut sich nichts. Auch die 2 Leds, die 
leuchten sollten (für den bootvorgang) leuchten nicht.

anbei ein Foto von meinem Schaltplan (eventuell ist da ein Fehler)


Besten Dank

von gordon51freeman (Gast)


Lesenswert?

Naja, 14Mhz sind nicht gerade Medium Frequency.

von spess53 (Gast)


Lesenswert?

Hi

>anbei ein Foto von meinem Schaltplan (eventuell ist da ein Fehler)

Sind die beiden Kondensatoren am Quarz wirklich 100nF?

MfG Spess

von Lutz (Gast)


Lesenswert?

Ist wohl hoffentlich ein C&P-Fehler, denn am MAX232 haben die 100nF auch 
nix verloren.

von Berni (Gast)


Lesenswert?

Ja sind 100nF

der MAX ist im Moment nicht eingelötet

Besten Dank

von Karl H. (kbuchegg)


Lesenswert?

Berni schrieb:
> Ja sind 100nF

Am Quarz?
Zuviel! 22pF sind angemessen.

von Ingo (Gast)


Lesenswert?

Die Kondensatoren des 232 müssen an den Anschlüssen + und - nach GND und 
nicht gegen einandner geschaltet werden, sowie ich das noch im Kopf 
habe.

Der 7805 hat keine Abblockkondensatoren.

Welchen Zweck genau erfüllt X1 parallel zu dem Widerstand?



Ingo

von Berni (Gast)


Lesenswert?

okay werde das mal ändern.

aber daran wird es nicht gelegen sein, da auch mit internem quarz nichts 
gelaufen ist.

Vielen Dank

von Karl H. (kbuchegg)


Lesenswert?

Berni schrieb:
> okay werde das mal ändern.
>
> aber daran wird es nicht gelegen sein, da auch mit internem quarz nichts
> gelaufen ist.

Das wiederrum glaub ich sofort. Weil es nämlich keinen 'internenb Quarz' 
gibt.
Das was da intern die Taktversorgung machen kann ist ein RC-Schwingkreis 
und kein Quarz.

von Karl H. (kbuchegg)


Lesenswert?

Hat dein Brennprogramm irgendwas in Richtung 'Fehler' von sich gegeben?
Kannst du zb die µC-Kennung auslesen?
Wenn du dein Brennprogramm den µC auslesen lässt, klappt das?

(Die Frage ist: läuft der µC grundsätzlich? Wenn ja, dann wirst du halt 
einen Fehler im Programm haben oder in deiner LED-Beschaltung stimmt was 
nicht. Daher ist es immer ganz gut, wenn man für erste Tests den 
simpelst möglichen Test macht: Einfach eine LED an den Pin - anderes 
Ende an Masse (+Vorwiderstand) und nachsehen ob die LED leuchtet, wenn 
du den Pin auf 1 setzt. Gegentest: Die LED darf nicht leuchten, wenn du 
den Pin auf 0 setzt. Jede Hadrware-Komponente mehr ist eine zusätzliche 
Schicht, die selber wieder Fehler haben kann.

von Ingo (Gast)


Lesenswert?

Berni schrieb:
> aber daran wird es nicht gelegen sein, da auch mit internem quarz nichts
> gelaufen ist.

Dann zeig uns dochmal den Code.



Ingo

von Berni (Gast)


Lesenswert?

oh, da ist mir ein Fehler mit X1 unterlaufen er sollte eigentlich gegen 
GND gehen

von Berni (Gast)


Lesenswert?

Draw:
1
// ############################################
2
// 
3
// 4x4x4 LED Cube project
4
// By Christian Moen 2008
5
// chr@syntaks.org
6
// Lisence: GPL
7
//
8
// Low level graphic functions
9
//
10
// ############################################
11
12
void setvoxel(int x, int y, int z);
13
void clrvoxel(int x, int y, int z);
14
unsigned char getvoxel(int x, int y, int z);
15
unsigned char inrange(int x, int y, int z);
16
void flpvoxel(int x, int y, int z);
17
void altervoxel(int x, int y, int z, int state);
18
void setplane_z(int z);
19
void clrplane_z(int z);
20
void setplane_x(int x);
21
void clrplane_x(int x);
22
void setplane_y(int y);
23
void clrplane_y(int y);
24
void setplane(unsigned char plane, int i, int state);
25
void setline_z(int x, int y, int z1, int z2);
26
void setline_x(int z, int y, int x1, int x2);
27
void setline_y(int z, int x, int y1, int y2);
28
void clrline_z(int x, int y, int z1, int z2);
29
void clrline_x(int z, int y, int x1, int x2);
30
void clrline_y(int z, int x, int y1, int y2);
31
void drawline_plane(int x2, int y2, int x1, int y1,unsigned char anchor);
32
void fill (unsigned char pattern);
33
void tmp2cube(void);
34
void cube2tmp(void);
35
36
37
// Set a voxel in the cube buffer
38
void setvoxel(int x, int y, int z)
39
{ 
40
  if (inrange(x, y, z))
41
    cube[z][y] |= (1 << x);
42
}
43
44
// Clear a voxel in the cube buffer
45
void clrvoxel(int x, int y, int z)
46
{
47
  if (inrange(x, y, z))
48
  cube[z][y] &= ~(1 << x);
49
}
50
51
// Get the current status of a voxel
52
unsigned char getvoxel(int x, int y, int z)
53
{
54
  if (inrange(x, y, z))
55
  {
56
    if (cube[z][y] & (1 << x))
57
    {
58
      return 0x01;
59
    } else

effects
1
// ############################################
2
// 
3
// 4x4x4 LED Cube project
4
// By Christian Moen 2008
5
// chr@syntaks.org
6
// Lisence: GPL
7
//
8
// Graphic effects
9
//
10
// ############################################
11
12
void effect_spiral(int direction, int iterations, int delay);
13
void effect_spinning_plane(int direction, int iterations, int delay);
14
void effect_rain (int iterations, int delay, int hold, int speed);
15
void sendvoxel_z (unsigned char x, unsigned char y, unsigned char z, int delay);
16
void sendplane_rand_z (unsigned char z, int delay, int wait);
17
void blinky(void);
18
void flyplane (unsigned char plane,unsigned char direction, int delay);
19
void loadbar(int delay);
20
void random_1 (int iterations, int voxels, int delay);
21
void random_2 (void);
22
void random_filler (int iterations, int pixels, int delay, int state);
23
void random_filler2 (int delay, int state);
24
void planeflip (unsigned char axis1, int pos1, unsigned char axis2, int pos2, int delay);
25
void flip_playback (int delay, unsigned char flip_x, unsigned char flip_y, unsigned char flip_z);
26
void boingboing (uint16_t iterations, int delay, unsigned char mode, unsigned char drawmode);
27
28
// Shows an animation of a spinning spiral
29
void effect_spiral(int direction, int iterations, int delay)
30
{
31
  int i;
32
  int z;    // cube level
33
34
  for (i=0;i<iterations;i++)
35
  {
36
    // Loop cube levels
37
    for (z=0;z<4;z++)
38
    {
39
      // Read the animation from program memory and put it in the cube buffer.
40
      // y=0 and y=2 is stored in the upper nibble of the byte, and must be bitshifted into place.
41
      cube[z][0] = (pgm_read_byte(&spinning_line[(i+z)%6][0]) >> 4);
42
      cube[z][1] = pgm_read_byte(&spinning_line[(i+z)%6][0]);
43
      cube[z][2] = (pgm_read_byte(&spinning_line[(i+z)%6][1]) >> 4);
44
      cube[z][3] = pgm_read_byte(&spinning_line[(i+z)%6][1]);
45
      // the +z makes the animation iterate one step for each plane
46
      // making it into a spiral
47
    }
48
    delay_ms(delay);
49
  }
50
}
51
52
// Shows an animation of a spinning plane.
53
void effect_spinning_plane(int direction, int iterations, int delay)
54
{
55
  int i;
56
  int z;    // cube level
57
58
  for (i=0;i<iterations;i++)
59
  {
60
    // Loop cube levels.
61
    for (z=0;z<4;z++)
62
    {
63
      cube[z][0] = (pgm_read_byte(&spinning_line[(i)%6][0]) >> 4);
64
      cube[z][1] = pgm_read_byte(&spinning_line[(i)%6][0]);
65
      cube[z][2] = (pgm_read_byte(&spinning_line[(i)%6][1]) >> 4);
66
      cube[z][3] = pgm_read_byte(&spinning_line[(i)%6][1]);
67
    }
68
    delay_ms(delay);
69
  }
frames


1
// ############################################
2
// 
3
// 4x4x4 LED Cube project
4
// By Christian Moen 2008
5
// chr@syntaks.org
6
// Lisence: GPL
7
//
8
// ############################################
9
10
// 6 frame animation of line spinning around the center of the cube
11
// the animation is in 2 dimensions.
12
const unsigned char spinning_line[6][2] PROGMEM =
13
{
14
  { 0x84, 0x21 },
15
  { 0x0c, 0x30 },
16
  { 0x03, 0xc0 },
17
  { 0x12, 0x48 },
18
  { 0x22, 0x44 },
19
  { 0x44, 0x22 },
20
};

Main:
1
  // == flicker free :)
2
  OCR2 = 15;       // interrupt at counter = 15
3
  TCCR2 = 0x05;     // prescaler = 1024
4
  TCCR2 |= (1 << WGM01);  // Clear Timer on Compare Match (CTC) mode
5
6
7
  // Initiate RS232
8
  // USART Baud rate: 9600
9
  UBRRH = MYUBRR >> 8;
10
  UBRRL = MYUBRR;
11
  // UCSR0C - USART control register
12
  // bit 7-6      sync/ascyn 00 = async,  01 = sync
13
  // bit 5-4      parity 00 = disabled
14
  // bit 3        stop bits 0 = 1 bit  1 = 2 bits
15
  // bit 2-1      frame length 11 = 8
16
  // bit 0        clock polarity = 0
17
  UCSRC  = 0b10000110;
18
  // Enable RS232, tx and rx
19
  UCSRB = (1<<RXEN)|(1<<TXEN);
20
  UDR = 0x00; // send an empty byte to indicate powerup.
21
22
}
23
24
25
// Blink the status LEDs a little to indicate that the device has just booted.
26
// This is usefull to see if an error is making the device reboot when not supposed to.
27
// And it looks cool.
28
void bootmsg (void)
29
{
30
  int i;
31
  LED_PORT |= LED_GREEN;
32
  for (i = 0; i < 2; i++)
33
  {
34
    // Blinky
35
    delay_ms(1000);
36
    LED_PORT &= ~LED_GREEN;
37
    LED_PORT |= LED_RED;
38
    // Blink
39
    delay_ms(1000);
40
    LED_PORT &= ~LED_RED;
41
    LED_PORT |= LED_GREEN;
42
  }
43
  delay_ms(1000);
44
  LED_PORT &= ~LED_GREEN;
45
}
46
47
48
// Delay function used in graphical effects.
49
void delay_ms(uint16_t x)
50
{
51
  uint8_t y, z;
52
  for ( ; x > 0 ; x--){
53
    for ( y = 0 ; y < 90 ; y++){
54
      for ( z = 0 ; z < 6 ; z++){
55
        asm volatile ("nop");
56
      }
57
    }
58
  }
59
}

von Berni (Gast)


Lesenswert?

Brennprogramm läuft und spuckt keine Fehler aus

Werde das mit der led sofort testen

Danke

von Uwe (Gast)


Lesenswert?

LED_PORT wo ist der definiert ?
Bitte den Kompletten Code.

von Berni (Gast)


Lesenswert?

das ist der ganze code....

eine led bekomm ich nicht zum laufen

von Uwe (Gast)


Lesenswert?

Nö ist nicht der ganze Code ! Weil ich nirgends sehen kann was LED_PORT 
ist und wo er ist. Und ohne das LED_PORT irgendwo definiert ist würde 
das Programm gar nicht Compiliert werden können. Dann such mal in deinem 
Projektordner wo LED_PORT herkommt.

von Bastler (Gast)


Lesenswert?

Wo werden die Ports initialisiert?

Wo ist die while(1)?

Außerdem sind die Klammer glaub nicht immer richtig!?

Main: ???

von Berni (Gast)


Lesenswert?


von Berni (Gast)


Lesenswert?

[c]

// ############################################
//
// 4x4x4 LED Cube project
// By Christian Moen 2008
// chr@syntaks.org
// Lisence: GPL
//
// ############################################

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

// Define USART stuff
// CPU speed and baud rate:
#define FOSC 14745600
#define BAUD 9600
// Are used to calculate the correct USART timings
#define MYUBRR (((((FOSC * 10) / (16L * BAUD)) + 5) / 10) - 1)


// Define masks used for status LEDs and input buttons.
#define LED_GREEN 0x01
#define LED_RED 0x02
#define BUTTON 0x08
// Define port used for status and input.
#define LED_PORT PORTB
#define BUTTON_PORT PORTB


// Define masks for the layer select.
#define LAYER1 0x80
#define LAYER2 0x40
#define LAYER3 0x20
#define LAYER4 0x10
#define LAYERS 0xf0 // All layers
#define LAYERS_R 0x0f // The inverse of the above.
#define LAYER_PORT PORTD

// Define LED grid ports
// Each of the grid ports are connected to two rows of leds.
// The upper 4 bits is one row, the lower 4 bits are one row.
#define GRID1 PORTC
#define GRID2 PORTA


void ioinit (void); // initiate IO on the AVR
void bootmsg (void); // blink some leds to indicate boot or reboot
void delay_ms (uint16_t x); // delay function used throughout the 
program
void led_red(unsigned char state); // led on or off
void led_green(unsigned char state);
void launch_effect (int effect); // effect program launcher

// *** Cube buffer ***
// The 3D image displayed on the cube is buffered in a 2d array 'cube'.
// The 1st dimension in this array is the Z axis of the cube.
// The 2nd dimension of the array is the Y axis.
// Each byte is a stripe of leds running along the X axis at the given
// Z and Y coordinates.
// Only the 4 lower bits are used, since the cube is only 4x4x4.
// This buffer design was chosen to have code compatability with a 8x8x8 
cube.
// "volatile" makes the variables reachable from within the interrupt 
functions
volatile unsigned char cube[4][4];

// We sometimes want to draw into a temporary buffer so we can modify it
// before writing it to the cube buffer.
// e.g. invert, flip, reverse the cube..
volatile unsigned char tmpcube[4][4];

// What layer the interrupt routine is currently showing.
volatile unsigned char current_layer;

// Low level geometric functions
#include "draw.c"

// Static animation data
#include "frames.c"

// Fancy animations to run on the cube
#include "effect.c"


int main (void)
{
  // Initiate IO ports and peripheral devices.
  ioinit();

  // Indicate that the device has just booted.
  bootmsg();

  int x;
  int i;
  int z;

  // Set the layer to start drawing at
  current_layer = 0x00;

  // Enable interrupts to start drawing the cube buffer.
  // When interrupts are enabled, ISR(TIMER2_COMP_vect)
  // will run on timed intervalls.
  sei();

  // Main program loop.
  while (1)
  {
    for (i=0;i<13;i++)
    {
      launch_effect(i);
    }
    // Comment the loop above and uncomment the line below
    // if you want the effects in random order (produced some bugs.. )
    //launch_effect(rand()%13);
  }

}

// Launches one of those fancy effects.
void launch_effect (int effect)
{
  switch (effect)
  {
    // Lights all the layers one by one
    case 0:
      loadbar(1000);
      break;

    // A pixel bouncing randomly around
    case 1:
      // blink
      boingboing(150,500,0x03,0x01);
      break;

    // Randomly fill the cube
    // Randomly empty the cube
    case 2:
      fill(0x00);
      random_filler(100,1,500,1);
      random_filler(100,1,500,0);
      break;

    // Send voxels randomly back and forth the Z axis
    case 3:
      sendvoxels_rand_z(150,500,2000);
      break;

    // Spinning spiral
    case 4:
      effect_spiral(1,75,1000);
      break;

    // A coordinate bounces randomly around the cube
    // For every position the status of that voxel is toggled.
    case 5:
      // toggle
      boingboing(150,500,0x03,0x02);
      break;

    // Random raindrops
    case 6:
      effect_rain(20,5000,3000,500);
      break;

    // A snake randomly bounce around the cube.
    case 7:
      // snake
      boingboing(150,500,0x03,0x03);
      break;

    // Spinning plane
    case 8:
      effect_spinning_plane(1,50,1000);
      break;

    // set x number of random voxels, delay, unset them.
    // x increases from 1 to 20 and back to 1.
    case 9:
      random_2();
      break;

    // Set all 64 voxels in a random order.
    // Unset all 64 voxels in a random order.
    case 10:
      random_filler2(200,1);
      delay_ms(2000);
      random_filler2(200,0);
      delay_ms(1000);
      break;

    // bounce a plane up and down all the directions.
    case 11:
      flyplane("z",1,1000);
      delay_ms(2000);
      flyplane("y",1,1000);
      delay_ms(2000);
      flyplane("x",1,1000);
      delay_ms(2000);
      flyplane("z",0,1000);
      delay_ms(2000);
      flyplane("y",0,1000);
      delay_ms(2000);
      flyplane("x",0,1000);
      delay_ms(2000);
      break;

    // Fade in and out at low framerate
    case 12:
      blinky2();
      break;
  }
}

// ** Diagnostic led functions **

// Set or unset the red LED
void led_red(unsigned char state)
{
  if (state == 0x00)
  {
    LED_PORT &= ~LED_RED;
  } else
  {
    LED_PORT |= LED_RED;
  }
}

// Set or unset the green LED
void led_green(unsigned char state)
{
  if (state == 0x00)
  {
    LED_PORT &= ~LED_GREEN;
  } else
  {
    LED_PORT |= LED_GREEN;
  }
}


// Cube buffer draw interrupt routine
ISR(TIMER2_COMP_vect)
{

  // AND the reverse bitmask onto the layer port.
  // This disables all the layers. rendering all the leds off.
  // We don't want to see the cube updating.
  LAYER_PORT &= LAYERS_R;

  // Take the current 2D image at the current layer along the Z axis
  // and place it on the LED grid.
  GRID1 = (0x0f & cube[current_layer][0]) | (0xf0 & 
(cube[current_layer][1] << 4));
  GRID2 = (0x0f & cube[current_layer][2]) | (0xf0 & 
(cube[current_layer][3] << 4));

  // Enable the apropriate layer
  LAYER_PORT |= (0x01 << (7 - current_layer));

  // The cube only has 4 layers (0,1,2,3)
  // If we are at layer 3 now, we want to go back to layer 0.
  if (current_layer++ == 3)
    current_layer = 0;
}

void ioinit (void)
{
  // ### Initiate I/O

  // Data Direction Registers
  // Bit set to 1 means it works as an output
  // Bit set to 1 means it is an input
  DDRA = 0xff;  // Inner cube byte
  DDRB = 0xf7;  // ISP and 0-1: led. 3: button
  DDRC = 0xff;  // Outer cube byte
  DDRD = 0xff;  // Layer select

  // Set all ports OFF, and enable pull up resistors where needed.
  PORTA = 0x00;
  PORTC = 0x00;
  PORTB = 0x08; // Enable pull up button.
  PORTD = 0x00;

  // ### Initiate timers and USART

  // Frame buffer interrupt
  TCNT2 = 0x00;  // initial counter value = 0;
  TIMSK |= (1 << OCIE2); // Enable CTC interrupt

  // Every 1024th cpu cycle, a counter is incremented.
  // Every time that counter reaches 15, it is reset to 0,
  // and the interrupt routine is executed.
  // 14745600/1024/15 = 960 times per second
  // There are 4 layers to update..
  // 14745600/1024/15/4 = 240 FPS
  // == flicker free :)
  OCR2 = 15;       // interrupt at counter = 15
  TCCR2 = 0x05;     // prescaler = 1024
  TCCR2 |= (1 << WGM01);  // Clear Timer on Compare Match (CTC) mode


  // Initiate RS232
  // USART Baud rate: 9600
  UBRRH = MYUBRR >> 8;
  UBRRL = MYUBRR;
  // UCSR0C - USART control register
  // bit 7-6      sync/ascyn 00 = async,  01 = sync
  // bit 5-4      parity 00 = disabled
  // bit 3        stop bits 0 = 1 bit  1 = 2 bits
  // bit 2-1      frame length 11 = 8
  // bit 0        clock polarity = 0
  UCSRC  = 0b10000110;
  // Enable RS232, tx and rx
  UCSRB = (1<<RXEN)|(1<<TXEN);
  UDR = 0x00; // send an empty byte to indicate powerup.

}


// Blink the status LEDs a little to indicate that the device has just 
booted.
// This is usefull to see if an error is making the device reboot when 
not supposed to.
// And it looks cool.
void bootmsg (void)
{
  int i;
  LED_PORT |= LED_GREEN;
  for (i = 0; i < 2; i++)
  {
    // Blinky
    delay_ms(1000);
    LED_PORT &= ~LED_GREEN;
    LED_PORT |= LED_RED;
    // Blink
    delay_ms(1000);
    LED_PORT &= ~LED_RED;
    LED_PORT |= LED_GREEN;
  }
  delay_ms(1000);
  LED_PORT &= ~LED_GREEN;
}


// Delay function used in graphical effects.
void delay_ms(uint16_t x)
{
  uint8_t y, z;
  for ( ; x > 0 ; x--){
    for ( y = 0 ; y < 90 ; y++){
      for ( z = 0 ; z < 6 ; z++){
        asm volatile ("nop");
      }
    }
  }
}
[c/]

da hat sich doch glatt der halbe code versteckt

sorry

von Uwe (Gast)


Lesenswert?

Also doch nicht komplett. Oben sind doch die defines.
LED_PORT ist protb
LED_GREEN ist also Pin 0 von Port b. Dieser sollte nach dem start 
blinken.

von Berni (Gast)


Lesenswert?

siehe da alles durchgemessen und sie leuchtet schon mal !

worans gelegen ist kann ich nicht sagen hex ist die selbe wie vorher 
polarität an der led auch und der schalter ist auch drann ?!

ich bin mal kurtz im keller die matrix zu testen


schonmal riesen danke!

von Berni (Gast)


Lesenswert?

danke vielmals es läuft alles wie es soll :)

Eine Bitte noch kann mir jemand sagen was genau der button kann?

Danke :)

von Stefan Frings (Gast)


Lesenswert?

Der Button wird offensichtlich nicht verwendet

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.