Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
main.cpp
00001 /* ------------------------ INCLUDE ----------------------------------------- */ 00002 #include "SETUP.h" 00003 00004 /* ---------------------------- END ----------------------------------------- */ 00005 00006 00007 /* Zum testen */ 00008 DigitalOut myled(LED1); 00009 DigitalIn mybutton(USER_BUTTON); 00010 00011 00012 00013 /* ----------------------- INITIALISIERUNG ---------------------------------- */ 00014 /* -------------------------------------------------------------------------- */ 00015 00016 /* Status Spleisser definieren*/ 00017 int StatusSpleisser = ST_SOLO; 00018 00019 extern int StatusDUO; 00020 extern int StatusSOLO; 00021 00022 00023 /*Buttons initialisieren*/ 00024 00025 //InterruptIn buttonSTART(START_BUTTON); 00026 DigitalIn Button1(START_BUTTON); 00027 volatile bool buttonSTART_pressed = false; // Used in the main loop 00028 volatile bool buttonSTART_enabled = true; // Used for debouncing 00029 Timeout buttonSTART_timeout; // Used for debouncing 00030 00031 //InterruptIn buttonAbbruch(ABBRUCH_BUTTON); 00032 DigitalIn Button2(ABBRUCH_BUTTON); 00033 volatile bool buttonAbbruch_pressed = false; // Used in the main loop 00034 volatile bool buttonAbbruch_enabled = true; // Used for debouncing 00035 Timeout buttonAbbruch_timeout; // Used for debouncing 00036 00037 00038 /*PWMs initialisieren*/ 00039 PwmOut Servo (SERVO_PWM); 00040 PwmOut Cutter_1 (CUTTER_ARC_1); 00041 PwmOut Cutter_2 (CUTTER_ARC_2); 00042 PwmOut Spleisser_1 (SPLEISSER_ARC_1); 00043 PwmOut Spleisser_2 (SPLEISSER_ARC_2); 00044 00045 /*Lichtschranken*/ 00046 DigitalIn LS_1(LICHTSCHRANKE_1); // HIGH - kein Filament / LOW - Filament 00047 DigitalIn LS_2(LICHTSCHRANKE_2); // HIGH - kein Filament / LOW - Filament /* Mit LS_x.read(); auslesen */ 00048 DigitalIn LS_3(LICHTSCHRANKE_3); // HIGH - kein Filament / LOW - Filament 00049 00050 /*Input initalisieren für Status Spleisser*/ 00051 DigitalIn InputKontrollmodul(COM_SIGNAL); 00052 int val_InputKontrollmodul = 0; 00053 00054 DigitalIn CutSignal(CUT_SIGNAL); 00055 DigitalIn FertigSignal(FERTIG_SIGNAL); 00056 00057 00058 /* Motor Control Expansion Board. */ 00059 XNucleoIHM02A1 *x_nucleo_ihm02a1_1; 00060 XNucleoIHM02A12 *x_nucleo_ihm02a1_2; 00061 00062 /* Initialization parameters of the motors connected to the expansion board. */ 00063 L6470_init_t init[L6470DAISYCHAINSIZE] = { 00064 /* First Motor. */ 00065 { 00066 12.0, /* Motor supply voltage in V. */ 00067 400, /* Min number of steps per revolution for the motor. */ 00068 1.7, /* Max motor phase voltage in A. */ 00069 3.06, /* Max motor phase voltage in V. */ 00070 300.0, /* Motor initial speed [step/s]. */ 00071 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ 00072 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ 00073 992.0, /* Motor maximum speed [step/s]. */ 00074 0.0, /* Motor minimum speed [step/s]. */ 00075 602.7, /* Motor full-step speed threshold [step/s]. */ 00076 3.06, /* Holding kval [V]. */ 00077 3.06, /* Constant speed kval [V]. */ 00078 3.06, /* Acceleration starting kval [V]. */ 00079 3.06, /* Deceleration starting kval [V]. */ 00080 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ 00081 392.1569e-6, /* Start slope [s/step]. */ 00082 643.1372e-6, /* Acceleration final slope [s/step]. */ 00083 643.1372e-6, /* Deceleration final slope [s/step]. */ 00084 0, /* Thermal compensation factor (range [0, 15]). */ 00085 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ 00086 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ 00087 StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ 00088 0xFF, /* Alarm conditions enable. */ 00089 0x2E88 /* Ic configuration. */ 00090 }, 00091 00092 /* Second Motor. */ 00093 { 00094 12.0, /* Motor supply voltage in V. */ 00095 400, /* Min number of steps per revolution for the motor. */ 00096 1.7, /* Max motor phase voltage in A. */ 00097 3.06, /* Max motor phase voltage in V. */ 00098 300.0, /* Motor initial speed [step/s]. */ 00099 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ 00100 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ 00101 992.0, /* Motor maximum speed [step/s]. */ 00102 0.0, /* Motor minimum speed [step/s]. */ 00103 602.7, /* Motor full-step speed threshold [step/s]. */ 00104 3.06, /* Holding kval [V]. */ 00105 3.06, /* Constant speed kval [V]. */ 00106 3.06, /* Acceleration starting kval [V]. */ 00107 3.06, /* Deceleration starting kval [V]. */ 00108 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ 00109 392.1569e-6, /* Start slope [s/step]. */ 00110 643.1372e-6, /* Acceleration final slope [s/step]. */ 00111 643.1372e-6, /* Deceleration final slope [s/step]. */ 00112 0, /* Thermal compensation factor (range [0, 15]). */ 00113 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ 00114 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ 00115 StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ 00116 0xFF, /* Alarm conditions enable. */ 00117 0x2E88 /* Ic configuration. */ 00118 } 00119 }; 00120 00121 /* Motor Objekte */ 00122 L6470B **motors2; 00123 L6470 **motors; 00124 00125 /* --------------------------------- END ------------------------------------ */ 00126 /* -------------------------------------------------------------------------- */ 00127 00128 00129 00130 00131 00132 00133 /* ------------------------------- BOOT SCREEN ------------------------------ */ 00134 void Boot_Screen() 00135 { 00136 00137 DisplaySendeBefehl(0x01); 00138 DisplaySendeBefehl(0x0C); 00139 gotoxy(1, 1); 00140 DisplaySendeString("BOOT:"); 00141 gotoxy(1, 3); 00142 DisplaySendeString("SPLEISSER FIRMWARE"); 00143 00144 gotoxy(1, 4); 00145 DisplaySendeString("[ 0% ]"); 00146 Thread::wait((BOOTTIME/14)*1000); 00147 gotoxy(1, 4); 00148 DisplaySendeString("[- 7% ]"); 00149 Thread::wait((BOOTTIME/14)*1000); 00150 gotoxy(1, 4); 00151 DisplaySendeString("[-- 14% ]"); 00152 Thread::wait((BOOTTIME/14)*1000); 00153 gotoxy(1, 4); 00154 DisplaySendeString("[--- 21% ]"); 00155 Thread::wait((BOOTTIME/14)*1000); 00156 gotoxy(1, 4); 00157 DisplaySendeString("[---- 28% ]"); 00158 Thread::wait((BOOTTIME/14)*1000); 00159 gotoxy(1, 4); 00160 DisplaySendeString("[----- 35% ]"); 00161 Thread::wait((BOOTTIME/14)*1000); 00162 gotoxy(1, 4); 00163 DisplaySendeString("[------ 42% ]"); 00164 Thread::wait((BOOTTIME/14)*1000); 00165 gotoxy(1, 4); 00166 DisplaySendeString("[-------49% ]"); 00167 Thread::wait((BOOTTIME/14)*1000); 00168 gotoxy(1, 4); 00169 DisplaySendeString("[-------56%- ]"); 00170 Thread::wait((BOOTTIME/14)*1000); 00171 gotoxy(1, 4); 00172 DisplaySendeString("[-------63%-- ]"); 00173 Thread::wait((BOOTTIME/14)*1000); 00174 gotoxy(1, 4); 00175 DisplaySendeString("[-------70%--- ]"); 00176 Thread::wait((BOOTTIME/14)*1000); 00177 gotoxy(1, 4); 00178 DisplaySendeString("[-------77%---- ]"); 00179 Thread::wait((BOOTTIME/14)*1000); 00180 gotoxy(1, 4); 00181 DisplaySendeString("[-------84%----- ]"); 00182 Thread::wait((BOOTTIME/14)*1000); 00183 gotoxy(1, 4); 00184 DisplaySendeString("[-------91%------ ]"); 00185 Thread::wait((BOOTTIME/14)*1000); 00186 gotoxy(1, 4); 00187 DisplaySendeString("[-------98%------- ]"); 00188 Thread::wait((BOOTTIME/14)*1000); 00189 gotoxy(1, 4); 00190 DisplaySendeString("[-------100%-------]"); 00191 Thread::wait(500); 00192 } 00193 /* --------------------------------- END ------------------------------------ */ 00194 00195 00196 00197 00198 00199 00200 00201 /* ---------------------------------- MAIN ---------------------------------- */ 00202 /* -------------------------------------------------------------------------- */ 00203 00204 int main() 00205 { 00206 00207 /* Initializing Motor Control Expansion Board. */ 00208 x_nucleo_ihm02a1_1 = new XNucleoIHM02A1 (&init[0], &init[1], IRQ_FLAG_MOTOR, IRQ_BUSY_MOTOR, STB_MOTOR, SPI_CS_1, SPI_MOSI, SPI_MISO, SPI_CLK ); 00209 x_nucleo_ihm02a1_2 = new XNucleoIHM02A12(&init[0], &init[1], IRQ_FLAG_MOTOR, IRQ_BUSY_MOTOR, STB_MOTOR, SPI_CS_2, SPI_MOSI, SPI_MISO, SPI_CLK ); 00210 00211 /* Building a list of motor control components. */ 00212 motors2 = x_nucleo_ihm02a1_2->get_components(); 00213 motors = x_nucleo_ihm02a1_1->get_components(); 00214 00215 /* Attach ISR to handle button press event 00216 buttonSTART.fall(callback(buttonSTART_onpressed_cb)); 00217 buttonAbbruch.fall(callback(buttonAbbruch_onpressed_cb)); 00218 */ 00219 /* Init PWM */ 00220 Init_Servo(); 00221 Init_Cutter(); 00222 Init_Spleisser(); 00223 00224 /*Display*/ 00225 wait_ms(250); 00226 DisplayInit(); 00227 00228 00229 00230 Boot_Screen(); 00231 00232 00233 /* -------------------- ---- STATE_MACHINE ------------------------------ */ 00234 while(1) { 00235 val_InputKontrollmodul=InputKontrollmodul; 00236 // printf("%i",val_InputKontrollmodul); 00237 00238 //val_InputKontrollmodul = InputKontrollmodul.read(); 00239 switch (StatusSpleisser) { 00240 case ST_SOLO: 00241 if(InputKontrollmodul == 0) 00242 { 00243 EntrySOLO(); 00244 } 00245 else if(InputKontrollmodul == 1) 00246 { 00247 StatusDUO =DUO_DEFAULT; 00248 StatusSpleisser = ST_DUO; 00249 } 00250 break; 00251 case ST_DUO: 00252 if(InputKontrollmodul == 1) { 00253 00254 EntryDUO(); 00255 } 00256 else if (InputKontrollmodul == 0) 00257 { 00258 StatusSOLO =SOLO_DEFAULT; 00259 StatusSpleisser = ST_SOLO; 00260 } 00261 break; 00262 } 00263 00264 } 00265 /* ------------------------------ END ----------------------------------- */ 00266 00267 00268 00269 00270 } 00271 /* --------------------------------- END ------------------------------------ */ 00272 /* -------------------------------------------------------------------------- */
Generated on Mon Jul 25 2022 02:36:14 by
 1.7.2
 1.7.2