accalleration and update test

This commit is contained in:
Mats van Reenen 2020-06-06 19:31:22 +02:00
parent 2d76ca73ef
commit f764c445fd

33
main.c
View File

@ -41,7 +41,7 @@
* 1: NFC test * 1: NFC test
* 2: motioncontroller test * 2: motioncontroller test
*/ */
#define TEST 1 #define TEST 0
const uchar STEP_PINS = BIT4 | BIT5; const uchar STEP_PINS = BIT4 | BIT5;
const uchar DIRr_PIN = BIT3; const uchar DIRr_PIN = BIT3;
@ -53,16 +53,21 @@ const ulong halfRound = 2800;
void stap(uint n, ulong t){ void stap(uint n, ulong t){
ulong d = t; ulong d = t;
uint s = n-100;
while(n != 0){ while(n != 0){
n--; n--;
P2OUT |= STEP_PINS; P2OUT |= STEP_PINS;
P2OUT &= ~STEP_PINS; P2OUT &= ~STEP_PINS;
d=t; if(s < n || n < 100)
d = 100; // a crude way of a accaleration
else
d=t;
while(d != 0){ while(d != 0){
d--; d--;
__delay_cycles(160); __delay_cycles(160);
} }
} }
__delay_cycles(160000);
} }
void dir(enum Direction d){ void dir(enum Direction d){
@ -105,35 +110,35 @@ int main(void)
for(ii=2; ii>0; ii--){ for(ii=2; ii>0; ii--){
dir(Forward); dir(Forward);
stap(16000, v); stap(10000, v);
__delay_cycles(160000);
dir(RightTurn); dir(RightTurn);
stap(halfRound, v*2); stap(halfRound, v*2);
__delay_cycles(160000);
dir(Forward); dir(Forward);
stap(16000, v); stap(10000, v);
__delay_cycles(160000);
dir(LeftTurn); dir(LeftTurn);
stap(halfRound, v*2); stap(halfRound, v*2);
__delay_cycles(160000);
} }
for(ii=2; ii>0; ii--){ for(ii=2; ii>0; ii--){
for(i=4; i>0; i--){ for(i=5; i>0; i--){
dir(Forward); dir(Forward);
stap(1600, v); stap(1600, v);
__delay_cycles(160000);
dir(RightTurn); dir(RightTurn);
stap(halfRound/2, v*2); stap(halfRound/2, v*2);
__delay_cycles(160000);
} }
for(i=4; i>0; i--){ dir(Forward);
stap(1600, v);
dir(RightTurn);
stap(halfRound, v*2);
for(i=5; i>0; i--){
dir(Forward); dir(Forward);
stap(1600, v); stap(1600, v);
__delay_cycles(160000);
dir(LeftTurn); dir(LeftTurn);
stap(halfRound/2, v*2); stap(halfRound/2, v*2);
__delay_cycles(160000);
} }
dir(Forward);
stap(1600, v);
dir(LeftTurn);
stap(halfRound, v*2);
} }
#endif #endif