mit Buttons/PWM als einzelne cpp und init in main
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
main.cpp
- Committer:
- scherfa2
- Date:
- 2019-04-07
- Revision:
- 27:23bd03a6a6f6
- Parent:
- 26:caec5f51abe8
- Child:
- 30:e464b2bb2376
File content as of revision 27:23bd03a6a6f6:
/** ****************************************************************************** * @file main.cpp * @author Fabian Scherrer * @version V1.0.0 * @date April 7th, 2019 * @brief ****************************************************************************** * @attention * Verwendete I/O's: Input: * PA9 (InputKontrollmodul Pin von Kontroll-Modul)(CN5-1) * * Output: * PA10 (D2) (Select Steppmotor Treiber2) * PA7 (D11) (mosi Steppmotor Treiber1) * PA6 (D12) (miso Steppmotor Treiber1) * PA4 (A2) (Select Steppmotor Treiber1) * * PB15 (mosi Steppmotor Treiber2) * PB14 (miso Steppmotor Treiber2) * PB13 (slk Steppmotor Treiber2) * PB6 (D10)(pwm_io)(CN5-3) * PB5 (D4)(Standby_reset Steppmotor) * PB4 (D5)(pwm_io2)(CN9-6) * PB3 (D3)(Select Steppmotor Treiber1) * PC1 (A4)(Flag_irq Steppmotor) * PC0 (A5)(Busy_irq Steppmotor) ******************************************************************************/ /* Includes ------------------------------------------------------------------*/ /* mbed specific header files. */ #include "mbed.h" #include "main.h" #include "PWM.h" #include "ST_SOLO.h" #include "ST_DUO.h" /* Helper header files. */ #include "DevSPI.h" /* Expansion Board specific header files. */ #include "XNucleoIHM02A1.h" /* Definitions ---------------------------------------------------------------*/ /* Number of movements per revolution. */ #define MPR_1 4 /* Number of steps. */ #define STEPS_1 (400 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */ #define STEPS_2 (STEPS_1 * 2) /* Delay in milliseconds. */ #define DELAY_1 1000 #define DELAY_2 2000 #define DELAY_3 5000 /* Status Spleisser definieren*/ int StatusSpleisser = ST_SOLO; /*Input initalisieren für Status Spleisser*/ DigitalIn InputKontrollmodul(PA_9); InterruptIn button1(USER_BUTTON); volatile int idx = 0; volatile bool button1_pressed = false; // Used in the main loop volatile bool button1_enabled = true; // Used for debouncing Timeout button1_timeout; // Used for debouncing // Enables button when bouncing is over void button1_enabled_cb(void) { button1_enabled = true; } // ISR handling button pressed event void button1_onpressed_cb(void) { if (button1_enabled) { // Disabled while the button is bouncing button1_enabled = false; button1_pressed = true; // To be read by the main loop if(idx<4){ idx++; } else{idx=1;} button1_timeout.attach(callback(button1_enabled_cb), 0.03); // Debounce time 300 ms } } /* Variables -----------------------------------------------------------------*/ /* Motor Control Expansion Board. */ XNucleoIHM02A1 *x_nucleo_ihm02a1_1; XNucleoIHM02A12 *x_nucleo_ihm02a1_2; /* Initialization parameters of the motors connected to the expansion board. */ L6470_init_t init[L6470DAISYCHAINSIZE] = { /* First Motor. */ { 9.0, /* Motor supply voltage in V. */ 400, /* Min number of steps per revolution for the motor. */ 1.7, /* Max motor phase voltage in A. */ 3.06, /* Max motor phase voltage in V. */ 300.0, /* Motor initial speed [step/s]. */ 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ 992.0, /* Motor maximum speed [step/s]. */ 0.0, /* Motor minimum speed [step/s]. */ 602.7, /* Motor full-step speed threshold [step/s]. */ 3.06, /* Holding kval [V]. */ 3.06, /* Constant speed kval [V]. */ 3.06, /* Acceleration starting kval [V]. */ 3.06, /* Deceleration starting kval [V]. */ 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ 392.1569e-6, /* Start slope [s/step]. */ 643.1372e-6, /* Acceleration final slope [s/step]. */ 643.1372e-6, /* Deceleration final slope [s/step]. */ 0, /* Thermal compensation factor (range [0, 15]). */ 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ 0xFF, /* Alarm conditions enable. */ 0x2E88 /* Ic configuration. */ }, /* Second Motor. */ { 9.0, /* Motor supply voltage in V. */ 400, /* Min number of steps per revolution for the motor. */ 1.7, /* Max motor phase voltage in A. */ 3.06, /* Max motor phase voltage in V. */ 300.0, /* Motor initial speed [step/s]. */ 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */ 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */ 992.0, /* Motor maximum speed [step/s]. */ 0.0, /* Motor minimum speed [step/s]. */ 602.7, /* Motor full-step speed threshold [step/s]. */ 3.06, /* Holding kval [V]. */ 3.06, /* Constant speed kval [V]. */ 3.06, /* Acceleration starting kval [V]. */ 3.06, /* Deceleration starting kval [V]. */ 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */ 392.1569e-6, /* Start slope [s/step]. */ 643.1372e-6, /* Acceleration final slope [s/step]. */ 643.1372e-6, /* Deceleration final slope [s/step]. */ 0, /* Thermal compensation factor (range [0, 15]). */ 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */ 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */ StepperMotor::STEP_MODE_1_128, /* Step mode selection. */ 0xFF, /* Alarm conditions enable. */ 0x2E88 /* Ic configuration. */ } }; /* Main ----------------------------------------------------------------------*/ int main() { /*----- Initialization. -----*/ pwm_io2(20000, 0.075); /* Initializing Motor Control Expansion Board. */ x_nucleo_ihm02a1_2 = new XNucleoIHM02A12(&init[0], &init[1],A4, A5, D4, D2, PB_15, PB_14, PB_13 ); x_nucleo_ihm02a1_1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, D11, D12, D3 ); printf("--> bis hier gehts2.\r\n"); /* Building a list of motor control components. */ L6470B **motors2 = x_nucleo_ihm02a1_2->get_components(); L6470 **motors = x_nucleo_ihm02a1_1->get_components(); printf("--> bis hier gehts3.\r\n"); button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event while(1) { switch (StatusSpleisser) { case ST_SOLO: if(InputKontrollmodul ==0) { EntrySOLO(); } else { StatusSpleisser = ST_DUO; } break; case ST_DUO: if(InputKontrollmodul ==1) { EntryDUO(); } else { StatusSpleisser = ST_SOLO; } break; } } }