
Medi
Revision 1:b974ec8fe646, committed 2020-03-11
- Comitter:
- carlotara
- Date:
- Wed Mar 11 15:12:13 2020 +0000
- Parent:
- 0:6999a083fb46
- Commit message:
- Medici
Changed in this revision
diff -r 6999a083fb46 -r b974ec8fe646 main.cpp --- a/main.cpp Thu Jun 14 12:18:18 2012 +0000 +++ b/main.cpp Wed Mar 11 15:12:13 2020 +0000 @@ -10,53 +10,174 @@ */ #include "mbed.h" -#include "sMotor.h" + Serial pc(USBTX, USBRX); -sMotor motor(p9, p10, p11, p12); // creates new stepper motor: IN1, IN2, IN3, IN4 +//sMotor motor(D8, D9, D10, D11); // creates new stepper motor: IN1, IN2, IN3, IN4 +//sMotor motor(p9, p10, p11, p12); // creates new stepper motor: IN1, IN2, IN3, IN4 int step_speed = 1200 ; // set default motor speed -int numstep = 512 ; // defines full turn of 360 degree +//int numstep = 512 ; // defines full turn of 360 degree +int numstep = 514 + ; // defines full turn of 360 degree //you might want to calibrate this value according to your motor +int statomax =7; +//int kmax = 2; +//int statomax =7; +int kmax = 8; +int stato; +int ora = 1; +int data = 0; +//int statomax =7; + + +DigitalOut IN1(D8); +DigitalOut IN2(D9); +DigitalOut IN3(D10); +DigitalOut IN4(D11); + +/* +const int IN1 = 8; // filo motore BLUE +const int IN2 = 9; // filo motore ROSA +const int IN3 = 10; // filo motore GIALLO +const int IN4 = 11; // filo motore ARANCIO +*/ +const int MotoreOFF = 99; // motore spento + + + +void Uscita( int i4,int i3,int i2,int i1) +{ + if (i1==1) IN1=1; else IN1=0; + if (i2==1) IN2=1; else IN2=0; + if (i3==1) IN3=1; else IN3=0; + if (i4==1) IN4=1; else IN4=0; +/* + if (i1==1) digitalWrite(IN1,HIGH); else digitalWrite(IN1,LOW); + if (i2==1) digitalWrite(IN2,HIGH); else digitalWrite(IN2,LOW); + if (i3==1) digitalWrite(IN3,HIGH); else digitalWrite(IN3,LOW); + if (i4==1) digitalWrite(IN4,HIGH); else digitalWrite(IN4,LOW); + */ +} + -int main() { - - //Credits - printf("4 Phase Stepper Motor v0.1 - Test Program\r\n"); - printf("developed by Samuel Matildes\r\n"); - printf("\n\r"); +void EseguiPasso(int stato) +{ +int i1,i2,i3,i4; - // Screen Menu - printf("Default Speed: %d\n\r",step_speed); - printf("1- 360 degree clockwise step\n\r"); - printf("2- 360 degree anticlockwise step\n\r"); - printf("3- 180 degree clockwise step\n\r"); - printf("4- 180 degree anticlockwise step\n\r"); - printf("5- Change Speed\n\r"); + switch ( stato ) + {// vedi tabella nel pdf del motore passo passo + case 0: Uscita(0,0,0,1); break; + case 1: Uscita(0,0,1,1); break; + case 2: Uscita(0,0,1,0); break; + case 3: Uscita(0,1,1,0); break; + case 4: Uscita(0,1,0,0); break; + case 5: Uscita(1,1,0,0); break; + case 6: Uscita(1,0,0,0); break; + case 7: Uscita(1,0,0,1); break; + case 8: Uscita(0,0,0,1); break; + case 9: Uscita(0,0,1,1); break; + case 10: Uscita(0,0,1,0); break; + case 11: Uscita(0,1,1,0); break; + case 12: Uscita(0,1,0,0); break; + case 13: Uscita(1,1,0,0); break; + case 14: Uscita(1,0,0,0); break; +// case 7: Uscita(1,0,0,1); break; + case MotoreOFF: //OFF + Uscita(0,0,0,0); break; + } + wait_ms(1); + // delay(1); //ritardo almeno 1 mS +} - while (1) { +void RitardoAccensione() +{ //attesa prima di attivare il motore + EseguiPasso(MotoreOFF); + for(int i=0; i<10; i++) + { +// digitalWrite(13,HIGH); +// wait_ms(250); + // delay(250); +// digitalWrite(13,LOW); +// wait_ms(250); + // delay(250); + } +} - if (pc.readable()) { // checks for serial +int main() +{ - if (pc.getc()=='1') - motor.step(numstep,0,step_speed); // number of steps, direction, speed + RitardoAccensione(); //2 secondi di pausa prima di iniziare + while (1) { + char kmaxCh; + printf("Inserisci numero Settore \r\n"); + // scanf("%c", &kmaxCh); + // printf("%c\n",kmaxCh); + scanf("%d", &kmax); + printf("%d\n",kmax); +//char numberstring[] = "42"; +//int number; + +//sscanf(numberstring, "%d", &number); +// kmax = 2; + stato=0; //inizio da uno stato arbitrario - if (pc.getc()=='2') - motor.step(numstep,1,step_speed); - if (pc.getc()=='3') - motor.step(numstep/2,0,step_speed); +if (kmax>0) +{ + stato=0; //inizio da uno stato arbitrario - if (pc.getc()=='4') - motor.step(numstep/2,1,step_speed); - - if (pc.getc()=='5') { - printf("Current Speed: %d\n\r", step_speed); - printf("New speed: \n\r"); - pc.scanf("%d",&step_speed); // sets new speed + for(int k=0; k<kmax; k++) //Rotazione Oraria + // for(int k=0; k<4; k++) //Rotazione Oraria + { + for (int i=0; i<numstep; i++) //45 gradi a ciclo + // for (int i=0; i<514; i++) //45 gradi a ciclo +// for (int i=0; i<1024; i++) //90 gradi a ciclo + { + EseguiPasso(stato); + stato=stato+1; // avanza nella tabella +/* printf("Stato : \r\n"); + printf("%d\r\n",stato); + printf("k : \r\n"); + printf("%d\r\n",k); + */ + if ((stato)>statomax) + { + stato=0; + // if ((stato)>7) stato=0; + } + EseguiPasso(MotoreOFF); + // wait_ms(500); // pausa di mezzo secondo + } + wait_ms(1000); // pausa di 1 secondo + } + for(int k=0; k<kmax; k++) //Rotazione AntiOraria +// for(int k=0; k<4; k++) //Rotazione AntiOraria + { + for (int i=0; i<numstep; i++) //45 gradi a ciclo +// for (int i=0; i<514; i++) //45 gradi a ciclo +// for (int i=0; i<1024; i++) //90 gradi a ciclo + { + EseguiPasso(stato); + stato=stato-1; //torna indietro nella tabella + /* printf("Stato : \r\n"); + printf("%d\r\n",stato); + printf("k : \r\n"); + printf("%d\r\n",k); + */ + if ((stato)<0) + { + stato=statomax; + // if ((stato)<0) stato=7; + } + EseguiPasso(MotoreOFF); + // wait_ms(500); } - } + wait_ms(1000); } -} \ No newline at end of file + } + +} +}
diff -r 6999a083fb46 -r b974ec8fe646 mbed.bld --- a/mbed.bld Thu Jun 14 12:18:18 2012 +0000 +++ b/mbed.bld Wed Mar 11 15:12:13 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479 +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
diff -r 6999a083fb46 -r b974ec8fe646 sMotor.lib --- a/sMotor.lib Thu Jun 14 12:18:18 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3