apres v5

Dependencies:   mbed bloc_io mbed-rtos html EthernetInterface

Committer:
thomascerruti
Date:
Tue Sep 28 15:04:04 2021 +0000
Revision:
1:140b1686bf3f
Parent:
0:e30c9ba95bd4
apres validation v5;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomascerruti 1:140b1686bf3f 1
superphil06 0:e30c9ba95bd4 2
superphil06 0:e30c9ba95bd4 3 //#include "EthernetInterface.h"
superphil06 0:e30c9ba95bd4 4 #include <stdlib.h>
superphil06 0:e30c9ba95bd4 5 #include <string.h>
superphil06 0:e30c9ba95bd4 6 #include "mbed.h"
superphil06 0:e30c9ba95bd4 7 #include "rtos.h" // need for main thread sleep
superphil06 0:e30c9ba95bd4 8 #include "html.h" // need for html patch working with web server
superphil06 0:e30c9ba95bd4 9 #include "bloc_io.h"
superphil06 0:e30c9ba95bd4 10 #define RADIUS 0.2F // wheel size
superphil06 0:e30c9ba95bd4 11 #define NBPOLES 8 // magnetic pole number
superphil06 0:e30c9ba95bd4 12 #define DELTA_T 0.1F // speed measurement counting period
thomascerruti 1:140b1686bf3f 13 DigitalOut valid_PWM(p21);
superphil06 0:e30c9ba95bd4 14
superphil06 0:e30c9ba95bd4 15 Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD
superphil06 0:e30c9ba95bd4 16 // analog input connected to mbed
superphil06 0:e30c9ba95bd4 17 // valid pmw mbed pin
superphil06 0:e30c9ba95bd4 18 Serial pc(USBTX, USBRX); // tx, rx
superphil06 0:e30c9ba95bd4 19 // Top_Hall Pin
superphil06 0:e30c9ba95bd4 20
superphil06 0:e30c9ba95bd4 21
superphil06 0:e30c9ba95bd4 22
superphil06 0:e30c9ba95bd4 23
superphil06 0:e30c9ba95bd4 24 /************ persistent file parameters section *****************/
superphil06 0:e30c9ba95bd4 25 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
superphil06 0:e30c9ba95bd4 26
superphil06 0:e30c9ba95bd4 27
superphil06 0:e30c9ba95bd4 28
superphil06 0:e30c9ba95bd4 29
superphil06 0:e30c9ba95bd4 30
superphil06 0:e30c9ba95bd4 31
superphil06 0:e30c9ba95bd4 32
superphil06 0:e30c9ba95bd4 33 /********************* web server section **********************************/
superphil06 0:e30c9ba95bd4 34
superphil06 0:e30c9ba95bd4 35 var_field_t tab_balise[10]; //une balise est présente dans le squelette
superphil06 0:e30c9ba95bd4 36 int giCounter=0;// acces counting
superphil06 0:e30c9ba95bd4 37
superphil06 0:e30c9ba95bd4 38
superphil06 0:e30c9ba95bd4 39 /*********************** can bus section ************/
superphil06 0:e30c9ba95bd4 40 // determine message ID used to send Gaz ref over can bus
superphil06 0:e30c9ba95bd4 41 #define _CAN_DEBUG // used to debug can bus activity
superphil06 0:e30c9ba95bd4 42 //#define USE_CAN_REF // uncomment to receive gaz ref over can_bus
superphil06 0:e30c9ba95bd4 43 CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield
superphil06 0:e30c9ba95bd4 44 bool bCan_Active=false;
superphil06 0:e30c9ba95bd4 45
superphil06 0:e30c9ba95bd4 46
superphil06 0:e30c9ba95bd4 47
superphil06 0:e30c9ba95bd4 48 DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/
superphil06 0:e30c9ba95bd4 49 DigitalOut led2(LED2);
superphil06 0:e30c9ba95bd4 50 DigitalOut led3(LED3); // blink when can message is sent
superphil06 0:e30c9ba95bd4 51 DigitalOut led4(LED4); // blink when can message is received
superphil06 0:e30c9ba95bd4 52
superphil06 0:e30c9ba95bd4 53
superphil06 0:e30c9ba95bd4 54
superphil06 0:e30c9ba95bd4 55
superphil06 0:e30c9ba95bd4 56
superphil06 0:e30c9ba95bd4 57 //************ local function prototypes *******************
superphil06 0:e30c9ba95bd4 58
thomascerruti 1:140b1686bf3f 59 void init(void);
thomascerruti 1:140b1686bf3f 60 void deinit(void);
superphil06 0:e30c9ba95bd4 61
superphil06 0:e30c9ba95bd4 62
superphil06 0:e30c9ba95bd4 63
superphil06 0:e30c9ba95bd4 64
superphil06 0:e30c9ba95bd4 65
superphil06 0:e30c9ba95bd4 66 /**************** Read persistent data from text file located on local file system ****************/
superphil06 0:e30c9ba95bd4 67
superphil06 0:e30c9ba95bd4 68
superphil06 0:e30c9ba95bd4 69
superphil06 0:e30c9ba95bd4 70 /**************** write persitant data to text file located on local file system ****************/
superphil06 0:e30c9ba95bd4 71
superphil06 0:e30c9ba95bd4 72
superphil06 0:e30c9ba95bd4 73
superphil06 0:e30c9ba95bd4 74
superphil06 0:e30c9ba95bd4 75
superphil06 0:e30c9ba95bd4 76
superphil06 0:e30c9ba95bd4 77 //************** calibation gaz function needed to record min_gaz and max_gaz value to persistent text file ******************
superphil06 0:e30c9ba95bd4 78
superphil06 0:e30c9ba95bd4 79
superphil06 0:e30c9ba95bd4 80 // ************top hall counting interrupt needed for speed measurement
superphil06 0:e30c9ba95bd4 81
superphil06 0:e30c9ba95bd4 82
superphil06 0:e30c9ba95bd4 83 //********************** timer interrupt for speed measurement each 100ms *************************
superphil06 0:e30c9ba95bd4 84
superphil06 0:e30c9ba95bd4 85
superphil06 0:e30c9ba95bd4 86
superphil06 0:e30c9ba95bd4 87
superphil06 0:e30c9ba95bd4 88
superphil06 0:e30c9ba95bd4 89
superphil06 0:e30c9ba95bd4 90 //********************* Timer Interrupt for gaz ref management each 10ms ********************
superphil06 0:e30c9ba95bd4 91
superphil06 0:e30c9ba95bd4 92
superphil06 0:e30c9ba95bd4 93
superphil06 0:e30c9ba95bd4 94 /********* main cgi function used to patch data to the web server thread **********************************/
superphil06 0:e30c9ba95bd4 95 void CGI_Function(void) // cgi function that patch web data to empty web page
superphil06 0:e30c9ba95bd4 96 { char ma_chaine4[20]={};// needed to form html response
superphil06 0:e30c9ba95bd4 97
superphil06 0:e30c9ba95bd4 98 }
superphil06 0:e30c9ba95bd4 99
superphil06 0:e30c9ba95bd4 100
superphil06 0:e30c9ba95bd4 101 /*********************** CAN BUS SECTION **********************/
superphil06 0:e30c9ba95bd4 102
superphil06 0:e30c9ba95bd4 103
superphil06 0:e30c9ba95bd4 104
superphil06 0:e30c9ba95bd4 105 void CAN_REC_THREAD(void const *args)
superphil06 0:e30c9ba95bd4 106 { int iCount,iError;
superphil06 0:e30c9ba95bd4 107
superphil06 0:e30c9ba95bd4 108 while (bCan_Active)
superphil06 0:e30c9ba95bd4 109 {Thread::wait(100);// wait 100ms
superphil06 0:e30c9ba95bd4 110 // code todo
superphil06 0:e30c9ba95bd4 111
superphil06 0:e30c9ba95bd4 112 }
superphil06 0:e30c9ba95bd4 113
superphil06 0:e30c9ba95bd4 114 }
superphil06 0:e30c9ba95bd4 115
superphil06 0:e30c9ba95bd4 116
superphil06 0:e30c9ba95bd4 117
superphil06 0:e30c9ba95bd4 118 //*************************** main function *****************************************
superphil06 0:e30c9ba95bd4 119 int main() {
thomascerruti 1:140b1686bf3f 120 init();
thomascerruti 1:140b1686bf3f 121 char cChoix=0;
thomascerruti 1:140b1686bf3f 122 while(cChoix!='q' and cChoix!='Q')
thomascerruti 1:140b1686bf3f 123 {
thomascerruti 1:140b1686bf3f 124 pc.printf(" veuillez saisir un choix parmi la liste proposee: \n");
thomascerruti 1:140b1686bf3f 125 pc.printf(" a:saisie consigne pwm \n");
thomascerruti 1:140b1686bf3f 126 pc.printf(" q:quitter \n");
superphil06 0:e30c9ba95bd4 127
thomascerruti 1:140b1686bf3f 128 pc.scanf(" %c",&cChoix);
thomascerruti 1:140b1686bf3f 129 int PWM;
superphil06 0:e30c9ba95bd4 130
superphil06 0:e30c9ba95bd4 131
superphil06 0:e30c9ba95bd4 132 switch (cChoix){
superphil06 0:e30c9ba95bd4 133 case 'a':
thomascerruti 1:140b1686bf3f 134
thomascerruti 1:140b1686bf3f 135 printf("donnez une valeur de pwm : \n\r");
thomascerruti 1:140b1686bf3f 136 pc.scanf("%d", &PWM);
thomascerruti 1:140b1686bf3f 137 if (PWM < 0)
thomascerruti 1:140b1686bf3f 138 {
thomascerruti 1:140b1686bf3f 139 PWM = 0;
thomascerruti 1:140b1686bf3f 140 }
thomascerruti 1:140b1686bf3f 141 if (PWM > 255)
thomascerruti 1:140b1686bf3f 142 {
thomascerruti 1:140b1686bf3f 143 PWM = 255;
thomascerruti 1:140b1686bf3f 144 }
thomascerruti 1:140b1686bf3f 145 printf(" valeur de pwm = %d \n\r", PWM);
thomascerruti 1:140b1686bf3f 146 MyPLD.write(PWM);
thomascerruti 1:140b1686bf3f 147
thomascerruti 1:140b1686bf3f 148
superphil06 0:e30c9ba95bd4 149 break;
superphil06 0:e30c9ba95bd4 150 case 'q':
thomascerruti 1:140b1686bf3f 151 deinit();
superphil06 0:e30c9ba95bd4 152 break;
superphil06 0:e30c9ba95bd4 153 }
superphil06 0:e30c9ba95bd4 154 } // end while
superphil06 0:e30c9ba95bd4 155
superphil06 0:e30c9ba95bd4 156 //************** thread deinit *********************
superphil06 0:e30c9ba95bd4 157 //DeInit_Web_Server();
superphil06 0:e30c9ba95bd4 158 //bCan_Active=false;
superphil06 0:e30c9ba95bd4 159 //CanThread=false;// close can received thread
thomascerruti 1:140b1686bf3f 160
thomascerruti 1:140b1686bf3f 161 }// end main
thomascerruti 1:140b1686bf3f 162
thomascerruti 1:140b1686bf3f 163 void init()
thomascerruti 1:140b1686bf3f 164 {
thomascerruti 1:140b1686bf3f 165 valid_PWM.write(0);
thomascerruti 1:140b1686bf3f 166 MyPLD.write(0);
thomascerruti 1:140b1686bf3f 167 valid_PWM.write(1);
thomascerruti 1:140b1686bf3f 168 }
thomascerruti 1:140b1686bf3f 169 void deinit()
thomascerruti 1:140b1686bf3f 170 {
thomascerruti 1:140b1686bf3f 171 MyPLD.write(0);
thomascerruti 1:140b1686bf3f 172 valid_PWM.write(0);
thomascerruti 1:140b1686bf3f 173 }