Blame view

RIOT/tests/driver_tb6612fng/main.c 1.2 KB
31faf16b   elopes   add a new dc moto...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <stdio.h>
  
  #include "cpu.h"
  #include "board.h"
  #include "xtimer.h"
  #include "periph/pwm.h"
  #include "periph/gpio.h"
  #include "tb6612fng.h"
  
  #define PWM1        PWM_DEV(0)
  #define PWM2	    PWM_DEV(1)
  
  #define MOTOR1_CHANNEL     1
  #define MOTOR1_IN1     GPIO_PIN(PORT_E,0)
  #define MOTOR1_IN2     GPIO_PIN(PORT_E,2)
  
  #define MOTOR2_CHANNEL     1
  #define MOTOR2_IN1     GPIO_PIN(PORT_E,1)
  #define MOTOR2_IN2     GPIO_PIN(PORT_E,3)
  
  #define STBY	GPIO_PIN(PORT_D,4)
  
  static motor_t left;
  static motor_t right;
  
  
  int main(void)
  {
      int res;
      puts("\nRIOT dc motor test");
      puts("Connect an dc motor or scope to PWM_0/1 channel 1 to see anything");
  
      res = motor_init(&left,PWM1,MOTOR1_CHANNEL,MOTOR1_IN1,MOTOR1_IN2,STBY,1);
      if (res < 0) {
          puts("Errors while initializing motor");
          return -1;
      }
      puts("motor 1 initialized.");
  
     res = motor_init(&right,PWM2,MOTOR2_CHANNEL,MOTOR2_IN1,MOTOR2_IN2,STBY,1);
      if (res < 0) {
          puts("Errors while initializing motor");
          return -1;
      }
      puts("motor 2 initialized.");
  
      while (1) {
          motor_forward(&left,&right,100);
          xtimer_sleep(1);
  	motor_back(&left,&right,100);
  	xtimer_sleep(1);
      }
  
      return 0;
  }