Zeitraffer Programm (Probleme mit UART)

Gast #1735163
Lesenswert?

Moin,
bin grad dabei nen motion-ctrl Programm für nen Zeitraffer Kamerakopf 
auf dem ATM8 zu schreiben.

Allerdings tritt ein merkwürdiges Problem auf:
Die Funktion, welche ich zum einlesen von Werten im UART verwendet habe 
hört nicht mehr auf einzulesen....
1
case '1':   uart_puts_P("\fSet Movielength[s]:");
2
            for (int i=0; i < 7; i++) buffer[i] = '\0';
3
            for (int j=0; j < 4; j++){
4
              while(buffer[j] == '\0') buffer[j] =  uart_getc();
5
              uart_putc(buffer[j]);
6
            }
7
            movielength = atoi(buffer);
8
            status = 0;
9
            break;

Benutze die UART-Funktionen von Peter Fleury.
Was mache ich falsch? bis vor kurzem hat diese Fkt. noch funktioniert.

Gruß
Horst
Gast #1735194
Lesenswert?

Also Interrupts sind immer an.
1
  //UART
2
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); 
3

4
  //Timer1 ------ Shutter Ctrl config
5
    TCCR1B |= (1<<WGM12); // CTC1 Modus
6
    TCCR1B |= (1<<CS11) | (1<<CS10); // Prescaler 64
7
    // ((8000000/64)/1000) = 125
8
    OCR1A = 125-1;
9
    // Compare Interrupt erlauben
10
    TIMSK |= (1<<OCIE1A);
11

12
  //Timer0 ------ Stepper Ctrl config
13
    TCCR0 = (1<<CS00); // CPU Takt
14
    // Overflow Interrupt 
15
    TIMSK |= (1<<TOIE0);
16

17
  //Interrupts 
18
  sei();

Könnten meine Timer den UART zerschiessen?
1
//Interruptroutines
2
ISR (TIMER1_COMPA_vect)
3
{
4
    milliseconds++;
5
    if(milliseconds >= msperframe){
6
      milliseconds = 0;
7
    makephoto = 1;
8
    frames++;
9
    }
10
}
11

12
ISR (TIMER0_OVF_vect)
13
{
14
  if(runsteppers == 1){
15
      s1eightmicroseconds++;
16
      if (s1eightmicroseconds >= s1microvelocity){
17
        PORTC |=(1<<PC2);
18
      asm("nop");
19
      asm("nop");
20
      asm("nop");
21
      asm("nop");
22
      asm("nop");
23
      asm("nop");
24
      asm("nop");
25
      asm("nop");
26
      asm("nop");
27
      s1eightmicroseconds = 0;
28
     }
29
      else PORTC &=~(1<<PC2);
30

31
      s2eightmicroseconds++;
32
      if (s2eightmicroseconds >= s2microvelocity){
33
        PORTC |=(1<<PC4);
34
      asm("nop");
35
      asm("nop");
36
      asm("nop");
37
      asm("nop");
38
      asm("nop");
39
      asm("nop");
40
      asm("nop");
41
      asm("nop");
42
      asm("nop");
43
      s2eightmicroseconds = 0;
44
      }
45
      else PORTC &=~(1<<PC3);
46
  }
47
}

das komische ist, das diese Funktion hier soweit funktioniert:
1
      case '4':   //Set Angle S1
2
            uart_puts_P("\fSet Angle S1[°]:");
3
            for (int i=0; i < 7; i++) buffer[i] = '\0';
4
            for (int i=0; i < 3; i++){
5
              while(buffer[i] == '\0') buffer[i] =  uart_getc();
6
              uart_putc(buffer[i]);
7
            }
8
            s1angle = atoi(buffer);
9
            uart_puts_P("\n\rAngle set to:");
10
            itoa(s1angle, buffer, 10);
11
            uart_puts(buffer);
12
            for (int i=0; i < 7; i++) buffer[i] = '\0';
13
            s1angle = (s1angle*10000)/360;
14

15
            //Set Direction S1
16
            uart_puts_P("\n\rSet Direction S1[l/r]:");
