new

Dependencies:   mbed CANMsg

Revision:
12:5bfbccfb3cf4
Parent:
11:21e990eb31d0
Child:
13:0ae23132a2b6
--- a/main.cpp	Thu Dec 27 15:54:22 2018 +0000
+++ b/main.cpp	Sat Dec 29 08:07:25 2018 +0000
@@ -3,14 +3,14 @@
 //********************************************************************************************************************
 // FIRMWARE SEMINATRICE MODULA
 // VERSIONE PER SCHEDA DI CONTROLLO CON DRIVER INTEGRATI
-// V4 - ATTENZIONE - LA VERSIONE V4 HA IL DRIVER STEPPER LV8727
+// V5 - ATTENZIONE - LA VERSIONE V5 HA IL DRIVER STEPPER LV8727
 // IL MOTORE DC E' GESTITO CON IL DRIVER VNH3SP30-E E CON LA LETTURA
 // DELLA CORRENTE ASSORBITA TRAMITE IL CONVERTITORE MLX91210-CAS102 CON 50A FONDOSCALA
 // CHE FORNISCE UNA TENSIONE DI USCITA PARI A 40mV/A
 // FIRST RELEASE OF BOARD DEC 2017
 // FIRST RELEASE OF FIRMWARE JAN 2018
 //
-// THIS RELEASE: 09 JULY 2018
+// THIS RELEASE: 29 DECEMBER 2018
 //
 // APPLICATION: MODULA CON DISTRIBUTORE ZUCCA OPPURE RISO E PUO' FUNZIONARE ANCHE CON SENSORE A 25 FORI SUL DISCO O 
 //              ENCODER MOTORE SETTANDO GLI APPOSITI FLAGS
@@ -23,8 +23,13 @@
 // 05 06 2018 - INSERITO IL CONTROLLO DI GESTIONE DEL QUINCONCE SENZA ENCODER
 // 09 06 2018 - INSERITO CONTROLLO DI FASE CON ENCODER MASTER PER QUINCONCE - DATO SCAMBIATO IN CAN
 //
