schrittmotor Richtung umdrehen

Gast #1476233
Lesenswert?

Hallo,

Ich muss von einem Nanotec Schrittmotor die Drehrichtung umkehren.
D.h. wenn mann einen Taste drückt, wird die Drehrichtung umgekehrt.

Meinem pin für die Drehrichtung ist auf PINC.2 angeschlossen.

Da hab ich mir einen überlegt (also siehe code unten).

Kann jemand mir sagen warum es nicht funktioniert. Die Umkehrung des 
Richtung wird einfach ignoriert.


Danke schonmal
1
int Rotation_Sense(void)
2
{   
3
   int Stepper_Tack =0;
4
   if((PINC & 0x02) == 0x00) //Link Drehung
5
   Stepper_Tack = 0x02;
6
   
7
   else if((PINC & 0x02) == 0x01) //Recht Drehung
8
   Stepper_Tack = 0x00;
9
   
10
   PORTD = 0xFD;         // Led
11
   return Stepper_Tack;
12
}
13

14
.....
15
//in main
16

17
if((PINB & 0x01) == 0x00)
18
{
19
  UART_Puts( "Stepper Motor is enable" );    
20
  UART_Puts("\r\n");
21
  PORTD = 0xFE;     // Led
22
  PORTC = 0x20;    // Pins Motor Enable
23
      
24
  _delay_ms(50);    // dirty "debounce"
25

26
}
27
else if((PINB & 0x02) == 0x00)
28
{
29
  UART_Puts( "The direction is Toggle " );    
30
     UART_Puts("\r\n");
31

32
  mDirection =Rotation_Sense();
33
      
34
  _delay_ms(50);     // dirty "debounce"
35

36
}
37
else if((PINB & 0x04) == 0x00)
38
{
39
  UART_Puts( "Motor turns with a 1ms speed and 1/2 Tour" );  
40
     UART_Puts("\r\n");
41
  for(int i = 0; i<100; i++) //entspricht 1 Umdrehung 200 Schritte
42
  {
43
    PORTD = 0xFB;   // Led
44
    PORTC = mDirection | 0xFF;//Pins Motor
45
    _delay_ms(1);    // dirty "debounce" 
46
    PORTC = mDirection | 0xFE;  //Pins Motor
47
        
48
  }
49
  _delay_ms(50);
50
}
Gast #1476921
Lesenswert?

Danke an alle
ich bin kein profis in C
aber mit den code geht auch nicht wo ist dann meinem Fehler?
1
if((PINC & (1 << 2)) //Link Drehung
2
   Stepper_Tack = 0x02;
3
   
4
   else if((PINC & (0 << 2)) //Recht Drehung

gruß

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