17
            for (int i=0; i < 7; i++) buffer[i] = '\0';
18
            while(buffer[0] == '\0') buffer[0] =  uart_getc();
19
            if(buffer[0] == 'r') PORTC |=(1<<PC3);
20
            else{ 
21
              if(buffer[0] == 'l') PORTC &=~(1<<PC3);
22
              else uart_puts_P("ERROR");
23
            }
24
            for (int i=0; i < 7; i++) buffer[i] = '\0';
25
            status = 0;
26
            break;

Gruß
Horst
Gast #1735212
Lesenswert?

Könnten meine Timer den UART zerschiessen?
1
//Interruptroutines
2

3
//Interrupt every millisecond:
4
ISR (TIMER1_COMPA_vect)
5
{
6
    //increase milliseconds
7
    milliseconds++;
8
    //compare actual milliseconds to milliseconds per frame
9
    if(milliseconds >= msperframe){
10
      milliseconds = 0;
11
      //make a photo
12
      makephoto = 1;
13
      //count up total frames
14
      frames++;
15
    }
16
}
17

18
//Interrupt every 32µs
19
ISR (TIMER0_OVF_vect)
20
{
21
  only do something when steppers are active
22
  if(runsteppers == 1){
23
      //increase timing counter
24
      s1eightmicroseconds++;
25
      //compare microseconds to a previously calculated variable
26
      if (s1eightmicroseconds >= s1microvelocity){
27
        PORTC |=(1<<PC2);
28
        //do nothing (keep the pulselength > 1µs)
29
      asm("nop");
30
      asm("nop");
31
      asm("nop");
32
      asm("nop");
33
      asm("nop");
34
      asm("nop");
35
      asm("nop");
36
      asm("nop");
37
      asm("nop");
38
      s1eightmicroseconds = 0;
39
     }
40
      else PORTC &=~(1<<PC2);
41

42
      s2eightmicroseconds++;
43
      if (s2eightmicroseconds >= s2microvelocity){
44
        PORTC |=(1<<PC4);
45
      asm("nop");
46
      asm("nop");
47
      asm("nop");
48
      asm("nop");
49
      asm("nop");
50
      asm("nop");
51
      asm("nop");
52
      asm("nop");
53
      asm("nop");
54
      s2eightmicroseconds = 0;
55
      }
56
      else PORTC &=~(1<<PC3);
57
  }
58
}

das komische ist, das diese Funktion hier soweit funktioniert:
1
      case '4':   //Set Angle S1
2
            uart_puts_P("\fSet Angle S1[°]:");
3
            //clear buffer
4
            for (int i=0; i < 7; i++) buffer[i] = '\0';
5
            //read in array of 3 chars
6
            for (int i=0; i < 3; i++){
7
              while(buffer[i] == '\0') buffer[i] =  uart_getc();
8
              uart_putc(buffer[i]);
9
            }
10
            //convert to integer
11
            s1angle = atoi(buffer);
12
            //give back value
13
            uart_puts_P("\n\rAngle set to:");
14
            itoa(s1angle, buffer, 10);
15
            uart_puts(buffer);
16
            //clear buffer
17
            for (int i=0; i < 7; i++) buffer[i] = '\0';
18
            //calculate steps for the specified move
19
            s1angle = (s1angle*10000)/360;
20

21
            //Set Direction S1
22
            uart_puts_P("\n\rSet Direction S1[l/r]:");
23
            //clear buffer
24
            for (int i=0; i < 7; i++) buffer[i] = '\0';
25
            //read in 1 char
26
            while(buffer[0] == '\0') buffer[0] =  uart_getc();
27
            if(buffer[0] == 'r') PORTC |=(1<<PC3);
28
            else{ 
29
              if(buffer[0] == 'l') PORTC &=~(1<<PC3);
30
              else uart_puts_P("ERROR");
31
            }
32
            //clear buffer
33
            for (int i=0; i < 7; i++) buffer[i] = '\0';
34
            //set back status
35
            status = 0;
36
            break;

Gruß
Horst

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren