5e5cc9af9b352bb8495a26b3be3560daaa89979f
[aversive.git] / modules / devices / brushless_motors / brushless_3phase_digital_hall / 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:12 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   
48         if(cpt == 10)
49                 dir = -1;
50         if (cpt == -10 )
51                 dir = 1;
52   
53   
54   
55         brushless_0_set_parameters(BRUSHLESS_MAX_SPEED, PWM_MAX/10*cpt    /1  );
56
57         printf_P(PSTR("vitesse M0 : %5i t/s %5i t/min      "), mesures.speed /48, (int16_t)((int32_t)mesures.speed *60/48));
58
59 }
60
61 void test_capteurs(void)
62 {
63
64         uint8_t sensor1_0;uint8_t sensor2_0;uint8_t sensor3_0;
65         //uint8_t sensor1_1;uint8_t sensor2_1;uint8_t sensor3_1;
66   
67         while(1)
68                 {
69
70                         sensor1_0 = 0;sensor2_0 = 0;sensor3_0 = 0;
71                         //sensor1_1 = 0;sensor2_1 = 0;sensor3_1 = 0;
72     
73     
74                         if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_1_PORT),BRUSHLESS_0_SENSOR_1_BIT))
75                                 sensor1_0 =1;
76                         if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_2_PORT),BRUSHLESS_0_SENSOR_2_BIT))
77                                 sensor2_0 =1;
78                         if(bit_is_set(PIN(BRUSHLESS_0_SENSOR_3_PORT),BRUSHLESS_0_SENSOR_3_BIT))
79                                 sensor3_0 =1;
80       
81
82   
83                         /*if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_1_PORT),BRUSHLESS_1_SENSOR_1_BIT))
84                           sensor1_1 =1;
85                           if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_2_PORT),BRUSHLESS_1_SENSOR_2_BIT))
86                           sensor2_1 =1;
87                           if(bit_is_set(PIN(BRUSHLESS_1_SENSOR_3_PORT),BRUSHLESS_1_SENSOR_3_BIT))
88                           sensor3_1 =1;*/
89
90                         printf_P(PSTR("sensors M0 = %i%i%i    "), sensor1_0,sensor2_0,sensor3_0);
91                         wait_ms(100);
92                         //printf_P(PSTR("sensors M1 = %i%i%i\n")  , sensor1_1,sensor2_1,sensor3_1);
93
94                         wait_ms(250);
95                 }
96   
97 }
98
99
100
101
102
103 int main(void)
104 {
105
106
107   
108         brushless_init();
109
110         wait_ms(500);
111
112
113         uart_init();
114         fdevopen((void *)uart0_send,NULL,0);
115
116         printf_P(PSTR("\nbonjour\n"));
117         sei();
118   
119
120
121         //test_capteurs();
122
123
124
125
126         // enable power bridges
127         sbi(DDRG, 1);
128         sbi(PORTG, 1);
129   
130
131
132         brushless_0_register_periodic_event(event0);
133
134         show_int_loop();
135         return 0;
136 }
137