Forked to initiate the Current Loop Gain
Dependencies: mbed QEI DmTftLibraryEx
main.cpp@25:5fd2d69e2927, 2022-02-10 (annotated)
- Committer:
- lex9296
- Date:
- Thu Feb 10 13:19:59 2022 +0000
- Revision:
- 25:5fd2d69e2927
- Parent:
- 23:b9d23a2f390e
- Child:
- 26:bfca0c471a87
Working @full Int Speed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:9c0917bfde97 | 1 | |
lex9296 | 23:b9d23a2f390e | 2 | //Warning: Incompatible redefinition of macro "MBED_RAM_SIZE" in "tmp/HU5Hqj", Line: 39, Col: 10 |
lex9296 | 23:b9d23a2f390e | 3 | #ifndef MBED_RAM_SIZE |
lex9296 | 23:b9d23a2f390e | 4 | #define MBED_RAM_SIZE 0x00018000 |
lex9296 | 23:b9d23a2f390e | 5 | #endif |
lex9296 | 23:b9d23a2f390e | 6 | |
lex9296 | 23:b9d23a2f390e | 7 | //#include "mbed.h" |
lex9296 | 23:b9d23a2f390e | 8 | #include "QEI.h" |
lex9296 | 23:b9d23a2f390e | 9 | #include "SWPos.h" |
lex9296 | 23:b9d23a2f390e | 10 | |
GregCr | 0:9c0917bfde97 | 11 | #include "Timers.h" |
lex9296 | 23:b9d23a2f390e | 12 | //#include "Menu.h" |
GregCr | 0:9c0917bfde97 | 13 | #include "Eeprom.h" |
lex9296 | 23:b9d23a2f390e | 14 | //#include "main.h" |
lex9296 | 23:b9d23a2f390e | 15 | //#include "app_config.h" |
GregCr | 0:9c0917bfde97 | 16 | |
GregCr | 0:9c0917bfde97 | 17 | /*! |
GregCr | 0:9c0917bfde97 | 18 | * \brief Define IO for Unused Pin |
GregCr | 0:9c0917bfde97 | 19 | */ |
lex9296 | 23:b9d23a2f390e | 20 | //DigitalOut F_CS (D6); // MBED description of pin |
lex9296 | 23:b9d23a2f390e | 21 | //DigitalOut SD_CS (D8); // MBED description of pin |
lex9296 | 23:b9d23a2f390e | 22 | |
lex9296 | 23:b9d23a2f390e | 23 | DigitalIn userButton (USER_BUTTON); |
mverdy | 15:ed7ed20b7114 | 24 | |
lex9296 | 23:b9d23a2f390e | 25 | AnalogIn adc_temp (ADC_TEMP); |
lex9296 | 23:b9d23a2f390e | 26 | AnalogIn adc_vref (ADC_VREF); |
lex9296 | 23:b9d23a2f390e | 27 | AnalogIn adc_vbat (ADC_VBAT); |
GregCr | 0:9c0917bfde97 | 28 | |
lex9296 | 23:b9d23a2f390e | 29 | // PWM |
lex9296 | 23:b9d23a2f390e | 30 | // === |
lex9296 | 23:b9d23a2f390e | 31 | // |
lex9296 | 25:5fd2d69e2927 | 32 | PwmOut PWM_PB3(PWM_OUT); // LA: PWM_OUT = D3 = PB_3 |
mverdy | 14:ebd89dacc807 | 33 | |
lex9296 | 23:b9d23a2f390e | 34 | // Motion |
lex9296 | 23:b9d23a2f390e | 35 | // ====== |
lex9296 | 23:b9d23a2f390e | 36 | // |
lex9296 | 23:b9d23a2f390e | 37 | //Ticker POS_MotionScan; // |
mverdy | 15:ed7ed20b7114 | 38 | |
lex9296 | 23:b9d23a2f390e | 39 | QEI Stabilus322699 (PA_1, PA_0, NC, 100, QEI::X4_ENCODING); |
lex9296 | 23:b9d23a2f390e | 40 | // |
lex9296 | 23:b9d23a2f390e | 41 | in_sPosizionatoreSW in_PosizionatoreSW; |
lex9296 | 23:b9d23a2f390e | 42 | out_sPosizionatoreSW out_PosizionatoreSW; |
GregCr | 0:9c0917bfde97 | 43 | |
lex9296 | 23:b9d23a2f390e | 44 | // LCD Display |
lex9296 | 23:b9d23a2f390e | 45 | // =========== |
lex9296 | 23:b9d23a2f390e | 46 | // |
lex9296 | 23:b9d23a2f390e | 47 | //Ticker LCD_RefreshViews; // |
lex9296 | 23:b9d23a2f390e | 48 | |
lex9296 | 23:b9d23a2f390e | 49 | //extern void StabilusMenu (uint32_t, uint32_t, int64_t); // LA: Prototype ... |
mverdy | 15:ed7ed20b7114 | 50 | |
lex9296 | 22:12c555cade79 | 51 | void FactoryReset (void) { |
mverdy | 15:ed7ed20b7114 | 52 | EepromFactoryReset( ); |
mverdy | 15:ed7ed20b7114 | 53 | HAL_NVIC_SystemReset( ); |
mverdy | 15:ed7ed20b7114 | 54 | } |
lex9296 | 23:b9d23a2f390e | 55 | |
lex9296 | 23:b9d23a2f390e | 56 | /* |
lex9296 | 23:b9d23a2f390e | 57 | void LCD____tScan (void) { |
lex9296 | 23:b9d23a2f390e | 58 | // StabilusMenu (out_PosizionatoreSW.ui32_PreviousStep_ms, out_PosizionatoreSW.ui32_ActualStepSampled_ms, out_PosizionatoreSW.ui32_PassedActual_ms); |
lex9296 | 23:b9d23a2f390e | 59 | } |
lex9296 | 23:b9d23a2f390e | 60 | |
lex9296 | 23:b9d23a2f390e | 61 | |
lex9296 | 23:b9d23a2f390e | 62 | void Motion_tScan (void) { |
lex9296 | 23:b9d23a2f390e | 63 | PosizionatoreSW (in_PosizionatoreSW, out_PosizionatoreSW); |
lex9296 | 23:b9d23a2f390e | 64 | } |
lex9296 | 23:b9d23a2f390e | 65 | */ |
lex9296 | 23:b9d23a2f390e | 66 | |
lex9296 | 23:b9d23a2f390e | 67 | // ======= |
lex9296 | 23:b9d23a2f390e | 68 | // ======= |
lex9296 | 23:b9d23a2f390e | 69 | // Main(s) |
lex9296 | 23:b9d23a2f390e | 70 | // ======= |
lex9296 | 23:b9d23a2f390e | 71 | // ======= |
lex9296 | 23:b9d23a2f390e | 72 | // |
lex9296 | 23:b9d23a2f390e | 73 | int main (void){ |
lex9296 | 23:b9d23a2f390e | 74 | //int32_t i32_Pulses; |
lex9296 | 23:b9d23a2f390e | 75 | // F_CS = 1; // LA: HW Initialization InProgress |
lex9296 | 23:b9d23a2f390e | 76 | // SD_CS = 1; // LA: HW Initialization InProgress |
lex9296 | 23:b9d23a2f390e | 77 | // BoardLED3 = 1; |
lex9296 | 23:b9d23a2f390e | 78 | |
lex9296 | 23:b9d23a2f390e | 79 | EepromInit(); // LA: Inizializza la EEProm |
lex9296 | 23:b9d23a2f390e | 80 | TimersInit(); // LA: Parte il Timer a 1ms |
lex9296 | 23:b9d23a2f390e | 81 | |
lex9296 | 23:b9d23a2f390e | 82 | // LA: FactoryReset se "userButton" premuto all'avvio |
lex9296 | 23:b9d23a2f390e | 83 | // |
lex9296 | 23:b9d23a2f390e | 84 | if (userButton == 0) { |
lex9296 | 23:b9d23a2f390e | 85 | FactoryReset(); |
lex9296 | 23:b9d23a2f390e | 86 | } |
lex9296 | 23:b9d23a2f390e | 87 | |
lex9296 | 23:b9d23a2f390e | 88 | MenuInit(); // LA: Inizializza il Display |
lex9296 | 23:b9d23a2f390e | 89 | // LCD_RefreshViews.attach_us (&LCD____tScan, 250000); // Scansione LCD @100ms |
lex9296 | 23:b9d23a2f390e | 90 | |
lex9296 | 23:b9d23a2f390e | 91 | // LA: Motion (1st) Setup |
lex9296 | 23:b9d23a2f390e | 92 | // |
lex9296 | 23:b9d23a2f390e | 93 | in_PosizionatoreSW.b_AxisPowered = false; |
lex9296 | 23:b9d23a2f390e | 94 | in_PosizionatoreSW.b_ACPos_Homed = false; |
lex9296 | 23:b9d23a2f390e | 95 | in_PosizionatoreSW.i32_Max_Speed = 1024; // [ui] |
lex9296 | 23:b9d23a2f390e | 96 | in_PosizionatoreSW.i32_ZeroSpeed = 0; // |
lex9296 | 23:b9d23a2f390e | 97 | |
lex9296 | 23:b9d23a2f390e | 98 | in_PosizionatoreSW.b_JogMode = false; |
lex9296 | 23:b9d23a2f390e | 99 | in_PosizionatoreSW.b_JogFW = false; |
lex9296 | 23:b9d23a2f390e | 100 | in_PosizionatoreSW.b_JogBW = false; |
lex9296 | 23:b9d23a2f390e | 101 | in_PosizionatoreSW.i32_JogAccel_ms = 500; // [ms] |
lex9296 | 23:b9d23a2f390e | 102 | in_PosizionatoreSW.i32_JogDecel_ms = 250; // |
lex9296 | 23:b9d23a2f390e | 103 | // |
lex9296 | 23:b9d23a2f390e | 104 | in_PosizionatoreSW.f_JogSpeed_x100_FW = 25.0; // % of "i32_Max_Speed" |
lex9296 | 23:b9d23a2f390e | 105 | in_PosizionatoreSW.f_JogSpeed_x100_BW = 25.0; // |
lex9296 | 23:b9d23a2f390e | 106 | |
lex9296 | 23:b9d23a2f390e | 107 | in_PosizionatoreSW.b_ServoLock = false; |
lex9296 | 23:b9d23a2f390e | 108 | in_PosizionatoreSW.rtServoLock_Q = false; |
lex9296 | 23:b9d23a2f390e | 109 | // |
lex9296 | 23:b9d23a2f390e | 110 | in_PosizionatoreSW.i64_TargetPosition = 0; // [ui] |
lex9296 | 23:b9d23a2f390e | 111 | in_PosizionatoreSW.i64_ActualPosition = 0; // |
lex9296 | 23:b9d23a2f390e | 112 | in_PosizionatoreSW.i64_AccelerationWindow = 0; // LA: Spazio concesso all'accelerazione. |
lex9296 | 23:b9d23a2f390e | 113 | in_PosizionatoreSW.i64_DecelerationWindow = 0; // Spazio concesso alla decelerazione, è prioritario rispetto all'accelerazione. |
lex9296 | 23:b9d23a2f390e | 114 | in_PosizionatoreSW.i64_diToleranceWindow = 0; // Finestra di Tolleranza |
lex9296 | 23:b9d23a2f390e | 115 | // |
lex9296 | 23:b9d23a2f390e | 116 | in_PosizionatoreSW.f_MaximumSpeed_x100_FW = 25.0; // % of "i32_Max_Speed" |
lex9296 | 23:b9d23a2f390e | 117 | in_PosizionatoreSW.f_MaximumSpeed_x100_BW = 25.0; // |
lex9296 | 23:b9d23a2f390e | 118 | in_PosizionatoreSW.f_ServoLockSpeed_x100_FW = 5.0; // |
lex9296 | 23:b9d23a2f390e | 119 | in_PosizionatoreSW.f_ServoLockSpeed_x100_BW = 5.0; // |
lex9296 | 23:b9d23a2f390e | 120 | |
lex9296 | 23:b9d23a2f390e | 121 | // POS_MotionScan.attach_us (&Motion_tScan, 2000); // LA: Scansione Motion @2ms |
lex9296 | 23:b9d23a2f390e | 122 | |
lex9296 | 23:b9d23a2f390e | 123 | // PWM_SetOut.attach_us (&PWM____tScan, 100); // Scansione base PWM @100us Ok |
lex9296 | 23:b9d23a2f390e | 124 | // PWM_SetOut.attach_us (&PWM____tScan, 50); // Scansione base PWM @50us Ok |
lex9296 | 23:b9d23a2f390e | 125 | // PWM_SetOut.attach_us (&PWM____tScan, 30); // Scansione base PWM @30us Ok |
lex9296 | 23:b9d23a2f390e | 126 | // PWM_SetOut.attach_us (&PWM____tScan, 25); // Scansione base PWM @25us No (al pelo ...) |
lex9296 | 23:b9d23a2f390e | 127 | // PWM_SetOut.attach_us (&PWM____tScan, 10); // Scansione base PWM @10us No (al pelo ...) |
lex9296 | 23:b9d23a2f390e | 128 | // PWM_SetOut.attach_us (&PWM____tScan, 20); // Scansione base PWM @20us No |
lex9296 | 23:b9d23a2f390e | 129 | |
lex9296 | 23:b9d23a2f390e | 130 | // PWM_SetOut.attach_us (&PWM____tScan, 40); // Scansione base PWM @40us, Duty Cycle 4ms, 0- 100% |
lex9296 | 23:b9d23a2f390e | 131 | // PWM_SetOut.attach_us (&PWM____tScan, 100); // Scansione base PWM @40us, Duty Cycle 5ms, 0- 100% |
lex9296 | 23:b9d23a2f390e | 132 | |
lex9296 | 25:5fd2d69e2927 | 133 | PWM_PB3.period_us(100); // LA: TimeBase is 100us |
lex9296 | 25:5fd2d69e2927 | 134 | PWM_PB3.pulsewidth_us(50); // 0.. 100us -> 0.. 100% |
lex9296 | 23:b9d23a2f390e | 135 | |
lex9296 | 23:b9d23a2f390e | 136 | while (1) { |
lex9296 | 23:b9d23a2f390e | 137 | // int32_t i32_Pulses; |
lex9296 | 23:b9d23a2f390e | 138 | // i32_Pulses = Stabilus322699.getPulses(); |
lex9296 | 23:b9d23a2f390e | 139 | |
lex9296 | 25:5fd2d69e2927 | 140 | PosizionatoreSW (in_PosizionatoreSW, out_PosizionatoreSW); |
lex9296 | 25:5fd2d69e2927 | 141 | |
lex9296 | 23:b9d23a2f390e | 142 | // LA: Wedge 4 LCDRefresh |
lex9296 | 23:b9d23a2f390e | 143 | StabilusMenu (out_PosizionatoreSW.ui32_PreviousStep_ms, out_PosizionatoreSW.ui32_ActualStepSampled_ms, out_PosizionatoreSW.ui32_PassedActual_ms, Stabilus322699.getPulses()); |
lex9296 | 23:b9d23a2f390e | 144 | // StabilusMenu (0, 1, 2, i32_Pulses); |
lex9296 | 23:b9d23a2f390e | 145 | // StabilusMenu (0, 1, i32_Pulses); |
lex9296 | 23:b9d23a2f390e | 146 | // StabilusMenu (0, 0, 0); // i32_Pulses); |
lex9296 | 23:b9d23a2f390e | 147 | // StabilusMenu (); // i32_Pulses); |
lex9296 | 23:b9d23a2f390e | 148 | // StabilusMenu (1); // i32_Pulses); |
lex9296 | 23:b9d23a2f390e | 149 | |
lex9296 | 25:5fd2d69e2927 | 150 | |
lex9296 | 23:b9d23a2f390e | 151 | /* |
lex9296 | 23:b9d23a2f390e | 152 | PWM_PB3 = PWM_PB3+ (float)0.01; |
lex9296 | 25:5fd2d69e2927 | 153 | // wait_ms(10); |
lex9296 | 23:b9d23a2f390e | 154 | if (PWM_PB3 >= (float)1.0) |
lex9296 | 23:b9d23a2f390e | 155 | PWM_PB3 = 0; |
lex9296 | 23:b9d23a2f390e | 156 | */ |
lex9296 | 25:5fd2d69e2927 | 157 | |
lex9296 | 23:b9d23a2f390e | 158 | } |
lex9296 | 23:b9d23a2f390e | 159 | } |
lex9296 | 23:b9d23a2f390e | 160 | |
lex9296 | 23:b9d23a2f390e | 161 | |
lex9296 | 23:b9d23a2f390e | 162 | /* |
lex9296 | 23:b9d23a2f390e | 163 | bool PWM_0000 (uint32_t ui32_Duty_x100) { |
lex9296 | 23:b9d23a2f390e | 164 | static uint32_t ui32_PWM_Base; |
lex9296 | 23:b9d23a2f390e | 165 | |
lex9296 | 23:b9d23a2f390e | 166 | if (ui32_PWM_Base >= 100) |
lex9296 | 23:b9d23a2f390e | 167 | ui32_PWM_Base = 0; |
lex9296 | 23:b9d23a2f390e | 168 | else |
lex9296 | 23:b9d23a2f390e | 169 | ui32_PWM_Base ++; |
lex9296 | 23:b9d23a2f390e | 170 | |
lex9296 | 23:b9d23a2f390e | 171 | if ( |
lex9296 | 23:b9d23a2f390e | 172 | (ui32_Duty_x100 > 0) && |
lex9296 | 23:b9d23a2f390e | 173 | (ui32_Duty_x100 <= 100) && |
lex9296 | 23:b9d23a2f390e | 174 | (ui32_PWM_Base <= ui32_Duty_x100) |
lex9296 | 23:b9d23a2f390e | 175 | ) |
lex9296 | 23:b9d23a2f390e | 176 | return (true); |
lex9296 | 23:b9d23a2f390e | 177 | else |
lex9296 | 23:b9d23a2f390e | 178 | return (false); |
lex9296 | 23:b9d23a2f390e | 179 | } |
lex9296 | 23:b9d23a2f390e | 180 | |
lex9296 | 23:b9d23a2f390e | 181 | void PWM____tScan (void) { |
lex9296 | 23:b9d23a2f390e | 182 | PWM = PWM_0000 (50); |
lex9296 | 23:b9d23a2f390e | 183 | } |
lex9296 | 23:b9d23a2f390e | 184 | */ |