aaebd2e4990fdd32f1344c5ed1c9835bee90cd46
[aversive.git] / modules / devices / brushless_motors / brushless_3phase_digital_hall_double / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: main.c,v 1.2.2.3 2007-05-23 17:18:13 zer0 Exp $
19  *
20  */
21  
22 #include <avr/io.h>
23 #include <aversive/wait.h>
24 #include <aversive.h>
25
26 #include <brushless.h>
27
28 #include <pwm.h>
29
30 #include <diagnostic.h>
31
32 #include <uart.h>
33 #include <stdio.h>
34 #include <aversive/pgmspace.h>
35
36
37
38
39
40 void event0(brushless mesures)
41 {
42         static int8_t cpt;
43         static int8_t dir = 1;
44
45         cpt +=dir;
46   
47         if(cpt == 10)
48                 dir = -1;
49         if (cpt == -10 )
50                 dir = 1;
51   
52   
53   
54         brushless_0_set_parameters(BRUSHLESS_MAX_SPEED, PWM_MAX/10*cpt    /1  );
55
56         printf_P(PSTR("vitesse M0 : %5i t/s %5i t/min      "), mesures.speed /48, (int16_t)((int32_t)mesures.speed *60/48));
57
58 }
59 void event1(brushless mesures)
60 {
61         static int8_t cpt;
62         static int8_t dir = 1;
63
64         cpt +=dir;
65   
66         if(cpt == 10)
67                 dir = -1;
68         if (cpt == -10 )
69                 dir = 1;
70   
71   
72   
73         brushless_1_set_parameters(BRUSHLESS_MAX_SPEED, PWM_MAX/10*cpt    /1  );
74
75         printf_P(PSTR("vitesse M1 : %5i t/s %5i t/min\n"), mesures.speed /48, (int16_t)((int32_t)mesures.speed *60/48));
76
77 }
78
79 void test_capteurs(void)
80 {
81
82         uint8_t sensor1_0;
83         uint8_t sensor2_0;
84         uint8_t sensor3_0;
85         
86         uint8_t sensor1_1;
87         uint8_t sensor2_1;
88         uint8_t sensor3_1;
89   
90         while(1) {
91
92                 sensor1_0 = 0;
93                 sensor2_0 = 0;
94                 sensor3_0 = 0;
95                 
96                 sensor1_1 = 0;
97                 sensor2_1 = 0;
98                 sensor3_1 = 0;
99     
100                 if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_1_PORT),BRUSHLESS_0_SENSOR_1_BIT))
101                         sensor1_0 =1;
102                 if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_2_PORT),BRUSHLESS_0_SENSOR_2_BIT))
103                         sensor2_0 =1;
104                 if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_3_PORT),BRUSHLESS_0_SENSOR_3_BIT))
105                         sensor3_0 =1;
106       
107
108   
109                 if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_1_PORT),BRUSHLESS_1_SENSOR_1_BIT))
110                         sensor1_1 =1;
111                 if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_2_PORT),BRUSHLESS_1_SENSOR_2_BIT))
112                         sensor2_1 =1;
113                 if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_3_PORT),BRUSHLESS_1_SENSOR_3_BIT))
114                         sensor3_1 =1;
115
116                 printf_P(PSTR("sensors M0 = %i%i%i    "), sensor1_0,sensor2_0,sensor3_0);
117                 wait_ms(100);
118                 printf_P(PSTR("sensors M1 = %i%i%i\n")  , sensor1_1,sensor2_1,sensor3_1);
119
120                 wait_ms(250);
121         }
122   
123 }
124
125
126
127
128
129 int main(void)
130 {
131
132
133   
134         brushless_init();
135
136         //wait_ms(500);
137
138
139         uart_init();
140         fdevopen((void *)uart0_send,NULL,0);
141
142         printf_P(PSTR("\nbonjour\n"));
143         sei();
144
145
146
147
148         //test_capteurs();
149
150
151         // enable power bridges
152         sbi(DDRG, 1);
153         sbi(PORTG, 1);
154   
155
156
157         brushless_0_register_periodic_event(event0);
158         brushless_1_register_periodic_event(event1);
159         show_int_loop();
160         return 0;
161 }
162