All the previous but the PID

Dependencies:   mbed QEI PID DmTftLibraryEx

Committer:
lex9296
Date:
Thu Feb 10 13:46:17 2022 +0000
Revision:
26:bfca0c471a87
Parent:
25:5fd2d69e2927
Child:
27:654100855f5c
Last Commitment of LA0005 Fork

Who changed what in which revision?

UserRevisionLine numberNew 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
lex9296 26:bfca0c471a87 17 // LA: Theory of Operation
lex9296 26:bfca0c471a87 18 // ===================
lex9296 26:bfca0c471a87 19 //
lex9296 26:bfca0c471a87 20 // Il PWM funziona da sè in Interrupt
lex9296 26:bfca0c471a87 21 // Il QEI funziona da sè in Interrupt
lex9296 26:bfca0c471a87 22 // Se si creano dei Ticker (Che sono a loro volta interrupt(s)) è possibile che PWM e QEI perdano correlazione con l'HW.
lex9296 26:bfca0c471a87 23 //
lex9296 26:bfca0c471a87 24 // PQM
lex9296 26:bfca0c471a87 25 //
lex9296 26:bfca0c471a87 26 // Il rinfresco del Display e la gestione del motion vanno fatte il più frequentemente possibile ma fuori dal loop dei Ticker.
lex9296 26:bfca0c471a87 27 // Con qst versione (LA0005, che termina un FORK (il successivo è LA0010) quanto detto sopra è FUNZIONANTE.
lex9296 26:bfca0c471a87 28 // Questo messaggio è incluso nel "commitment"
lex9296 26:bfca0c471a87 29
GregCr 0:9c0917bfde97 30 /*!
GregCr 0:9c0917bfde97 31 * \brief Define IO for Unused Pin
GregCr 0:9c0917bfde97 32 */
lex9296 23:b9d23a2f390e 33 //DigitalOut F_CS (D6); // MBED description of pin
lex9296 23:b9d23a2f390e 34 //DigitalOut SD_CS (D8); // MBED description of pin
lex9296 23:b9d23a2f390e 35
lex9296 23:b9d23a2f390e 36 DigitalIn userButton (USER_BUTTON);
mverdy 15:ed7ed20b7114 37
lex9296 23:b9d23a2f390e 38 AnalogIn adc_temp (ADC_TEMP);
lex9296 23:b9d23a2f390e 39 AnalogIn adc_vref (ADC_VREF);
lex9296 23:b9d23a2f390e 40 AnalogIn adc_vbat (ADC_VBAT);
GregCr 0:9c0917bfde97 41
lex9296 23:b9d23a2f390e 42 // PWM
lex9296 23:b9d23a2f390e 43 // ===
lex9296 23:b9d23a2f390e 44 //
lex9296 25:5fd2d69e2927 45 PwmOut PWM_PB3(PWM_OUT); // LA: PWM_OUT = D3 = PB_3
mverdy 14:ebd89dacc807 46
lex9296 23:b9d23a2f390e 47 // Motion
lex9296 23:b9d23a2f390e 48 // ======
lex9296 23:b9d23a2f390e 49 //
lex9296 23:b9d23a2f390e 50 //Ticker POS_MotionScan; //
mverdy 15:ed7ed20b7114 51
lex9296 23:b9d23a2f390e 52 QEI Stabilus322699 (PA_1, PA_0, NC, 100, QEI::X4_ENCODING);
lex9296 23:b9d23a2f390e 53 //
lex9296 23:b9d23a2f390e 54 in_sPosizionatoreSW in_PosizionatoreSW;
lex9296 23:b9d23a2f390e 55 out_sPosizionatoreSW out_PosizionatoreSW;
GregCr 0:9c0917bfde97 56
lex9296 23:b9d23a2f390e 57 // LCD Display
lex9296 23:b9d23a2f390e 58 // ===========
lex9296 23:b9d23a2f390e 59 //
lex9296 23:b9d23a2f390e 60 //Ticker LCD_RefreshViews; //
lex9296 23:b9d23a2f390e 61
lex9296 23:b9d23a2f390e 62 //extern void StabilusMenu (uint32_t, uint32_t, int64_t); // LA: Prototype ...
mverdy 15:ed7ed20b7114 63
lex9296 22:12c555cade79 64 void FactoryReset (void) {
mverdy 15:ed7ed20b7114 65 EepromFactoryReset( );
mverdy 15:ed7ed20b7114 66 HAL_NVIC_SystemReset( );
mverdy 15:ed7ed20b7114 67 }
lex9296 23:b9d23a2f390e 68
lex9296 23:b9d23a2f390e 69 /*
lex9296 23:b9d23a2f390e 70 void LCD____tScan (void) {
lex9296 23:b9d23a2f390e 71 // StabilusMenu (out_PosizionatoreSW.ui32_PreviousStep_ms, out_PosizionatoreSW.ui32_ActualStepSampled_ms, out_PosizionatoreSW.ui32_PassedActual_ms);
lex9296 23:b9d23a2f390e 72 }
lex9296 23:b9d23a2f390e 73
lex9296 23:b9d23a2f390e 74
lex9296 23:b9d23a2f390e 75 void Motion_tScan (void) {
lex9296 23:b9d23a2f390e 76 PosizionatoreSW (in_PosizionatoreSW, out_PosizionatoreSW);
lex9296 23:b9d23a2f390e 77 }
lex9296 23:b9d23a2f390e 78 */
lex9296 23:b9d23a2f390e 79
lex9296 23:b9d23a2f390e 80 // =======
lex9296 23:b9d23a2f390e 81 // =======
lex9296 23:b9d23a2f390e 82 // Main(s)
lex9296 23:b9d23a2f390e 83 // =======
lex9296 23:b9d23a2f390e 84 // =======
lex9296 23:b9d23a2f390e 85 //
lex9296 23:b9d23a2f390e 86 int main (void){
lex9296 23:b9d23a2f390e 87 //int32_t i32_Pulses;
lex9296 23:b9d23a2f390e 88 // F_CS = 1; // LA: HW Initialization InProgress
lex9296 23:b9d23a2f390e 89 // SD_CS = 1; // LA: HW Initialization InProgress
lex9296 23:b9d23a2f390e 90 // BoardLED3 = 1;
lex9296 23:b9d23a2f390e 91
lex9296 23:b9d23a2f390e 92 EepromInit(); // LA: Inizializza la EEProm
lex9296 23:b9d23a2f390e 93 TimersInit(); // LA: Parte il Timer a 1ms
lex9296 23:b9d23a2f390e 94
lex9296 23:b9d23a2f390e 95 // LA: FactoryReset se "userButton" premuto all'avvio
lex9296 23:b9d23a2f390e 96 //
lex9296 23:b9d23a2f390e 97 if (userButton == 0) {
lex9296 23:b9d23a2f390e 98 FactoryReset();
lex9296 23:b9d23a2f390e 99 }
lex9296 23:b9d23a2f390e 100
lex9296 23:b9d23a2f390e 101 MenuInit(); // LA: Inizializza il Display
lex9296 23:b9d23a2f390e 102 // LCD_RefreshViews.attach_us (&LCD____tScan, 250000); // Scansione LCD @100ms
lex9296 23:b9d23a2f390e 103
lex9296 23:b9d23a2f390e 104 // LA: Motion (1st) Setup
lex9296 23:b9d23a2f390e 105 //
lex9296 23:b9d23a2f390e 106 in_PosizionatoreSW.b_AxisPowered = false;
lex9296 23:b9d23a2f390e 107 in_PosizionatoreSW.b_ACPos_Homed = false;
lex9296 23:b9d23a2f390e 108 in_PosizionatoreSW.i32_Max_Speed = 1024; // [ui]
lex9296 23:b9d23a2f390e 109 in_PosizionatoreSW.i32_ZeroSpeed = 0; //
lex9296 23:b9d23a2f390e 110
lex9296 23:b9d23a2f390e 111 in_PosizionatoreSW.b_JogMode = false;
lex9296 23:b9d23a2f390e 112 in_PosizionatoreSW.b_JogFW = false;
lex9296 23:b9d23a2f390e 113 in_PosizionatoreSW.b_JogBW = false;
lex9296 23:b9d23a2f390e 114 in_PosizionatoreSW.i32_JogAccel_ms = 500; // [ms]
lex9296 23:b9d23a2f390e 115 in_PosizionatoreSW.i32_JogDecel_ms = 250; //
lex9296 23:b9d23a2f390e 116 //
lex9296 23:b9d23a2f390e 117 in_PosizionatoreSW.f_JogSpeed_x100_FW = 25.0; // % of "i32_Max_Speed"
lex9296 23:b9d23a2f390e 118 in_PosizionatoreSW.f_JogSpeed_x100_BW = 25.0; //
lex9296 23:b9d23a2f390e 119
lex9296 23:b9d23a2f390e 120 in_PosizionatoreSW.b_ServoLock = false;
lex9296 23:b9d23a2f390e 121 in_PosizionatoreSW.rtServoLock_Q = false;
lex9296 23:b9d23a2f390e 122 //
lex9296 23:b9d23a2f390e 123 in_PosizionatoreSW.i64_TargetPosition = 0; // [ui]
lex9296 23:b9d23a2f390e 124 in_PosizionatoreSW.i64_ActualPosition = 0; //
lex9296 23:b9d23a2f390e 125 in_PosizionatoreSW.i64_AccelerationWindow = 0; // LA: Spazio concesso all'accelerazione.
lex9296 23:b9d23a2f390e 126 in_PosizionatoreSW.i64_DecelerationWindow = 0; // Spazio concesso alla decelerazione, è prioritario rispetto all'accelerazione.
lex9296 23:b9d23a2f390e 127 in_PosizionatoreSW.i64_diToleranceWindow = 0; // Finestra di Tolleranza
lex9296 23:b9d23a2f390e 128 //
lex9296 23:b9d23a2f390e 129 in_PosizionatoreSW.f_MaximumSpeed_x100_FW = 25.0; // % of "i32_Max_Speed"
lex9296 23:b9d23a2f390e 130 in_PosizionatoreSW.f_MaximumSpeed_x100_BW = 25.0; //
lex9296 23:b9d23a2f390e 131 in_PosizionatoreSW.f_ServoLockSpeed_x100_FW = 5.0; //
lex9296 23:b9d23a2f390e 132 in_PosizionatoreSW.f_ServoLockSpeed_x100_BW = 5.0; //
lex9296 23:b9d23a2f390e 133
lex9296 23:b9d23a2f390e 134 // POS_MotionScan.attach_us (&Motion_tScan, 2000); // LA: Scansione Motion @2ms
lex9296 23:b9d23a2f390e 135
lex9296 23:b9d23a2f390e 136 // PWM_SetOut.attach_us (&PWM____tScan, 100); // Scansione base PWM @100us Ok
lex9296 23:b9d23a2f390e 137 // PWM_SetOut.attach_us (&PWM____tScan, 50); // Scansione base PWM @50us Ok
lex9296 23:b9d23a2f390e 138 // PWM_SetOut.attach_us (&PWM____tScan, 30); // Scansione base PWM @30us Ok
lex9296 23:b9d23a2f390e 139 // PWM_SetOut.attach_us (&PWM____tScan, 25); // Scansione base PWM @25us No (al pelo ...)
lex9296 23:b9d23a2f390e 140 // PWM_SetOut.attach_us (&PWM____tScan, 10); // Scansione base PWM @10us No (al pelo ...)
lex9296 23:b9d23a2f390e 141 // PWM_SetOut.attach_us (&PWM____tScan, 20); // Scansione base PWM @20us No
lex9296 23:b9d23a2f390e 142
lex9296 23:b9d23a2f390e 143 // PWM_SetOut.attach_us (&PWM____tScan, 40); // Scansione base PWM @40us, Duty Cycle 4ms, 0- 100%
lex9296 23:b9d23a2f390e 144 // PWM_SetOut.attach_us (&PWM____tScan, 100); // Scansione base PWM @40us, Duty Cycle 5ms, 0- 100%
lex9296 23:b9d23a2f390e 145
lex9296 25:5fd2d69e2927 146 PWM_PB3.period_us(100); // LA: TimeBase is 100us
lex9296 23:b9d23a2f390e 147
lex9296 23:b9d23a2f390e 148 while (1) {
lex9296 26:bfca0c471a87 149 int32_t i32_Pulses;
lex9296 26:bfca0c471a87 150 i32_Pulses = Stabilus322699.getPulses();
lex9296 23:b9d23a2f390e 151
lex9296 25:5fd2d69e2927 152 PosizionatoreSW (in_PosizionatoreSW, out_PosizionatoreSW);
lex9296 26:bfca0c471a87 153 PWM_PB3.pulsewidth_us(((float)i32_Pulses/ (float)5000.0)* (float)100.0); // 0.. 100us -> 0.. 100%
lex9296 25:5fd2d69e2927 154
lex9296 23:b9d23a2f390e 155 // LA: Wedge 4 LCDRefresh
lex9296 26:bfca0c471a87 156 StabilusMenu (0, 0, out_PosizionatoreSW.ui32_PassedActual_ms, i32_Pulses);
lex9296 23:b9d23a2f390e 157 }
lex9296 23:b9d23a2f390e 158 }
lex9296 23:b9d23a2f390e 159
lex9296 23:b9d23a2f390e 160
lex9296 23:b9d23a2f390e 161 /*
lex9296 23:b9d23a2f390e 162 bool PWM_0000 (uint32_t ui32_Duty_x100) {
lex9296 23:b9d23a2f390e 163 static uint32_t ui32_PWM_Base;
lex9296 23:b9d23a2f390e 164
lex9296 23:b9d23a2f390e 165 if (ui32_PWM_Base >= 100)
lex9296 23:b9d23a2f390e 166 ui32_PWM_Base = 0;
lex9296 23:b9d23a2f390e 167 else
lex9296 23:b9d23a2f390e 168 ui32_PWM_Base ++;
lex9296 23:b9d23a2f390e 169
lex9296 23:b9d23a2f390e 170 if (
lex9296 23:b9d23a2f390e 171 (ui32_Duty_x100 > 0) &&
lex9296 23:b9d23a2f390e 172 (ui32_Duty_x100 <= 100) &&
lex9296 23:b9d23a2f390e 173 (ui32_PWM_Base <= ui32_Duty_x100)
lex9296 23:b9d23a2f390e 174 )
lex9296 23:b9d23a2f390e 175 return (true);
lex9296 23:b9d23a2f390e 176 else
lex9296 23:b9d23a2f390e 177 return (false);
lex9296 23:b9d23a2f390e 178 }
lex9296 23:b9d23a2f390e 179
lex9296 23:b9d23a2f390e 180 void PWM____tScan (void) {
lex9296 23:b9d23a2f390e 181 PWM = PWM_0000 (50);
lex9296 23:b9d23a2f390e 182 }
lex9296 23:b9d23a2f390e 183 */