Forum: Mikrocontroller und Digitale Elektronik Attiny3213 Programmierung Servoanschlüsse


von Black H. (blackhawk852)


Angehängte Dateien:

Lesenswert?

Hallo ich möchte an Pin 16 noch einen Servoanschluss hinzufügen wie er 
bereits an Pin 15 vorhanden ist. Pin 18 und 19 möchte ich nicht Nutzen. 
Wäre echt nett wenn mir jemand helfen könnte den Programmcode 
dementsprechend abzuändern. Im Anhang ein Schema zum Microcontroller 
statt der H-Bridge möchte ich einen elektronischen Fahrtenregler 
anschließen dieser hat dann einen Servo anschluss wie auf Pin 15 schon 
vorhanden ist.
1
/* Bluetooth Controlled Car
2
Accpets commands through UART, via GP-GC021 Bluetooth Module
3
Control of head lights, brake lights, one drive motor and one
4
steering servo are implemented.
5
Clock frequency is 4MHz
6
*/
7
8
#define HDLED PORTB.B7
9
#define BRKLED PORTB.B6
10
#define M1p PORTB.B5
11
#define M1m PORTB.B4
12
#define SERVO PORTB.B3
13
14
unsigned short uart_rd;
15
char pos;
16
17
// Posistion Servo Rotor
18
void position(){
19
     char i;
20
     SERVO = 1;
21
     // create ON-time delay in 10ths of a ms, delay in for-loop, hence less than 100ms
22
     for (i=0; i<=pos; i++) Delay_us(85);
23
     SERVO = 0;
24
     Delay_ms(12);
25
}
26
27
// Write outputs
28
void action(){
29
// simple error check
30
   if ((uart_rd & 0b00000011)>0){        // faulty byte received, since last two bits aren't used
31
      // clear outputs, center servo
32
      PORTB = 0;
33
      UART1_Write(0b00000011);           // send error, ie faulty bits
34
      pos = 14;                          // compensate for off-center rotor placement, 1.5ms should be standard
35
   }else{
36
      // write outputs, place servo
37
      UART1_Write(uart_rd);              // send response
38
      if ((uart_rd & 0b00001000)>0){
39
           pos = 9;
40
      }else if ((uart_rd & 0b00000100)>0){
41
           pos = 18;
42
      }else{
43
           pos = 14;                      // compensate for off-center rotor placement
44
      }
45
      PORTB = uart_rd & 0xF0;
46
   }
47
}
48
49
// Read UART and call action
50
void main() {
51
     UART1_Init(9600);                   // Initialize UART module at 9600 bps
52
     Delay_ms(100);                      // Wait for UART module to stabilize
53
     DDRB = 0b11111000;                  // PORTB as output, save PB0, PB1 and PB2 which aren't used
54
     PORTB = 0;                          // Initialize portb
55
56
 while (1)
57
 {
58
       if (UART1_Data_Ready())           // If data is received,
59
       {
60
          uart_rd = UART1_Read();        // read the received data
61
       }
62
       action();                         // write outputs
63
       position();                       // posistion servo
64
 }
65
}

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.