Kostiantyn Vasko / Mbed 2 deprecated Emiter_ECG_455kHz

Dependencies:   mbed FastPWM

Committer:
NTesla
Date:
Wed Oct 24 13:20:49 2018 +0000
Revision:
0:7ee4334a99fc
Child:
1:616a5dd8ec34
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NTesla 0:7ee4334a99fc 1 #include "mbed.h"
NTesla 0:7ee4334a99fc 2 #include "FastPWM.h"
NTesla 0:7ee4334a99fc 3 // https://developer.mbed.org/forum/electronics/topic/15346/
NTesla 0:7ee4334a99fc 4 //------------------------------------
NTesla 0:7ee4334a99fc 5 //Emission pgrm for the patient transmetting device. It uses the source code
NTesla 0:7ee4334a99fc 6 //originally made for Arduino. It has been first designed by S.Sahuguede
NTesla 0:7ee4334a99fc 7 //------------------------------------
NTesla 0:7ee4334a99fc 8 /* 17.10.2018 sketch modified by Kostiantyn Vasko together with Borys Shtanhei
NTesla 0:7ee4334a99fc 9 * Transmitting by IR LED with 38kHz Freq FOR STM32
NTesla 0:7ee4334a99fc 10 * Important pins:
NTesla 0:7ee4334a99fc 11 * D1 - Tx
NTesla 0:7ee4334a99fc 12 * D0 - Rx
NTesla 0:7ee4334a99fc 13 * D10 - PWM
NTesla 0:7ee4334a99fc 14 * A0 - Analog input for ECG
NTesla 0:7ee4334a99fc 15 */
NTesla 0:7ee4334a99fc 16 //Serial Com defined for Tx=D8 and Rx=D2 at 4800 bauds
NTesla 0:7ee4334a99fc 17 Serial Serial2(D8,D2,38400);
NTesla 0:7ee4334a99fc 18
NTesla 0:7ee4334a99fc 19 //Initializing of clock Output
NTesla 0:7ee4334a99fc 20 FastPWM mypwm(D10,1);
NTesla 0:7ee4334a99fc 21
NTesla 0:7ee4334a99fc 22 //init variables
NTesla 0:7ee4334a99fc 23 int cptmesure = 0;
NTesla 0:7ee4334a99fc 24 unsigned int analogin;
NTesla 0:7ee4334a99fc 25
NTesla 0:7ee4334a99fc 26 //VALUE TO MODIFY BY PATIENT
NTesla 0:7ee4334a99fc 27 unsigned int patient=2;
NTesla 0:7ee4334a99fc 28
NTesla 0:7ee4334a99fc 29 //creation of variables for transmission control
NTesla 0:7ee4334a99fc 30 int verif;
NTesla 0:7ee4334a99fc 31
NTesla 0:7ee4334a99fc 32 AnalogIn X(A0);
NTesla 0:7ee4334a99fc 33
NTesla 0:7ee4334a99fc 34 int main() {
NTesla 0:7ee4334a99fc 35 //pwm_io(16, 0.5); //26.041 us with a duty cycle of 50% ==> Here I get 38kHz as Output with 16µs...
NTesla 0:7ee4334a99fc 36
NTesla 0:7ee4334a99fc 37 //Bytes variables which gonna be sent
NTesla 0:7ee4334a99fc 38 unsigned int trame1,trame2,trame3,trame8, trame9;
NTesla 0:7ee4334a99fc 39
NTesla 0:7ee4334a99fc 40 //Clock settings for 38kHz
NTesla 0:7ee4334a99fc 41 //mypwm.period_us(26);//26
NTesla 0:7ee4334a99fc 42 // mypwm.pulsewidth_us(13);//13
NTesla 0:7ee4334a99fc 43
NTesla 0:7ee4334a99fc 44 //Serial Com data sent
NTesla 0:7ee4334a99fc 45 uint8_t TrameTab[6];
NTesla 0:7ee4334a99fc 46
NTesla 0:7ee4334a99fc 47 //Clock settings for 455kHz
NTesla 0:7ee4334a99fc 48 mypwm.period_us(2.1978);
NTesla 0:7ee4334a99fc 49 mypwm.pulsewidth_us(1.0989);//Duty-Cycle 50% here
NTesla 0:7ee4334a99fc 50 while(1)
NTesla 0:7ee4334a99fc 51 {
NTesla 0:7ee4334a99fc 52 analogin = (int16_t) (65535 * X.read());// Read ECG signal and transforming into digit.
NTesla 0:7ee4334a99fc 53
NTesla 0:7ee4334a99fc 54 trame2=(analogin & 0xFF00) >> 8;//mask 1111 1111 0000 0000 (ECG signal 16 bit)
NTesla 0:7ee4334a99fc 55 trame3=(analogin & 0xFF);//mask 0000 0000 1111 1111
NTesla 0:7ee4334a99fc 56
NTesla 0:7ee4334a99fc 57 //increment of measurement: avoids the redundancy of the display on the server
NTesla 0:7ee4334a99fc 58 cptmesure++;
NTesla 0:7ee4334a99fc 59 if(cptmesure==8)
NTesla 0:7ee4334a99fc 60 {
NTesla 0:7ee4334a99fc 61 cptmesure=0;
NTesla 0:7ee4334a99fc 62 }
NTesla 0:7ee4334a99fc 63
NTesla 0:7ee4334a99fc 64 verif = (trame2 << 3) + cptmesure ;
NTesla 0:7ee4334a99fc 65
NTesla 0:7ee4334a99fc 66 //first frame: patient + verif (2 bits high)
NTesla 0:7ee4334a99fc 67 trame1= (patient << 4) + ((verif & 0x700)>>7);//mask 111 0000 0000
NTesla 0:7ee4334a99fc 68
NTesla 0:7ee4334a99fc 69 trame8= (verif & 0xFF);//mask 1111 1111
NTesla 0:7ee4334a99fc 70
NTesla 0:7ee4334a99fc 71 //fifth frame: patient + increment measurement
NTesla 0:7ee4334a99fc 72 trame9= (patient << 4) + (cptmesure << 1);
NTesla 0:7ee4334a99fc 73
NTesla 0:7ee4334a99fc 74 //We fill the table which gonna be sent
NTesla 0:7ee4334a99fc 75 TrameTab[0] = 255;
NTesla 0:7ee4334a99fc 76 TrameTab[1] = trame1;
NTesla 0:7ee4334a99fc 77
NTesla 0:7ee4334a99fc 78 TrameTab[2] = trame2;
NTesla 0:7ee4334a99fc 79 TrameTab[3] = trame3;
NTesla 0:7ee4334a99fc 80
NTesla 0:7ee4334a99fc 81 TrameTab[4] = trame8;
NTesla 0:7ee4334a99fc 82 TrameTab[5] = trame9;
NTesla 0:7ee4334a99fc 83
NTesla 0:7ee4334a99fc 84 //We sent the table through the serial port
NTesla 0:7ee4334a99fc 85 Serial2.write(TrameTab,6,0,0);
NTesla 0:7ee4334a99fc 86 //Serial.write pour envoyer l'information sous 8 bits. Serial.print envoi un nombre chiffre par chiffre à utiliser pour avoir un affichage sur le moniteur.
NTesla 0:7ee4334a99fc 87
NTesla 0:7ee4334a99fc 88 wait(0.0025);
NTesla 0:7ee4334a99fc 89 }
NTesla 0:7ee4334a99fc 90 }