Julius Bernth / Mbed OS Cuvette_Centrifuge_Test_v1-2_ParallelMode

Dependencies:   QEI LIS3DH_spi

Committer:
juliusbernth
Date:
Mon Aug 09 18:59:04 2021 +0000
Revision:
5:e9bb800a3742
Parent:
4:d04afc466198
Child:
6:004dc33f4081
Working Version 1.1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
juliusbernth 0:64442857169c 1 /* mbed Microcontroller Library
juliusbernth 0:64442857169c 2 * Copyright (c) 2019 ARM Limited
juliusbernth 0:64442857169c 3 * SPDX-License-Identifier: Apache-2.0
juliusbernth 0:64442857169c 4 */
juliusbernth 0:64442857169c 5
juliusbernth 0:64442857169c 6 #include "mbed.h"
juliusbernth 0:64442857169c 7 #include "platform/mbed_thread.h"
juliusbernth 0:64442857169c 8 #include "Settings.h"
juliusbernth 0:64442857169c 9 #include "QEI.h"
juliusbernth 0:64442857169c 10 //#include "LIS3DH.h"
juliusbernth 0:64442857169c 11
juliusbernth 0:64442857169c 12 /*
juliusbernth 0:64442857169c 13 Open issues:
juliusbernth 5:e9bb800a3742 14 - need to figure out how to handle transitions to error states
juliusbernth 5:e9bb800a3742 15 - Need to test how breaking is performed.
juliusbernth 5:e9bb800a3742 16 -Test onboard current limitation
juliusbernth 0:64442857169c 17 */
juliusbernth 0:64442857169c 18
juliusbernth 0:64442857169c 19 Timer encoderTimer;
juliusbernth 0:64442857169c 20 Timer buttonTimer;
juliusbernth 0:64442857169c 21 Timer testTimer;
juliusbernth 0:64442857169c 22
juliusbernth 0:64442857169c 23 Timeout buttonTimeout;
juliusbernth 0:64442857169c 24
juliusbernth 0:64442857169c 25 Thread PrintThread(osPriorityAboveNormal);
juliusbernth 0:64442857169c 26 Thread CentrifugeTestThread(osPriorityHigh);
juliusbernth 0:64442857169c 27 Thread ReadButtonThread(osPriorityNormal);
juliusbernth 0:64442857169c 28 Thread MotorControlThread(osPriorityRealtime);
juliusbernth 0:64442857169c 29
juliusbernth 0:64442857169c 30 double SPIN_T[6]; //times for spin cycle
juliusbernth 0:64442857169c 31
juliusbernth 0:64442857169c 32 QEI encoder(PA_14, PA_13, PA_15, 256, QEI::X4_ENCODING);
juliusbernth 0:64442857169c 33
juliusbernth 0:64442857169c 34 //LIS3DH accel = LIS3DH(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS,LIS3DH_DR_NR_LP_400HZ, LIS3DH_FS_2G);
juliusbernth 0:64442857169c 35
juliusbernth 0:64442857169c 36 DigitalOut EN_FAULTA (D2);
juliusbernth 0:64442857169c 37 DigitalOut STBY (D8);
juliusbernth 0:64442857169c 38 DigitalOut PHA (D3);
juliusbernth 0:64442857169c 39 DigitalOut PHB (D7);
juliusbernth 0:64442857169c 40 PwmOut PWMA (D5);
juliusbernth 0:64442857169c 41 PwmOut PWMB (D4);
juliusbernth 0:64442857169c 42 PwmOut REF_PWM_A (D15);
juliusbernth 0:64442857169c 43 PwmOut REF_PWM_B (D14);
juliusbernth 0:64442857169c 44
juliusbernth 0:64442857169c 45 Serial pc(USBTX,USBRX);
juliusbernth 0:64442857169c 46
juliusbernth 0:64442857169c 47 DigitalOut pinStatusLED (D13);
juliusbernth 0:64442857169c 48 DigitalIn pinButton (PC_13);
juliusbernth 0:64442857169c 49
juliusbernth 0:64442857169c 50 /* Still to allocate
juliusbernth 0:64442857169c 51
juliusbernth 0:64442857169c 52 DigitalOut pinBuzzer
juliusbernth 0:64442857169c 53 DigitalOut pinPowerLED
juliusbernth 0:64442857169c 54
juliusbernth 0:64442857169c 55 */
juliusbernth 0:64442857169c 56
juliusbernth 0:64442857169c 57 //global variables
juliusbernth 0:64442857169c 58 double speedFilterConstant;
juliusbernth 5:e9bb800a3742 59 char state;
juliusbernth 0:64442857169c 60 double currentPulses;
juliusbernth 0:64442857169c 61 double lastPulses;
juliusbernth 0:64442857169c 62 double lastSpeedRPM;
juliusbernth 0:64442857169c 63 double Tnow;
juliusbernth 5:e9bb800a3742 64 double demandSpeed_RPM = 0.0;
juliusbernth 5:e9bb800a3742 65 double currentSpeedRPM;
juliusbernth 0:64442857169c 66 double deltaError;
juliusbernth 0:64442857169c 67 double lastError;
juliusbernth 0:64442857169c 68 double integralTerm;
juliusbernth 0:64442857169c 69 double output;
juliusbernth 0:64442857169c 70
juliusbernth 0:64442857169c 71 Ticker tickerMotorControl;
juliusbernth 0:64442857169c 72 Ticker tickerPrint;
juliusbernth 0:64442857169c 73 Ticker tickerReleaseButton;
juliusbernth 0:64442857169c 74
juliusbernth 0:64442857169c 75 Semaphore semMotorControl(0);
juliusbernth 0:64442857169c 76 Semaphore semPrint(0);
juliusbernth 0:64442857169c 77 Semaphore semStartTest(0);
juliusbernth 0:64442857169c 78 Semaphore semButton(0);
juliusbernth 0:64442857169c 79
juliusbernth 3:4f215646a42b 80 Mutex mut1;
juliusbernth 0:64442857169c 81
juliusbernth 0:64442857169c 82 double LimitDouble(double input, double min, double max){
juliusbernth 0:64442857169c 83 double output;
juliusbernth 0:64442857169c 84 output = input;
juliusbernth 0:64442857169c 85 if (input > max){
juliusbernth 0:64442857169c 86 output = max;
juliusbernth 0:64442857169c 87 }
juliusbernth 0:64442857169c 88 if (input < min){
juliusbernth 0:64442857169c 89 output = min;
juliusbernth 0:64442857169c 90 }
juliusbernth 0:64442857169c 91 return output;
juliusbernth 0:64442857169c 92 }
juliusbernth 0:64442857169c 93 /*
juliusbernth 0:64442857169c 94 double GetSpeed(int pulses, int lastPulses, double currentSpeed){
juliusbernth 0:64442857169c 95 double filteredSpeedRPM;
juliusbernth 0:64442857169c 96
juliusbernth 0:64442857169c 97 //find change in pulses.
juliusbernth 0:64442857169c 98 double speedRPM = (double) (pulses - lastPulses); //get change in angle
juliusbernth 0:64442857169c 99 speedRPM /= encoderTimer.read_us(); //calculate speed in pulses/us
juliusbernth 0:64442857169c 100 encoderTimer.reset();
juliusbernth 0:64442857169c 101 speedRPM *= 60000000.0/PULSES_PER_REV/4.0;//convert to RPM;
juliusbernth 0:64442857169c 102
juliusbernth 0:64442857169c 103 //filter speed
juliusbernth 0:64442857169c 104 //filteredSpeedRPM = speedFilterConstant * speedRPM + currentSpeed - speedFilterConstant * currentSpeed;
juliusbernth 0:64442857169c 105 filteredSpeedRPM = speedRPM;
juliusbernth 0:64442857169c 106 return filteredSpeedRPM;
juliusbernth 0:64442857169c 107 }*/
juliusbernth 0:64442857169c 108
juliusbernth 0:64442857169c 109
juliusbernth 0:64442857169c 110 void PIDControl(){
juliusbernth 0:64442857169c 111
juliusbernth 0:64442857169c 112 }
juliusbernth 0:64442857169c 113
juliusbernth 0:64442857169c 114 void TestCompleteNotification(){
juliusbernth 0:64442857169c 115 //send message
juliusbernth 0:64442857169c 116 printf("\r\nTest complete\r\n");
juliusbernth 0:64442857169c 117 //sound buzzer and blink 3 times
juliusbernth 0:64442857169c 118 }
juliusbernth 0:64442857169c 119
juliusbernth 0:64442857169c 120 void MotorControlRelease(){
juliusbernth 0:64442857169c 121 semMotorControl.release();
juliusbernth 0:64442857169c 122 }
juliusbernth 0:64442857169c 123 void PrintRelease(){
juliusbernth 0:64442857169c 124 semPrint.release();
juliusbernth 0:64442857169c 125 }
juliusbernth 0:64442857169c 126
juliusbernth 5:e9bb800a3742 127 void PrintTimeRemaining(){
juliusbernth 0:64442857169c 128 while(1){
juliusbernth 0:64442857169c 129 semPrint.wait();
juliusbernth 5:e9bb800a3742 130 if(state == STATE_RUNNING){
juliusbernth 0:64442857169c 131 double timeElapsed = testTimer.read();
juliusbernth 0:64442857169c 132 double timeRemaining = SPIN_T[5] - timeElapsed;
juliusbernth 0:64442857169c 133 int displayTime = int(timeRemaining)+1;
juliusbernth 0:64442857169c 134 //printf("Time remaining %d s\r\n", displayTime);
juliusbernth 3:4f215646a42b 135 mut1.lock();
juliusbernth 5:e9bb800a3742 136 double printDemandSpeed = demandSpeed_RPM;
juliusbernth 5:e9bb800a3742 137 double printCurrentSpeed = currentSpeedRPM;
juliusbernth 3:4f215646a42b 138 mut1.unlock();
juliusbernth 5:e9bb800a3742 139 printf("%f\t%f\r\n",demandSpeed_RPM, currentSpeedRPM);
juliusbernth 3:4f215646a42b 140 }
juliusbernth 3:4f215646a42b 141 }
juliusbernth 3:4f215646a42b 142 }
juliusbernth 3:4f215646a42b 143
juliusbernth 0:64442857169c 144 void MotorControl(){
juliusbernth 0:64442857169c 145 while(1){
juliusbernth 0:64442857169c 146 semMotorControl.wait();//wait for a signal
juliusbernth 5:e9bb800a3742 147 if(state == STATE_RUNNING){//need to check if this is the best condition to look for.
juliusbernth 5:e9bb800a3742 148
juliusbernth 5:e9bb800a3742 149 Tnow = testTimer.read();
juliusbernth 5:e9bb800a3742 150 //check accel. If problem, change state to ERROR
juliusbernth 5:e9bb800a3742 151
juliusbernth 5:e9bb800a3742 152 //int deltaT = encoderTimer.read();//read current time in seconds
juliusbernth 5:e9bb800a3742 153
juliusbernth 0:64442857169c 154 //calculate current demand
juliusbernth 5:e9bb800a3742 155 if ( (SPIN_T[0] <= Tnow) && (Tnow < SPIN_T[1]) ) {//test is in warmup
juliusbernth 0:64442857169c 156 demandSpeed_RPM = 0.0;
juliusbernth 5:e9bb800a3742 157 //printf("warm up %f\r\n", demandSpeed_RPM);
juliusbernth 5:e9bb800a3742 158 //deactivate motor?
juliusbernth 0:64442857169c 159 }
juliusbernth 5:e9bb800a3742 160 if ((SPIN_T[1] <= Tnow)&&(Tnow < SPIN_T[2])){//test is in ramp up
juliusbernth 5:e9bb800a3742 161
juliusbernth 5:e9bb800a3742 162 double a = Tnow - SPIN_T[1];
juliusbernth 5:e9bb800a3742 163 demandSpeed_RPM = a * targetSpeed_RPM / T_RAMP;
juliusbernth 5:e9bb800a3742 164 //printf("ramp up %f\r\n", demandSpeed_RPM);
juliusbernth 5:e9bb800a3742 165 }
juliusbernth 5:e9bb800a3742 166 if ((SPIN_T[2] <= Tnow)&&(Tnow < SPIN_T[3])){//test is in coast
juliusbernth 5:e9bb800a3742 167 demandSpeed_RPM = targetSpeed_RPM;
juliusbernth 5:e9bb800a3742 168 //printf("coast %f\r\n", demandSpeed_RPM);
juliusbernth 4:d04afc466198 169 }
juliusbernth 5:e9bb800a3742 170 if ((SPIN_T[3] <= Tnow)&&(Tnow < SPIN_T[4])){//test is in ramp down
juliusbernth 5:e9bb800a3742 171 double a = Tnow - SPIN_T[3];
juliusbernth 5:e9bb800a3742 172 demandSpeed_RPM = targetSpeed_RPM - (a/T_RAMP*targetSpeed_RPM);
juliusbernth 5:e9bb800a3742 173 //printf("ramp down %f\r\n", demandSpeed_RPM);
juliusbernth 5:e9bb800a3742 174 }
juliusbernth 5:e9bb800a3742 175 if ((SPIN_T[4] <= Tnow)&&(Tnow < SPIN_T[5])){//test is in cooldown
juliusbernth 5:e9bb800a3742 176 demandSpeed_RPM = 0.0;
juliusbernth 5:e9bb800a3742 177 //printf("cool down %f\r\n", demandSpeed_RPM);
juliusbernth 5:e9bb800a3742 178 //deactivate motor?
juliusbernth 4:d04afc466198 179 }
juliusbernth 4:d04afc466198 180
juliusbernth 5:e9bb800a3742 181 demandSpeed_RPM = LimitDouble(demandSpeed_RPM,0.0,MAX_SPEED_RPM);//limit demand
juliusbernth 5:e9bb800a3742 182 currentPulses = encoder.getPulses();//calculate current speed
juliusbernth 5:e9bb800a3742 183 double deltaPulses = currentPulses - lastPulses;
juliusbernth 5:e9bb800a3742 184 double speed_RPM = deltaPulses / SAMPLE_TIME_US * 1000000;//get in pulses per second
juliusbernth 5:e9bb800a3742 185 speed_RPM *= 60/4/PULSES_PER_REV;//convert to RPM
juliusbernth 5:e9bb800a3742 186
juliusbernth 5:e9bb800a3742 187 currentSpeedRPM = 0.3*speed_RPM + 0.7*lastSpeedRPM;//filter speed
juliusbernth 5:e9bb800a3742 188
juliusbernth 5:e9bb800a3742 189 double error = demandSpeed_RPM - currentSpeedRPM;//calculate error
juliusbernth 5:e9bb800a3742 190 deltaError = error - lastError;
juliusbernth 5:e9bb800a3742 191 double errorDot = deltaError/SAMPLE_TIME_US*1000000.0;
juliusbernth 5:e9bb800a3742 192 integralTerm += error*Ki*SAMPLE_TIME_US/1000000.0;
juliusbernth 5:e9bb800a3742 193 integralTerm = LimitDouble(integralTerm,-0.8, 0.8);
juliusbernth 5:e9bb800a3742 194
juliusbernth 5:e9bb800a3742 195 output = Kp * error; //calculate output
juliusbernth 5:e9bb800a3742 196 output += integralTerm;
juliusbernth 5:e9bb800a3742 197 output += Kd*errorDot;
juliusbernth 5:e9bb800a3742 198 output = LimitDouble(output,-1.0,1.0);
juliusbernth 5:e9bb800a3742 199 //printf("wd:%f\t w:%f\t e:%f\t o:%f \r\n",demandSpeed_RPM, currentSpeedRPM, error, output);
juliusbernth 5:e9bb800a3742 200
juliusbernth 5:e9bb800a3742 201 if(output >=0){//Set direction
juliusbernth 5:e9bb800a3742 202 PHA.write(0);
juliusbernth 5:e9bb800a3742 203 }else{
juliusbernth 5:e9bb800a3742 204 PHA.write(1);
juliusbernth 5:e9bb800a3742 205 output = -1*output;
juliusbernth 5:e9bb800a3742 206 }
juliusbernth 5:e9bb800a3742 207 PWMA.write(output);//write to motor
juliusbernth 5:e9bb800a3742 208
juliusbernth 5:e9bb800a3742 209 lastPulses = currentPulses;//update
juliusbernth 5:e9bb800a3742 210 lastError = error;
juliusbernth 5:e9bb800a3742 211 lastSpeedRPM = currentSpeedRPM;
juliusbernth 5:e9bb800a3742 212
juliusbernth 5:e9bb800a3742 213 //exit when test has completed
juliusbernth 5:e9bb800a3742 214 if (Tnow >= SPIN_T[5]){
juliusbernth 5:e9bb800a3742 215 printf("Terminating Test %f \t %f\r\n", Tnow, SPIN_T[5]);
juliusbernth 5:e9bb800a3742 216 state = STATE_READY;//change state
juliusbernth 0:64442857169c 217 testTimer.stop(); //stop and reset timers
juliusbernth 0:64442857169c 218 testTimer.reset();
juliusbernth 0:64442857169c 219 Tnow = testTimer.read();
juliusbernth 5:e9bb800a3742 220 encoderTimer.stop();
juliusbernth 5:e9bb800a3742 221 encoderTimer.reset();
juliusbernth 5:e9bb800a3742 222 EN_FAULTA.write(0);//disable motor
juliusbernth 0:64442857169c 223
juliusbernth 5:e9bb800a3742 224 tickerMotorControl.detach(); //detach the semaphore release for motor control
juliusbernth 5:e9bb800a3742 225 tickerPrint.detach();
juliusbernth 5:e9bb800a3742 226
juliusbernth 5:e9bb800a3742 227 printf("state = %d\r\n",state);
juliusbernth 0:64442857169c 228 TestCompleteNotification();//send notification
juliusbernth 0:64442857169c 229 //deactivate motor
juliusbernth 5:e9bb800a3742 230 //PrintThread.terminate();//terminate print thread
juliusbernth 0:64442857169c 231 //CentrifugeTestThread.terminate();//terminate threads
juliusbernth 0:64442857169c 232 }
juliusbernth 0:64442857169c 233 }
juliusbernth 0:64442857169c 234 }
juliusbernth 0:64442857169c 235 }
juliusbernth 0:64442857169c 236
juliusbernth 5:e9bb800a3742 237 void CentrifugeTest(){
juliusbernth 5:e9bb800a3742 238 while(1){
juliusbernth 5:e9bb800a3742 239 semStartTest.wait();
juliusbernth 0:64442857169c 240 printf("\r\n Test starting \r\n");
juliusbernth 5:e9bb800a3742 241 state = STATE_RUNNING;
juliusbernth 0:64442857169c 242 //set up test
juliusbernth 0:64442857169c 243 testTimer.reset();
juliusbernth 0:64442857169c 244 testTimer.start();//start timer
juliusbernth 0:64442857169c 245
juliusbernth 5:e9bb800a3742 246 char spinState;
juliusbernth 0:64442857169c 247
juliusbernth 0:64442857169c 248 //set up ticker to allow motor control thread to run periodically
juliusbernth 5:e9bb800a3742 249
juliusbernth 0:64442857169c 250 encoder.reset();//reset encoder
juliusbernth 0:64442857169c 251 lastPulses = 0;//reset previous encoder reading
juliusbernth 5:e9bb800a3742 252 encoderTimer.start();
juliusbernth 5:e9bb800a3742 253 PrintThread.start(PrintTimeRemaining);
juliusbernth 0:64442857169c 254 printf("\r\n Test setup complete \r\n");
juliusbernth 5:e9bb800a3742 255 EN_FAULTA.write(1);
juliusbernth 5:e9bb800a3742 256 if(state == STATE_RUNNING){
juliusbernth 5:e9bb800a3742 257 printf("\r\n running %d\r\n",state);
juliusbernth 5:e9bb800a3742 258 }
juliusbernth 0:64442857169c 259
juliusbernth 5:e9bb800a3742 260
juliusbernth 5:e9bb800a3742 261 }
juliusbernth 0:64442857169c 262 }
juliusbernth 0:64442857169c 263
juliusbernth 0:64442857169c 264 void ReleaseReadButton(){
juliusbernth 0:64442857169c 265 semButton.release();
juliusbernth 0:64442857169c 266 }
juliusbernth 0:64442857169c 267
juliusbernth 0:64442857169c 268 void ReadButton()
juliusbernth 0:64442857169c 269 {
juliusbernth 0:64442857169c 270 int countThreashold = int(BUTTON_HOLD_TIME_S/BUTTON_READ_SAMPLETIME_S);
juliusbernth 0:64442857169c 271 while (1)
juliusbernth 0:64442857169c 272 {
juliusbernth 0:64442857169c 273 semButton.wait();
juliusbernth 0:64442857169c 274 int count = 0;
juliusbernth 0:64442857169c 275
juliusbernth 0:64442857169c 276 while(!pinButton.read())
juliusbernth 0:64442857169c 277 {
juliusbernth 0:64442857169c 278 count++;
juliusbernth 0:64442857169c 279 if (count ==1){
juliusbernth 0:64442857169c 280 printf("button pressed\r\n");
juliusbernth 0:64442857169c 281 }
juliusbernth 0:64442857169c 282 ThisThread::sleep_for(10);
juliusbernth 0:64442857169c 283 }
juliusbernth 5:e9bb800a3742 284 switch (state)
juliusbernth 0:64442857169c 285 {
juliusbernth 0:64442857169c 286 case STATE_READY:
juliusbernth 0:64442857169c 287 if(count > countThreashold)
juliusbernth 0:64442857169c 288 {
juliusbernth 0:64442857169c 289 printf("button released count = %d\r\n",count);
juliusbernth 0:64442857169c 290 count = 0;
juliusbernth 0:64442857169c 291 //CentrifugeTestThread.start(CentrifugeTest);
juliusbernth 5:e9bb800a3742 292 semStartTest.release();
juliusbernth 0:64442857169c 293 tickerMotorControl.attach_us(&MotorControlRelease, SAMPLE_TIME_US);//set up signal for control frequency
juliusbernth 0:64442857169c 294 tickerPrint.attach(&PrintRelease,PRINT_TIME_S);
juliusbernth 0:64442857169c 295 }
juliusbernth 0:64442857169c 296 break;
juliusbernth 0:64442857169c 297 case STATE_RUNNING:
juliusbernth 0:64442857169c 298 if(count >1){
juliusbernth 5:e9bb800a3742 299 EN_FAULTA.write(0);
juliusbernth 0:64442857169c 300 }
juliusbernth 0:64442857169c 301 break;
juliusbernth 0:64442857169c 302
juliusbernth 0:64442857169c 303 case STATE_ERROR:
juliusbernth 0:64442857169c 304
juliusbernth 0:64442857169c 305 break;
juliusbernth 0:64442857169c 306 default:
juliusbernth 0:64442857169c 307 break;
juliusbernth 0:64442857169c 308 }
juliusbernth 0:64442857169c 309 count = 0;
juliusbernth 5:e9bb800a3742 310 ThisThread::sleep_for(100);
juliusbernth 0:64442857169c 311 }
juliusbernth 0:64442857169c 312 }
juliusbernth 0:64442857169c 313
juliusbernth 0:64442857169c 314 int main(){
juliusbernth 0:64442857169c 315 printf("\r\nSystem Online\r\n");
juliusbernth 0:64442857169c 316 //set up system
juliusbernth 0:64442857169c 317
juliusbernth 0:64442857169c 318 //set up motor
juliusbernth 0:64442857169c 319 //EN_FAULTA.mode(PullDown);
juliusbernth 0:64442857169c 320 //STBY.mode(PullDown);
juliusbernth 0:64442857169c 321
juliusbernth 0:64442857169c 322 REF_PWM_A.period_us(100);
juliusbernth 0:64442857169c 323 PWMA.period_us(100);
juliusbernth 0:64442857169c 324 REF_PWM_A.write(0.5);//set current reference
juliusbernth 0:64442857169c 325
juliusbernth 0:64442857169c 326 EN_FAULTA.write(0);
juliusbernth 0:64442857169c 327 STBY.write(1);
juliusbernth 0:64442857169c 328 //calculate filter constant
juliusbernth 0:64442857169c 329 speedFilterConstant = 2*3.141593*SAMPLE_TIME_US/1000000*FILTER_CUTOFF_FREQ;
juliusbernth 0:64442857169c 330 speedFilterConstant /= (1 + speedFilterConstant);
juliusbernth 0:64442857169c 331
juliusbernth 0:64442857169c 332 SPIN_T[0] = 0.0;
juliusbernth 0:64442857169c 333 SPIN_T[1] = T_WARMUP;
juliusbernth 0:64442857169c 334 SPIN_T[2] = T_WARMUP + T_RAMP;
juliusbernth 0:64442857169c 335 SPIN_T[3] = T_WARMUP + T_RAMP + T_TEST;
juliusbernth 0:64442857169c 336 SPIN_T[4] = T_WARMUP + T_RAMP + T_TEST + T_RAMP;
juliusbernth 0:64442857169c 337 SPIN_T[5] = T_WARMUP + T_RAMP + T_TEST + T_RAMP + T_WARMUP;
juliusbernth 0:64442857169c 338
juliusbernth 0:64442857169c 339 /* //set up button interrupts
juliusbernth 0:64442857169c 340 pinButton.rise(ISR_Button_Rise);
juliusbernth 0:64442857169c 341 pinButton.fall(ISR_Button_Fall);
juliusbernth 0:64442857169c 342 */
juliusbernth 5:e9bb800a3742 343
juliusbernth 5:e9bb800a3742 344 state = STATE_READY;//set state to READY
juliusbernth 0:64442857169c 345 //start all threads
juliusbernth 0:64442857169c 346 MotorControlThread.start(MotorControl);
juliusbernth 0:64442857169c 347
juliusbernth 5:e9bb800a3742 348 CentrifugeTestThread.start(CentrifugeTest);
juliusbernth 0:64442857169c 349 //start print thread.
juliusbernth 0:64442857169c 350
juliusbernth 0:64442857169c 351 ReadButtonThread.start(ReadButton);
juliusbernth 0:64442857169c 352 tickerReleaseButton.attach(ReleaseReadButton,BUTTON_READ_SAMPLETIME_S);
juliusbernth 0:64442857169c 353
juliusbernth 0:64442857169c 354
juliusbernth 0:64442857169c 355 printf("\r\nSetup Complete\r\n");
juliusbernth 0:64442857169c 356 while (true) {
juliusbernth 0:64442857169c 357 //check state of button
juliusbernth 0:64442857169c 358 ThisThread::sleep_for(osWaitForever);
juliusbernth 0:64442857169c 359 }
juliusbernth 0:64442857169c 360 }