+// 28 12 2018 - RISOLTO UN BUG CHE BLOCCAVA IL TAMBURO IN TRANSIZIONE TRA LOWSPEED E CICLO NORMALE DATO DAL CALCOLO DEL LIMITE
+//              DI CLOCK DEL GENERATORE DI IMPULSI DEL TAMBURO
+//              IN QUESTA VERSIONE E' STATO RIALLINEATO ANCHE LA CONFIGURAZIONE DELLO STEPPER CHE PERO' RISPETTO ALLA PRECEDENTE 
+//              VERSIONE, SEMBRA CHE PRIMA IL DRIVER FOSSE IMPOSTATO A 2000 STEP/GIRO INVECE CHE 1600. IMPOSTANDOLO CORRETTAMENTE
+//              PERO' IL TAMBURO NON SI SINCRONIZZA E VA TROPPO VELOCE RISPETTO A QUANTO RICHIESTO. DA VERIFICARE PERCHE'!
 /********************
-IL FIRMWARE SI COMPONE DI 7 FILES:
+IL FIRMWARE SI COMPONE DI 9 FILES:
     - main.cpp
     - main.hpp
     - iodefinition.hpp
@@ -32,7 +37,9 @@
     - parameters.hpp
     - timeandtick.hpp
     - variables.hpp
-ED UTILIZZA LE LIBRERIE STANDARD MBED PIU' UNA LIBRERIA MODIFICATA E DEDICATA PER IL CAN
+    - watchdog.cpp
+    - watchdog.h
+ED UTILIZZA LE LIBRERIE STANDARD MBED, UNA LIBRERIA PER IL WATCHDOG ED UNA LIBRERIA MODIFICATA E DEDICATA PER IL CAN
 *********************
 LA MACCHINA UTILIZZA SEMPRE 2 SOLI SENSORI; UNO PER SENTIRE LE CELLE DI CARICO SEME ED UNO PER SENTIRE I BECCHI DI SEMINA.
 GLI AZIONAMENTI SONO COMPOSTI DA DUE MOTORI; UN DC PER IL CONTROLLO DELLA RUOTA DI SEMINA ED UNO STEPPER PER IL CONTROLLO DEL TAMBURO
@@ -168,11 +175,14 @@
 void step_TBPulseOut(){
     TBmotorStepOut=!TBmotorStepOut;
     if (TBmotorStepOut==0){
-        if (TBmotorDirecti==1){
-            TBactualPosition++;
-        }else{
-            TBactualPosition--;
-        }
+        TBactualPosition++;
+    }
+}
+void inverti(){
+    if (TBmotorDirecti==0){
+        TBmotorDirecti=1;
+    }else{
+        TBmotorDirecti=0;
     }
 }
 //*******************************************************
@@ -320,9 +330,55 @@
 void stepSetting(){
     // Stepper driver init and set
     TBmotorRst=1;                               // reset stepper driver
-    if (tractorSpeed_MtS_timed==0.0f){
-        TBmotorDirecti=1;                           // reset stepper direction
+    TBmotorDirecti=1;                           // reset stepper direction
+    // M1   M2  M3  RESOLUTION
+    // 0    0   0       1/2
+    // 1    0   0       1/8
+    // 0    1   0       1/16
+    // 1    1   0       1/32
+    // 0    0   1       1/64
+    // 1    0   1       1/128
+    // 0    1   1       1/10
+    // 1    1   1       1/20
+    if (TBmotorSteps==400){
+        TBmotor_M1=1;
+        TBmotor_M2=1;
+        TBmotor_M3=1;
+    }else if (TBmotorSteps==1600){
+        TBmotor_M1=0;
+        TBmotor_M2=1;
+        TBmotor_M3=1;
+    }else if (TBmotorSteps==3200){
+        TBmotor_M1=1;
+        TBmotor_M2=0;
+        TBmotor_M3=1;
+    }else if (TBmotorSteps==6400){
+        TBmotor_M1=0;
+        TBmotor_M2=0;
+        TBmotor_M3=1;
+    }else if (TBmotorSteps==12800){
+        TBmotor_M1=1;
+        TBmotor_M2=1;
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==25600){
+        TBmotor_M1=0;
+        TBmotor_M2=1;
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==2000){
+        TBmotor_M1=1;
+        TBmotor_M2=0;
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==4000){
+        TBmotor_M1=0;
+        TBmotor_M2=0;
+        TBmotor_M3=0;
     }
+    TBmotorRst=0;
+}
+/*void stepSetting(){
+    // Stepper driver init and set
+    TBmotorRst=1;                               // reset stepper driver
+    TBmotorDirecti=1;                           // reset stepper direction
     // M1   M2  M3  RESOLUTION
     // 0    0   0       1/2
     // 1    0   0       1/8
@@ -372,6 +428,7 @@
     }
     TBmotorRst=0;
 }
+*/
 //****************************************
 void dcSetting(){
         if ((speedFromPick==0)&&(encoder==false)){
@@ -729,8 +786,8 @@
                 uint8_t flags = rxMsg.data[0];
                 uint16_t steps = (uint32_t) rxMsg.data[1]*0x000000FF;
                 steps = steps + ((uint32_t)rxMsg.data[2]);
-                TBmotorSteps =steps;
-                //stepSetting();
+                //TBmotorSteps =steps;
+                stepSetting();
                 cellsCountSet = rxMsg.data[3];
                 if ((flags&0x01)==0x01){
                     if (encoder==false){
@@ -1101,6 +1158,7 @@
     #if defined(provaStepper)
        TBmotorRst=0;
        TBticker.attach_us(&step_TBPulseOut,500.0f);  // clock time are seconds and attach seed motor stepper controls
+       TBpTicker.attach(&inverti,0.5f);
     #endif // end prova stepper
     
     #if defined(canbusActive)
@@ -1723,12 +1781,6 @@
                             lockStart=1;
                             periodo = TBperiod;
                             if (aspettaStart==0){cambiaTB(periodo);}
-                            #if defined(pcSerial)
-                                #if defined(inCorre)
-                                    pc.printf("entrato \n");
-                                    pc.printf("Aspetta %d \n",aspettaStart);
-                                #endif
-                            #endif
                         }
                         // controllo di stop
                         double memoIntraP = (double)memoIntraPick*1.8f;