Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / testing / wl_network_colonet / motor.c @ 13

History | View | Annotate | Download (1.08 KB)

1 13 emarinel
/*
2
        motor.c - Contains functions necessary for activating and driving the
3
        H-bridge
4

5

6
        author: Robotics Club, Colony project
7

8
        much of this is taken from FWR's library, author: Tom Lauwers
9

10
*/
11
12
#include "motor.h"
13
14
/*
15
motor initialization
16
initializes both motors
17

18
*/
19
void motors_init( void ) {
20
21
        // Configure counter such that we use phase correct
22
        // PWM with 8-bit resolution
23
        DDRB |= 0x60;
24
25
        //timer 1A and 1B
26
        TCCR1A = 0xA1;
27
        TCCR1B = 0x04;
28
        OCR1AH=0;
29
        OCR1AL=0;
30
        OCR1BH=0;
31
        OCR1BL=0;
32
}
33
34
// The following functions set the motor direction and speed
35
void motor1_set(int direction, int speed) {
36
        if(direction == 0) {
37
                PORTD |= 0x10;
38
                PORTD &= 0xBF;
39
        }
40
        else {
41
                PORTD |= 0x40;
42
                PORTD &= 0xEF;
43
        }
44
45
        // Set the timer to count up to speed, an 8-bit value
46
        OCR1AL = speed;
47
}
48
49
void motor2_set(int direction, int speed) {
50
        if(direction == 0) {
51
                PORTD |= 0x20;
52
                PORTD &= 0x7F;
53
        }
54
        else {
55
                PORTD |= 0x80;
56
                PORTD &= 0xDF;
57
        }
58
        OCR1BL = speed;
59
}
60
61
// Just turns off both motors
62
void motors_off( void ) {
63
        OCR1AL = 0x0;
64
        OCR1BL = 0x0;
65
}