Commit 6601d4decc245caf83e960c43c3109a2c5a8d6d1
1 parent
7d329109
Test moteurs sur le robot
Showing
2 changed files
with
25 additions
and
8 deletions
Show diff stats
PercTeacher/Sources/Robot/servoAndStepperControl.c
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | #define PIN_MOTEUR_GAUCHE 0x40 // pin 12 |
7 | 7 | #define PIN_MOTEUR_DROIT 0x20 // pin 11 |
8 | 8 | |
9 | +#define CPU_FREQ 16000000L | |
10 | + | |
9 | 11 | //gestion des moteurs |
10 | 12 | void init_pins(void){ |
11 | 13 | // pin 12 et 11 |
... | ... | @@ -57,8 +59,8 @@ int main(void){ |
57 | 59 | unsigned char deltaR2 = get_serial(); |
58 | 60 | |
59 | 61 | // conversion 2x8 bits => 16 bits |
60 | - int deltaL = deltaL1 << 8 + deltaL2; | |
61 | - int deltaR = deltaR1 << 8 + deltaR2; | |
62 | + int deltaL = (deltaL1 << 8) + deltaL2; | |
63 | + int deltaR = (deltaR1 << 8) + deltaR2; | |
62 | 64 | |
63 | 65 | int deltaMax = deltaL > deltaR ? deltaL : deltaR; |
64 | 66 | for(int i=0; i<deltaMax; i++){ |
... | ... | @@ -67,7 +69,8 @@ int main(void){ |
67 | 69 | if(deltaR > i) |
68 | 70 | pas_moteur_droit(); |
69 | 71 | } |
70 | - | |
72 | + | |
73 | + send_serial(0x01); | |
71 | 74 | } |
72 | 75 | return 0; |
73 | 76 | } | ... | ... |
tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c
... | ... | @@ -3,13 +3,27 @@ |
3 | 3 | |
4 | 4 | int main(void){ |
5 | 5 | // pin 13 |
6 | - DDRB = 0x80; | |
6 | + DDRB = 0xC0; | |
7 | 7 | |
8 | + PORTB |= 0x40; // forward | |
9 | + int i = 0; | |
10 | + int sens = 0; | |
8 | 11 | while(1){ |
9 | - PORTB = 0x80; | |
10 | - _delay_us(1000); | |
11 | - PORTB = 0x00; | |
12 | - _delay_us(1000); | |
12 | + // step | |
13 | + PORTB |= 0x80; | |
14 | + _delay_ms(5); | |
15 | + PORTB &= 0x7F; | |
16 | + _delay_ms(5); | |
17 | + // dir | |
18 | + i++; | |
19 | + if(i > 200){ | |
20 | + i = 0; | |
21 | + sens = 1 - sens; | |
22 | + if(sens == 0) | |
23 | + PORTB |= 0x40; // forward | |
24 | + else | |
25 | + PORTB &= 0xBF; // backward | |
26 | + } | |
13 | 27 | } |
14 | 28 | return 0; |
15 | 29 | } | ... | ... |