scooter correction for mbed_os V5.2

Dependencies:   bloc_io html_mbed_os

Fork of scooter_mbed by ERS3 2015-2016

Committer:
superphil06
Date:
Wed Aug 12 15:54:13 2015 +0000
Revision:
1:e3cb81b3cbea
Parent:
0:8871b0c9af3b
Child:
3:ac3990c4a479
including can reception for gaz ref unsing thread

Who changed what in which revision?

UserRevisionLine numberNew contents of line
superphil06 0:8871b0c9af3b 1
superphil06 0:8871b0c9af3b 2
superphil06 1:e3cb81b3cbea 3 //#include "EthernetInterface.h"
superphil06 0:8871b0c9af3b 4 #include <stdlib.h>
superphil06 0:8871b0c9af3b 5 #include <string.h>
superphil06 0:8871b0c9af3b 6 #include "mbed.h"
superphil06 1:e3cb81b3cbea 7 #include "rtos.h" // need for main thread sleep
superphil06 0:8871b0c9af3b 8 #include "html.h" // need for html patch working with web server
superphil06 0:8871b0c9af3b 9 #include "bloc_io.h"
superphil06 0:8871b0c9af3b 10 #define RADIUS 0.2F // wheel size
superphil06 0:8871b0c9af3b 11 #define NBPOLES 8 // magnetic pole number
superphil06 0:8871b0c9af3b 12 #define DELTA_T 0.1F // speed measurement counting period
superphil06 0:8871b0c9af3b 13
superphil06 0:8871b0c9af3b 14 Ticker IT_Timer_Gaz,IT_Speed;
superphil06 0:8871b0c9af3b 15 float fSpeed=0;
superphil06 0:8871b0c9af3b 16 float fTabVal[10];// need to store analog value
superphil06 0:8871b0c9af3b 17 float fGaz,fTemp,fBat,fIdc;
superphil06 0:8871b0c9af3b 18 float fGAZ_MAX=70,fGAZ_MIN=15;
superphil06 0:8871b0c9af3b 19 unsigned int uiCptImpuls=0;
superphil06 0:8871b0c9af3b 20 Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD
superphil06 0:8871b0c9af3b 21 AnalogIn Gaz(p17),Bat(p18),Temp(p19),Idc(p20);// analog input connected to mbed
superphil06 0:8871b0c9af3b 22 DigitalOut ValidPWM (p21,0);// reset valid pmw pin
superphil06 0:8871b0c9af3b 23 Serial pc(USBTX, USBRX); // tx, rx
superphil06 0:8871b0c9af3b 24 InterruptIn TopHall(p22);
superphil06 0:8871b0c9af3b 25
superphil06 0:8871b0c9af3b 26
superphil06 0:8871b0c9af3b 27 float fGaz_Brute;
superphil06 0:8871b0c9af3b 28
superphil06 0:8871b0c9af3b 29 /************ persistent file parameters section *****************/
superphil06 0:8871b0c9af3b 30 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
superphil06 0:8871b0c9af3b 31
superphil06 0:8871b0c9af3b 32
superphil06 0:8871b0c9af3b 33
superphil06 0:8871b0c9af3b 34
superphil06 0:8871b0c9af3b 35
superphil06 0:8871b0c9af3b 36
superphil06 0:8871b0c9af3b 37
superphil06 0:8871b0c9af3b 38 /********************* web server section **********************************/
superphil06 1:e3cb81b3cbea 39 //char * ma_chaine3;
superphil06 0:8871b0c9af3b 40 var_field_t tab_balise[10]; //une balise est présente dans le squelette
superphil06 0:8871b0c9af3b 41 int giCounter=0;// acces counting
superphil06 0:8871b0c9af3b 42
superphil06 0:8871b0c9af3b 43
superphil06 1:e3cb81b3cbea 44 /*********************** can bus section ************/
superphil06 1:e3cb81b3cbea 45 #define GAZ_CAN_ID 1000 // determine message ID used to send Gaz ref over can bus
superphil06 1:e3cb81b3cbea 46 #define _CAN_DEBUG // used to debug can bus activity
superphil06 1:e3cb81b3cbea 47 #define USE_CAN_REF // uncomment to receive gaz ref over can_bus
superphil06 1:e3cb81b3cbea 48 CANMessage msg_receive,msg_send;
superphil06 1:e3cb81b3cbea 49 DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/
superphil06 1:e3cb81b3cbea 50 DigitalOut led2(LED2);
superphil06 1:e3cb81b3cbea 51 DigitalOut led3(LED3); // blink when can message is sent
superphil06 1:e3cb81b3cbea 52 DigitalOut led4(LED4); // blink when can message is received
superphil06 1:e3cb81b3cbea 53 CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield
superphil06 1:e3cb81b3cbea 54 int iGaz_Can=0;
superphil06 1:e3cb81b3cbea 55 bool bCan_Active=false;
superphil06 1:e3cb81b3cbea 56
superphil06 0:8871b0c9af3b 57
superphil06 0:8871b0c9af3b 58
superphil06 0:8871b0c9af3b 59 //************ prototypes *******************
superphil06 0:8871b0c9af3b 60
superphil06 0:8871b0c9af3b 61
superphil06 0:8871b0c9af3b 62
superphil06 0:8871b0c9af3b 63
superphil06 0:8871b0c9af3b 64
superphil06 0:8871b0c9af3b 65
superphil06 0:8871b0c9af3b 66 //***********
superphil06 0:8871b0c9af3b 67 //* functions
superphil06 0:8871b0c9af3b 68
superphil06 1:e3cb81b3cbea 69 /**************** Read persistent data from text file located on local file system ****************/
superphil06 0:8871b0c9af3b 70 int Read_File_Data(char * pcFileName)
superphil06 0:8871b0c9af3b 71 {
superphil06 0:8871b0c9af3b 72 float fRayon;
superphil06 0:8871b0c9af3b 73 int iPoles,iVit_Max;
superphil06 0:8871b0c9af3b 74 FILE *DataFile;
superphil06 0:8871b0c9af3b 75 DataFile= fopen(pcFileName, "rt");
superphil06 0:8871b0c9af3b 76 if ( DataFile == NULL)
superphil06 0:8871b0c9af3b 77 { printf("\r\nError Open File: %s", pcFileName); //open data file from disk
superphil06 0:8871b0c9af3b 78 return(NULL);
superphil06 0:8871b0c9af3b 79 }
superphil06 0:8871b0c9af3b 80 else
superphil06 0:8871b0c9af3b 81 {fscanf (DataFile,"rayon:%f ",&fRayon);// insert ' ' after %format mode to separe numeric data
superphil06 0:8871b0c9af3b 82 fscanf (DataFile,"poles:%d ",&iPoles);
superphil06 0:8871b0c9af3b 83 fscanf (DataFile,"vit_max:%d ",&iVit_Max);
superphil06 1:e3cb81b3cbea 84 fscanf (DataFile,"fgaz_max:%f ",&fGAZ_MAX);
superphil06 1:e3cb81b3cbea 85 fscanf (DataFile,"fgaz_min:%f ",&fGAZ_MIN);
superphil06 1:e3cb81b3cbea 86 printf("valeurs lues: rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN);
superphil06 0:8871b0c9af3b 87 fclose(DataFile);
superphil06 0:8871b0c9af3b 88 return 0;
superphil06 0:8871b0c9af3b 89 }
superphil06 0:8871b0c9af3b 90
superphil06 0:8871b0c9af3b 91 }
superphil06 0:8871b0c9af3b 92
superphil06 1:e3cb81b3cbea 93
superphil06 1:e3cb81b3cbea 94 /**************** write persitant data to text file located on local file system ****************/
superphil06 0:8871b0c9af3b 95 int Write_File_Data(char * pcFileName)
superphil06 0:8871b0c9af3b 96 {
superphil06 0:8871b0c9af3b 97 float fRayon=0.45;
superphil06 0:8871b0c9af3b 98 int iPoles=10,iVit_Max=15000;
superphil06 0:8871b0c9af3b 99 FILE *DataFile;
superphil06 0:8871b0c9af3b 100 DataFile= fopen(pcFileName,"wt");
superphil06 0:8871b0c9af3b 101
superphil06 0:8871b0c9af3b 102
superphil06 0:8871b0c9af3b 103
superphil06 0:8871b0c9af3b 104 if ( DataFile == NULL)
superphil06 0:8871b0c9af3b 105 { printf("\r\nError Open File: %s", pcFileName); //open data file from disk
superphil06 0:8871b0c9af3b 106 return(NULL);
superphil06 0:8871b0c9af3b 107 }
superphil06 0:8871b0c9af3b 108 else
superphil06 1:e3cb81b3cbea 109 { fprintf (DataFile, "rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN);
superphil06 0:8871b0c9af3b 110
superphil06 1:e3cb81b3cbea 111 printf("valeurs ecrites: rayon:%f poles:%d vit_max:%d gaz_max:%f gaz_min:%f \n\r",fRayon,iPoles,iVit_Max,fGAZ_MAX,fGAZ_MIN);
superphil06 0:8871b0c9af3b 112 fclose(DataFile);
superphil06 0:8871b0c9af3b 113 return 0;
superphil06 0:8871b0c9af3b 114 }
superphil06 0:8871b0c9af3b 115
superphil06 0:8871b0c9af3b 116 }
superphil06 0:8871b0c9af3b 117
superphil06 0:8871b0c9af3b 118
superphil06 0:8871b0c9af3b 119
superphil06 0:8871b0c9af3b 120
superphil06 0:8871b0c9af3b 121
superphil06 0:8871b0c9af3b 122
superphil06 1:e3cb81b3cbea 123 //************** needed to record min_gaz and max_gaz value to persistent text file ******************
superphil06 0:8871b0c9af3b 124 void Calibrate_Gaz(void)
superphil06 0:8871b0c9af3b 125 { char cJunk;
superphil06 0:8871b0c9af3b 126
superphil06 0:8871b0c9af3b 127 fGaz=Gaz.read()*100;
superphil06 0:8871b0c9af3b 128 fTemp=Temp.read()*100;
superphil06 0:8871b0c9af3b 129 fBat=Bat.read()*100;
superphil06 0:8871b0c9af3b 130 fIdc=Idc.read()*100;
superphil06 0:8871b0c9af3b 131
superphil06 0:8871b0c9af3b 132 pc.printf("mettre la poignee au minimum et appuyer sur une touche \n");
superphil06 0:8871b0c9af3b 133 pc.scanf(" %c",&cJunk);
superphil06 0:8871b0c9af3b 134 fTabVal[0]=Gaz.read()*100;// read min gaz value)
superphil06 0:8871b0c9af3b 135 fGAZ_MIN=fTabVal[0];// update local GAZ_MIN constante
superphil06 0:8871b0c9af3b 136 pc.printf("mettre la poignee au maximum et appuyer sur une touche \n");
superphil06 0:8871b0c9af3b 137 pc.scanf(" %c",&cJunk);
superphil06 0:8871b0c9af3b 138 fTabVal[1]=Gaz.read()*100;// read max gaz value
superphil06 0:8871b0c9af3b 139 fGAZ_MAX=fTabVal[1];// update local GAZ_MIN constante
superphil06 0:8871b0c9af3b 140 pc.printf("calibration terminee: gaz_min=%f gaz_max=%f \n",fTabVal[0],fTabVal[1]);
superphil06 1:e3cb81b3cbea 141 Write_File_Data("/local/persist.txt"); // write persistent data to text file
superphil06 0:8871b0c9af3b 142
superphil06 0:8871b0c9af3b 143 }
superphil06 0:8871b0c9af3b 144
superphil06 1:e3cb81b3cbea 145 // ************top hall counting interupt needed for speed measurement
superphil06 0:8871b0c9af3b 146 void SpeedCount(void)
superphil06 0:8871b0c9af3b 147 {uiCptImpuls++;// top hall encoured increment speed counter
superphil06 0:8871b0c9af3b 148 }
superphil06 0:8871b0c9af3b 149
superphil06 0:8871b0c9af3b 150
superphil06 1:e3cb81b3cbea 151 //********************** timer interrupt for speed measurement each 100ms *************************
superphil06 0:8871b0c9af3b 152 void MyITSpeed(void)
superphil06 0:8871b0c9af3b 153 {unsigned int uiCptSpeed;
superphil06 0:8871b0c9af3b 154
superphil06 0:8871b0c9af3b 155 uiCptSpeed=uiCptImpuls;// read actual count
superphil06 0:8871b0c9af3b 156 uiCptImpuls=0;// reset counter for next counting period
superphil06 0:8871b0c9af3b 157 fSpeed=2*(float)3.14159*RADIUS*(float)uiCptSpeed*3600/(6*NBPOLES*DELTA_T);
superphil06 0:8871b0c9af3b 158 }
superphil06 0:8871b0c9af3b 159
superphil06 0:8871b0c9af3b 160
superphil06 0:8871b0c9af3b 161
superphil06 0:8871b0c9af3b 162
superphil06 0:8871b0c9af3b 163
superphil06 1:e3cb81b3cbea 164 //********************* Timer Interrupt for gaz ref management each 10ms ********************
superphil06 0:8871b0c9af3b 165 void MyITGaz (void)
superphil06 0:8871b0c9af3b 166 {unsigned char byRefPWM=0;
superphil06 0:8871b0c9af3b 167
superphil06 0:8871b0c9af3b 168 fGaz=Gaz.read()*100;// read actual gaz
superphil06 0:8871b0c9af3b 169 fBat=Bat.read()*100;// read actual Bat voltage
superphil06 0:8871b0c9af3b 170 fIdc=Idc.read()*100;// read actual Idc current
superphil06 0:8871b0c9af3b 171 fTemp=Temp.read()*100;// readf actual Temp
superphil06 1:e3cb81b3cbea 172
superphil06 1:e3cb81b3cbea 173 #ifndef USE_CAN_REF
superphil06 1:e3cb81b3cbea 174 fGaz_Brute= (float)255/(fGAZ_MAX-fGAZ_MIN)* (fGaz-fGAZ_MIN);/ use local ref
superphil06 1:e3cb81b3cbea 175 #else
superphil06 1:e3cb81b3cbea 176 fGaz_Brute= iGaz_Can;// use can bus gaz ref
superphil06 1:e3cb81b3cbea 177 #endif
superphil06 1:e3cb81b3cbea 178
superphil06 0:8871b0c9af3b 179 if (fGaz_Brute>255) fGaz_Brute=255;
superphil06 0:8871b0c9af3b 180 if (fGaz_Brute<0) fGaz_Brute=0;
superphil06 0:8871b0c9af3b 181 byRefPWM=(unsigned char) fGaz_Brute;
superphil06 0:8871b0c9af3b 182 MyPLD.write(byRefPWM);// update pwm ref on pld
superphil06 0:8871b0c9af3b 183 }
superphil06 0:8871b0c9af3b 184
superphil06 0:8871b0c9af3b 185
superphil06 1:e3cb81b3cbea 186 /********* main cgi function used to patch data to the web server thread **********************************/
superphil06 1:e3cb81b3cbea 187 void CGI_Function(void) // cgi function that patch web data to empty web page
superphil06 1:e3cb81b3cbea 188 { char ma_chaine4[20]={};// needed to form html response
superphil06 1:e3cb81b3cbea 189 sprintf (ma_chaine4,"%d",(int)fSpeed);// convert speed as ascii string
superphil06 1:e3cb81b3cbea 190 Html_Patch (tab_balise,0,ma_chaine4);// patch first label with dyn.string
superphil06 1:e3cb81b3cbea 191
superphil06 1:e3cb81b3cbea 192 sprintf (ma_chaine4,"%d",(int)(fGaz_Brute*100)/255);// convert count as ascii string
superphil06 1:e3cb81b3cbea 193 Html_Patch (tab_balise,1,ma_chaine4);// patch first label with dyn.string
superphil06 1:e3cb81b3cbea 194
superphil06 1:e3cb81b3cbea 195 sprintf (ma_chaine4,"%d",(int)fBat);// convert count as ascii string
superphil06 1:e3cb81b3cbea 196 Html_Patch (tab_balise,2,ma_chaine4);// patch first label with dyn.string
superphil06 1:e3cb81b3cbea 197
superphil06 1:e3cb81b3cbea 198 sprintf (ma_chaine4,"%d",(int)fIdc);// convert count as ascii string
superphil06 1:e3cb81b3cbea 199 Html_Patch (tab_balise,3,ma_chaine4);// patch first label with dyn.string
superphil06 1:e3cb81b3cbea 200
superphil06 1:e3cb81b3cbea 201 sprintf (ma_chaine4,"%d",(int)fTemp);// convert count as ascii string
superphil06 1:e3cb81b3cbea 202 Html_Patch (tab_balise,4,ma_chaine4);// patch first label with dyn.string
superphil06 1:e3cb81b3cbea 203
superphil06 1:e3cb81b3cbea 204
superphil06 1:e3cb81b3cbea 205
superphil06 1:e3cb81b3cbea 206 }
superphil06 1:e3cb81b3cbea 207
superphil06 1:e3cb81b3cbea 208
superphil06 1:e3cb81b3cbea 209 /*********************** CAN BUS SECTION **********************/
superphil06 1:e3cb81b3cbea 210
superphil06 1:e3cb81b3cbea 211
superphil06 1:e3cb81b3cbea 212
superphil06 1:e3cb81b3cbea 213 void CAN_REC_THREAD(void const *args)
superphil06 1:e3cb81b3cbea 214 { int iCount,iError;
superphil06 1:e3cb81b3cbea 215
superphil06 1:e3cb81b3cbea 216 while (bCan_Active)
superphil06 1:e3cb81b3cbea 217 {Thread::wait(100);// wait 100ms
superphil06 1:e3cb81b3cbea 218 //printf("CAN_REC_Thread\n\r");
superphil06 1:e3cb81b3cbea 219 if(can_port.read(msg_receive)) //si on lit un message reçu */
superphil06 1:e3cb81b3cbea 220 //can_port.read(msg_receive);
superphil06 1:e3cb81b3cbea 221 {iError=0;
superphil06 1:e3cb81b3cbea 222 #ifdef _CAN_DEBUG
superphil06 1:e3cb81b3cbea 223 printf("CAN Message received : %s\n id=%d\n\r", msg_receive.data,msg_receive.id);
superphil06 1:e3cb81b3cbea 224 # endif
superphil06 1:e3cb81b3cbea 225 switch (msg_receive.id) {
superphil06 1:e3cb81b3cbea 226 case GAZ_CAN_ID: // received Gaz from can
superphil06 1:e3cb81b3cbea 227 sscanf((char *)msg_receive.data,"%03d",&iGaz_Can);// read and convert gaz ref from can bus
superphil06 1:e3cb81b3cbea 228 led4=!led4;
superphil06 1:e3cb81b3cbea 229 #ifdef _CAN_DEBUG
superphil06 1:e3cb81b3cbea 230 for (iCount=0; iCount<=5;iCount++)
superphil06 1:e3cb81b3cbea 231 {led4=!led4;
superphil06 1:e3cb81b3cbea 232 Thread::wait(100);
superphil06 1:e3cb81b3cbea 233 }
superphil06 1:e3cb81b3cbea 234 #endif
superphil06 1:e3cb81b3cbea 235 break;
superphil06 1:e3cb81b3cbea 236
superphil06 1:e3cb81b3cbea 237 }
superphil06 1:e3cb81b3cbea 238 }
superphil06 1:e3cb81b3cbea 239 }
superphil06 1:e3cb81b3cbea 240
superphil06 1:e3cb81b3cbea 241 }
superphil06 1:e3cb81b3cbea 242
superphil06 1:e3cb81b3cbea 243
superphil06 1:e3cb81b3cbea 244
superphil06 1:e3cb81b3cbea 245
superphil06 0:8871b0c9af3b 246 int main() {
superphil06 0:8871b0c9af3b 247
superphil06 0:8871b0c9af3b 248 char cChoix=0;
superphil06 1:e3cb81b3cbea 249 int iVal,iRefPWM;
superphil06 0:8871b0c9af3b 250
superphil06 0:8871b0c9af3b 251
superphil06 0:8871b0c9af3b 252 Read_File_Data("/local/persist.txt"); // read persistent data from text file
superphil06 1:e3cb81b3cbea 253 //Write_File_Data("/local/persist.txt"); // write persistent data to text file
superphil06 1:e3cb81b3cbea 254 //***************************************** web section ********************************************/
superphil06 1:e3cb81b3cbea 255 Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function
superphil06 1:e3cb81b3cbea 256 Thread WebThread(Web_Server_Thread);// create and launch web server thread
superphil06 1:e3cb81b3cbea 257 //******************************************* end web section ************************************* /
superphil06 0:8871b0c9af3b 258
superphil06 0:8871b0c9af3b 259
superphil06 1:e3cb81b3cbea 260 //ma_chaine3 = Gen_HtmlCode_From_File("/local/pagecgi2.htm",tab_balise,5);// read and localise ^VARDEF[X] tag
superphil06 1:e3cb81b3cbea 261 Gen_HtmlCode_From_File("/local/pagecgi2.htm",tab_balise,5);// read and localise ^VARDEF[X] tag in empty html file
superphil06 0:8871b0c9af3b 262
superphil06 0:8871b0c9af3b 263 IT_Timer_Gaz.attach_us(&MyITGaz, 10000);// install timer it each 10ms
superphil06 0:8871b0c9af3b 264 IT_Speed.attach_us(&MyITSpeed, 100000);// install timer it each 10ms
superphil06 0:8871b0c9af3b 265 TopHall.rise(&SpeedCount);
superphil06 0:8871b0c9af3b 266
superphil06 0:8871b0c9af3b 267 pc.printf(" programme scooter mbed \n");
superphil06 0:8871b0c9af3b 268 MyPLD.write(0);// set initial PWM ref=0
superphil06 0:8871b0c9af3b 269 ValidPWM.write(1);// enable pwm generator
superphil06 0:8871b0c9af3b 270
superphil06 1:e3cb81b3cbea 271 can_port.frequency(125000); //on impose une fréquence commune pour etre s’incroniser
superphil06 1:e3cb81b3cbea 272 //can_port.attach(&CAN_REC_IRQ); // install CAN BUS IRQ on data received
superphil06 1:e3cb81b3cbea 273 bCan_Active=true;
superphil06 1:e3cb81b3cbea 274 Thread CanThread(CAN_REC_THREAD);// create and launch can receiver thread
superphil06 1:e3cb81b3cbea 275
superphil06 1:e3cb81b3cbea 276
superphil06 0:8871b0c9af3b 277 while(cChoix!='q' and cChoix!='Q')
superphil06 0:8871b0c9af3b 278 {pc.printf(" veuillez saisir un choix parmi la liste proposee: \n");
superphil06 0:8871b0c9af3b 279 pc.printf(" a:saisie consigne pwm \n");
superphil06 0:8871b0c9af3b 280 pc.printf(" b:lecture registre PLD \n");
superphil06 0:8871b0c9af3b 281 pc.printf(" c:lecture ADC 4 voies \n");
superphil06 0:8871b0c9af3b 282 pc.printf(" d:calibration poignee Gaz \n");
superphil06 0:8871b0c9af3b 283 pc.printf(" e:affichage vitesse \n");
superphil06 0:8871b0c9af3b 284 pc.printf(" q:quitter \n");
superphil06 1:e3cb81b3cbea 285 /************* multithreading : main thread need to sleep in order to allow web response */
superphil06 1:e3cb81b3cbea 286 while (pc.readable()==0) // determine if char availabler
superphil06 0:8871b0c9af3b 287 {Thread::wait(10);} // wait 10 until char available on serial input
superphil06 1:e3cb81b3cbea 288 /************* end of main thread sleep ****************/
superphil06 0:8871b0c9af3b 289 pc.scanf(" %c",&cChoix);
superphil06 0:8871b0c9af3b 290 switch (cChoix){
superphil06 0:8871b0c9af3b 291 case 'a': pc.printf(" veuillez saisir une consigne pwm entre 0 et 255 \n");
superphil06 0:8871b0c9af3b 292 pc.scanf("%d",&iRefPWM);
superphil06 0:8871b0c9af3b 293 if (iRefPWM>255) iRefPWM=255;
superphil06 0:8871b0c9af3b 294 if (iRefPWM<0) iRefPWM=0;
superphil06 0:8871b0c9af3b 295 MyPLD.write((unsigned char)iRefPWM);// update pwm ref on pld
superphil06 0:8871b0c9af3b 296 break;
superphil06 0:8871b0c9af3b 297 case 'b': iVal=MyPLD.read();// read PLd internal register
superphil06 0:8871b0c9af3b 298 pc.printf("valeur lue dans le registre PLD: %02x \n",iVal);
superphil06 0:8871b0c9af3b 299 pc.printf("secteur hall: %01d \n",iVal&0x07);
superphil06 0:8871b0c9af3b 300 pc.printf("direction:%01d \n",(iVal&0x08)>>3);
superphil06 0:8871b0c9af3b 301 pc.printf("flta:%01d \n",(iVal&0x10)>>4);
superphil06 0:8871b0c9af3b 302 pc.printf("brake:%01d \n",(iVal&0x20)>>5);
superphil06 0:8871b0c9af3b 303 pc.printf("overCurrent:%01d \n",(iVal&0x40)>>6);
superphil06 0:8871b0c9af3b 304 break;
superphil06 0:8871b0c9af3b 305
superphil06 0:8871b0c9af3b 306 case 'c': // lecture ADC 4 voies
superphil06 0:8871b0c9af3b 307 fGaz=Gaz.read()*100;
superphil06 0:8871b0c9af3b 308 fTemp=Temp.read()*100;
superphil06 0:8871b0c9af3b 309 fBat=Bat.read()*100;
superphil06 0:8871b0c9af3b 310 fIdc=Idc.read()*100;
superphil06 0:8871b0c9af3b 311 pc.printf("valeur gaz:%3f Temperature:%3f Vbat:%3f Idc:%3f \n",fGaz,fTemp,fBat,fIdc);
superphil06 1:e3cb81b3cbea 312 pc.printf("valeur temp:%3f \n\r",fTemp*5.1282-53.53);
superphil06 0:8871b0c9af3b 313 break;
superphil06 0:8871b0c9af3b 314
superphil06 0:8871b0c9af3b 315 case 'd': // calibration poignée gaz
superphil06 0:8871b0c9af3b 316 Calibrate_Gaz();
superphil06 0:8871b0c9af3b 317 break;
superphil06 0:8871b0c9af3b 318 case 'e': // display actual speed m/h
superphil06 0:8871b0c9af3b 319 pc.printf("vitesse=%f m/h \n",fSpeed);
superphil06 0:8871b0c9af3b 320 break;
superphil06 0:8871b0c9af3b 321
superphil06 0:8871b0c9af3b 322 case 'q': break;
superphil06 0:8871b0c9af3b 323 }
superphil06 0:8871b0c9af3b 324
superphil06 0:8871b0c9af3b 325 /*for (iIndex=0;iIndex<=255;iIndex++)
superphil06 0:8871b0c9af3b 326 {MyPLD.write((unsigned char) iIndex);
superphil06 0:8871b0c9af3b 327 // iVal=MyPLD.read();
superphil06 0:8871b0c9af3b 328
superphil06 0:8871b0c9af3b 329 wait_ms(0.02);
superphil06 0:8871b0c9af3b 330 }*/
superphil06 0:8871b0c9af3b 331 }
superphil06 0:8871b0c9af3b 332 IT_Timer_Gaz.detach();// uninstall timer interrupt
superphil06 0:8871b0c9af3b 333 IT_Speed.detach();// uninstall timer interrupt
superphil06 0:8871b0c9af3b 334 MyPLD.write(0);// stop motor before exiting
superphil06 0:8871b0c9af3b 335 ValidPWM.write(0);// disable pwm generator
superphil06 1:e3cb81b3cbea 336 DeInit_Web_Server();
superphil06 1:e3cb81b3cbea 337 bCan_Active=false;
superphil06 1:e3cb81b3cbea 338 CanThread=false;// close can received thread
superphil06 0:8871b0c9af3b 339 pc.printf(" fin programme scooter mbed \n");
superphil06 0:8871b0c9af3b 340 }