Project

General

Profile

Revision 437

Added by Kevin Woo almost 14 years ago

Cleaned up analog.c code. Recompiled library. Mostly commenting and
documentation fixes. No changes made to actual code.

View differences:

motor.c
50 50
 * @see motors_off, motor1_set, motor2_set
51 51
 **/
52 52
void motors_init( void ) {
53
	// Configure counter such that we use phase correct
54
	// PWM with 8-bit resolution
55
	PORTA &= 0x0F;
56
	DDRA |= 0xF0;
57
	DDRB |= 0x60;
53
  // Configure counter such that we use phase correct
54
  // PWM with 8-bit resolution
55
  PORTA &= 0x0F;
56
  DDRA |= 0xF0;
57
  DDRB |= 0x60;
58 58

  
59
	//timer 1A and 1B
60
	TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
61
	TCCR1B = _BV(WGM12) | _BV(CS10);
62
//	TCCR1A = 0xA1;
63
//	TCCR1B = 0x04;
64
	OCR1AH=0;
65
	OCR1AL=0;
66
	OCR1BH=0;
67
	OCR1BL=0;
59
  //timer 1A and 1B
60
  TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
61
  TCCR1B = _BV(WGM12) | _BV(CS10);
62
  //	TCCR1A = 0xA1;
63
  //	TCCR1B = 0x04;
64
  OCR1AH=0;
65
  OCR1AL=0;
66
  OCR1BH=0;
67
  OCR1BL=0;
68 68
}
69 69

  
70 70
/**
......
78 78
 **/
79 79
void motor1_set(int direction, int speed) {
80 80

  
81
	if(direction == 0) {
82
	    // turn off PWM first if switching directions
83
		if((PORTA & 0x30) != 0x10)
84
		{
85
		  OCR1A = 0;
86
		}	
87
		PORTA = (PORTA & 0xCF) | 0x10;
88
//		PORTD |= 0x10;
89
//		PORTD &= 0xBF;
90
	}
91
	else {
92
	    // turn off PWM first if switching directions
93
		if((PORTA & 0x30) != 0x20)
94
		{
95
		  OCR1A = 0;
96
		}
97
		PORTA = (PORTA & 0xCF) | 0x20;
98
//		PORTD |= 0x40;
99
//		PORTD &= 0xEF;
100
	}
81
  if(direction == 0) {
82
    // turn off PWM first if switching directions
83
    if((PORTA & 0x30) != 0x10) {
84
      OCR1A = 0;
85
    }	
86
    PORTA = (PORTA & 0xCF) | 0x10;
87
    //		PORTD |= 0x10;
88
    //		PORTD &= 0xBF;
89
  } else {
90
    // turn off PWM first if switching directions
91
    if((PORTA & 0x30) != 0x20) {
92
      OCR1A = 0;
93
    }
94
    PORTA = (PORTA & 0xCF) | 0x20;
95
    //		PORTD |= 0x40;
96
    //		PORTD &= 0xEF;
97
  }
101 98
	
102
	// Set the timer to count up to speed, an 8-bit value
103
	OCR1AL = speed;
99
  // Set the timer to count up to speed, an 8-bit value
100
  OCR1AL = speed;
104 101
}
105 102

  
106 103
/**
......
113 110
 * @see motor1_set, motors_init
114 111
 **/
115 112
void motor2_set(int direction, int speed) {
116
	if(direction == 0) {
117
//		PORTD |= 0x20;
118
//		PORTD &= 0x7F;
119
	    // turn off PWM first if switching directions
120
		if((PORTA & 0xC0) != 0x80)
121
		{
122
		  OCR1B = 0;
123
		}		
113
  if(direction == 0) {
114
    //		PORTD |= 0x20;
115
    //		PORTD &= 0x7F;
116
    // turn off PWM first if switching directions
117
    if((PORTA & 0xC0) != 0x80) {
118
      OCR1B = 0;
119
    }		
124 120
		
125
		PORTA = (PORTA & 0x3F) | 0x80;
126
	}
127
	else {
128
//		PORTD |= 0x80;
129
//		PORTD &= 0xDF;
121
    PORTA = (PORTA & 0x3F) | 0x80;
122
  } else {
123
    //		PORTD |= 0x80;
124
    //		PORTD &= 0xDF;
130 125

  
131
	    // turn off PWM first if switching directions
132
		if((PORTA & 0xC0) != 0x40)
133
		{
134
		  OCR1B = 0;
135
		}		
126
    // turn off PWM first if switching directions
127
    if((PORTA & 0xC0) != 0x40) {
128
      OCR1B = 0;
129
    }		
136 130
		
137
		PORTA = (PORTA & 0x3F) | 0x40;
138
	}
139
	OCR1BL = speed;
131
    PORTA = (PORTA & 0x3F) | 0x40;
132
  }
133
  OCR1BL = speed;
140 134
}
141 135

  
142 136
/**
......
145 139
 * @see motors_init
146 140
 **/
147 141
void motors_off( void ) {
148
	OCR1AL = 0x0;
149
	OCR1BL = 0x0;
142
  OCR1AL = 0x0;
143
  OCR1BL = 0x0;
150 144
}
151 145

  
152 146
/**@}**///end defgroup

Also available in: Unified diff