Etienne

Dependencies:   mbed

Committer:
stersky
Date:
Tue Feb 12 14:39:49 2019 +0000
Revision:
0:c25758eee70f
Etienne

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stersky 0:c25758eee70f 1 #include "mbed.h"
stersky 0:c25758eee70f 2
stersky 0:c25758eee70f 3 Timer chrono1;
stersky 0:c25758eee70f 4 Timer chrono2;
stersky 0:c25758eee70f 5 Timer chrono3;
stersky 0:c25758eee70f 6 Timer chrono4;
stersky 0:c25758eee70f 7 Timer chrono5;
stersky 0:c25758eee70f 8 Timer chrono6;
stersky 0:c25758eee70f 9
stersky 0:c25758eee70f 10 InterruptIn ch1(p23);
stersky 0:c25758eee70f 11 InterruptIn ch2(p24);
stersky 0:c25758eee70f 12 InterruptIn ch3(p25);
stersky 0:c25758eee70f 13 InterruptIn ch4(p26);
stersky 0:c25758eee70f 14 InterruptIn ch5(p29);
stersky 0:c25758eee70f 15 InterruptIn ch6(p30);
stersky 0:c25758eee70f 16
stersky 0:c25758eee70f 17 DigitalOut del(LED1);
stersky 0:c25758eee70f 18
stersky 0:c25758eee70f 19 Serial PC(USBTX, USBRX);
stersky 0:c25758eee70f 20
stersky 0:c25758eee70f 21 double tps_ch1=0,tps_ch2=0,tps_ch3=0,tps_ch4=0,tps_ch5=0,tps_ch6=0;
stersky 0:c25758eee70f 22
stersky 0:c25758eee70f 23 void initial_PWMIn(void);
stersky 0:c25758eee70f 24
stersky 0:c25758eee70f 25 void ch1_start() {
stersky 0:c25758eee70f 26 chrono1.start();
stersky 0:c25758eee70f 27 }
stersky 0:c25758eee70f 28
stersky 0:c25758eee70f 29 void ch1_stop()
stersky 0:c25758eee70f 30 {
stersky 0:c25758eee70f 31 chrono1.stop();
stersky 0:c25758eee70f 32 tps_ch1 = chrono1.read_us();
stersky 0:c25758eee70f 33 chrono1.reset();
stersky 0:c25758eee70f 34 }
stersky 0:c25758eee70f 35
stersky 0:c25758eee70f 36 void ch2_start() {
stersky 0:c25758eee70f 37 chrono2.start();
stersky 0:c25758eee70f 38 }
stersky 0:c25758eee70f 39
stersky 0:c25758eee70f 40 void ch2_stop()
stersky 0:c25758eee70f 41 {
stersky 0:c25758eee70f 42 chrono2.stop();
stersky 0:c25758eee70f 43 tps_ch2 = chrono2.read_us();
stersky 0:c25758eee70f 44 chrono2.reset();
stersky 0:c25758eee70f 45 }
stersky 0:c25758eee70f 46
stersky 0:c25758eee70f 47 void ch3_start() {
stersky 0:c25758eee70f 48 chrono3.start();
stersky 0:c25758eee70f 49 }
stersky 0:c25758eee70f 50
stersky 0:c25758eee70f 51 void ch3_stop()
stersky 0:c25758eee70f 52 {
stersky 0:c25758eee70f 53 chrono3.stop();
stersky 0:c25758eee70f 54 tps_ch3 = chrono3.read_us();
stersky 0:c25758eee70f 55 chrono3.reset();
stersky 0:c25758eee70f 56 }
stersky 0:c25758eee70f 57
stersky 0:c25758eee70f 58 void ch4_start() {
stersky 0:c25758eee70f 59 chrono4.start();
stersky 0:c25758eee70f 60 }
stersky 0:c25758eee70f 61
stersky 0:c25758eee70f 62 void ch4_stop()
stersky 0:c25758eee70f 63 {
stersky 0:c25758eee70f 64 chrono4.stop();
stersky 0:c25758eee70f 65 tps_ch4 = chrono4.read_us();
stersky 0:c25758eee70f 66 chrono4.reset();
stersky 0:c25758eee70f 67 }
stersky 0:c25758eee70f 68
stersky 0:c25758eee70f 69 void ch5_start() {
stersky 0:c25758eee70f 70 chrono5.start();
stersky 0:c25758eee70f 71 }
stersky 0:c25758eee70f 72
stersky 0:c25758eee70f 73 void ch5_stop()
stersky 0:c25758eee70f 74 {
stersky 0:c25758eee70f 75 chrono5.stop();
stersky 0:c25758eee70f 76 tps_ch5 = chrono5.read_us();
stersky 0:c25758eee70f 77 chrono5.reset();
stersky 0:c25758eee70f 78 }
stersky 0:c25758eee70f 79
stersky 0:c25758eee70f 80 void ch6_start() {
stersky 0:c25758eee70f 81 chrono6.start();
stersky 0:c25758eee70f 82 }
stersky 0:c25758eee70f 83
stersky 0:c25758eee70f 84 void ch6_stop()
stersky 0:c25758eee70f 85 {
stersky 0:c25758eee70f 86 chrono6.stop();
stersky 0:c25758eee70f 87 tps_ch6 = chrono6.read_us();
stersky 0:c25758eee70f 88 chrono6.reset();
stersky 0:c25758eee70f 89 }
stersky 0:c25758eee70f 90
stersky 0:c25758eee70f 91 int main() {
stersky 0:c25758eee70f 92
stersky 0:c25758eee70f 93 PC.baud(460800);
stersky 0:c25758eee70f 94 initial_PWMIn();
stersky 0:c25758eee70f 95
stersky 0:c25758eee70f 96 while(true) {
stersky 0:c25758eee70f 97 PC.printf("Tps haut entree 1:%.lfus\n\r",tps_ch1);
stersky 0:c25758eee70f 98 PC.printf("Tps haut entree 2:%.lfus\n\r",tps_ch2);
stersky 0:c25758eee70f 99 PC.printf("Tps haut entree 3:%.lfus\n\r",tps_ch3);
stersky 0:c25758eee70f 100 PC.printf("Tps haut entree 4:%.lfus\n\r",tps_ch4);
stersky 0:c25758eee70f 101 PC.printf("Tps haut entree 5:%.lfus\n\r",tps_ch5);
stersky 0:c25758eee70f 102 PC.printf("Tps haut entree 6:%.lfus\n\r\n\r",tps_ch6);
stersky 0:c25758eee70f 103
stersky 0:c25758eee70f 104 if(tps_ch6 > 1200) del = 1; //Allume la led si ch6 en position haute
stersky 0:c25758eee70f 105 if(tps_ch6 < 1200) del = 0; //Allume la led si ch6 en position basse
stersky 0:c25758eee70f 106 wait(0.2);
stersky 0:c25758eee70f 107 }
stersky 0:c25758eee70f 108 }
stersky 0:c25758eee70f 109
stersky 0:c25758eee70f 110 void initial_PWMIn(void)
stersky 0:c25758eee70f 111 {
stersky 0:c25758eee70f 112 ch1.rise(&ch1_start);
stersky 0:c25758eee70f 113 ch1.fall(&ch1_stop);
stersky 0:c25758eee70f 114
stersky 0:c25758eee70f 115 ch2.rise(&ch2_start);
stersky 0:c25758eee70f 116 ch2.fall(&ch2_stop);
stersky 0:c25758eee70f 117
stersky 0:c25758eee70f 118 ch3.rise(&ch3_start);
stersky 0:c25758eee70f 119 ch3.fall(&ch3_stop);
stersky 0:c25758eee70f 120
stersky 0:c25758eee70f 121 ch4.rise(&ch4_start);
stersky 0:c25758eee70f 122 ch4.fall(&ch4_stop);
stersky 0:c25758eee70f 123
stersky 0:c25758eee70f 124 ch5.rise(&ch5_start);
stersky 0:c25758eee70f 125 ch5.fall(&ch5_stop);
stersky 0:c25758eee70f 126
stersky 0:c25758eee70f 127 ch6.rise(&ch6_start);
stersky 0:c25758eee70f 128 ch6.fall(&ch6_stop);
stersky 0:c25758eee70f 129
stersky 0:c25758eee70f 130 chrono1.reset();
stersky 0:c25758eee70f 131 chrono2.reset();
stersky 0:c25758eee70f 132 chrono3.reset();
stersky 0:c25758eee70f 133 chrono4.reset();
stersky 0:c25758eee70f 134 chrono5.reset();
stersky 0:c25758eee70f 135 chrono6.reset();
stersky 0:c25758eee70f 136 }