TP OS12-MT

Dependencies:   mbed C12832

Committer:
Etudiant_RT9749
Date:
Mon Mar 25 11:39:30 2019 +0000
Revision:
0:576717be4fce
Test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Etudiant_RT9749 0:576717be4fce 1 #include "mbed.h"
Etudiant_RT9749 0:576717be4fce 2 #include "C12832.h"
Etudiant_RT9749 0:576717be4fce 3
Etudiant_RT9749 0:576717be4fce 4 Ticker Acquisition;
Etudiant_RT9749 0:576717be4fce 5 AnalogOut Out(p18);
Etudiant_RT9749 0:576717be4fce 6 AnalogIn In(p17);
Etudiant_RT9749 0:576717be4fce 7
Etudiant_RT9749 0:576717be4fce 8 C12832 lcd(p5, p7, p6, p8, p11);
Etudiant_RT9749 0:576717be4fce 9
Etudiant_RT9749 0:576717be4fce 10 static unsigned char Echant_Ok = 0;
Etudiant_RT9749 0:576717be4fce 11
Etudiant_RT9749 0:576717be4fce 12 const int C_continu = 2048;
Etudiant_RT9749 0:576717be4fce 13
Etudiant_RT9749 0:576717be4fce 14 char buffer_can_logarithmique[100] = {};
Etudiant_RT9749 0:576717be4fce 15 char buffer_in[100] = {};
Etudiant_RT9749 0:576717be4fce 16 char buffer_filtre[100] = {};
Etudiant_RT9749 0:576717be4fce 17
Etudiant_RT9749 0:576717be4fce 18 //static float a[] = {};
Etudiant_RT9749 0:576717be4fce 19 //static float b[] = {};
Etudiant_RT9749 0:576717be4fce 20
Etudiant_RT9749 0:576717be4fce 21 static float En[2] = {0,0};
Etudiant_RT9749 0:576717be4fce 22 static float Sn[3] = {0,0,0};
Etudiant_RT9749 0:576717be4fce 23
Etudiant_RT9749 0:576717be4fce 24 /**
Etudiant_RT9749 0:576717be4fce 25 Taille des variables en memoire :
Etudiant_RT9749 0:576717be4fce 26 * short int = 2 octets = 8 bits
Etudiant_RT9749 0:576717be4fce 27 * int = 4 octets = 16 bits
Etudiant_RT9749 0:576717be4fce 28 * float = 4 octets = 32 bits
Etudiant_RT9749 0:576717be4fce 29 * double = 8 octect = 256 bits
Etudiant_RT9749 0:576717be4fce 30 **/
Etudiant_RT9749 0:576717be4fce 31
Etudiant_RT9749 0:576717be4fce 32
Etudiant_RT9749 0:576717be4fce 33 // Fonction Echantillonnage
Etudiant_RT9749 0:576717be4fce 34 void Echantillonage() {
Etudiant_RT9749 0:576717be4fce 35 Echant_Ok=1;
Etudiant_RT9749 0:576717be4fce 36 }
Etudiant_RT9749 0:576717be4fce 37
Etudiant_RT9749 0:576717be4fce 38 double CAN_log_func(int x){
Etudiant_RT9749 0:576717be4fce 39 double y = 0;
Etudiant_RT9749 0:576717be4fce 40
Etudiant_RT9749 0:576717be4fce 41 if (x > 0 && x <= 32){
Etudiant_RT9749 0:576717be4fce 42 y = x * 16;
Etudiant_RT9749 0:576717be4fce 43 } else if (x > 0 && x <= 32){
Etudiant_RT9749 0:576717be4fce 44 y = x * 8 - 1/8;
Etudiant_RT9749 0:576717be4fce 45 } else if (x > 32 && x <= 64){
Etudiant_RT9749 0:576717be4fce 46 y = x * 4 + 1/4;
Etudiant_RT9749 0:576717be4fce 47 } else if (x > 64 && x <= 128){
Etudiant_RT9749 0:576717be4fce 48 y = x * 2 + 3/8;
Etudiant_RT9749 0:576717be4fce 49 } else if (x > 128 && x <= 256){
Etudiant_RT9749 0:576717be4fce 50 y = x + 1/2;
Etudiant_RT9749 0:576717be4fce 51 } else if (x > 256 && x <= 512){
Etudiant_RT9749 0:576717be4fce 52 y = x * 1/2 + 5/8;
Etudiant_RT9749 0:576717be4fce 53 } else if (x > 512 && x <= 1024){
Etudiant_RT9749 0:576717be4fce 54 y = x * 1/4 + 3/4;
Etudiant_RT9749 0:576717be4fce 55 }
Etudiant_RT9749 0:576717be4fce 56 return y;
Etudiant_RT9749 0:576717be4fce 57 }
Etudiant_RT9749 0:576717be4fce 58
Etudiant_RT9749 0:576717be4fce 59 float Filtrage(int x){
Etudiant_RT9749 0:576717be4fce 60 return (0.1*En[0]-0.0897*En[1]+1.55952*Sn[1]-0.6065*Sn[2]);
Etudiant_RT9749 0:576717be4fce 61 }
Etudiant_RT9749 0:576717be4fce 62
Etudiant_RT9749 0:576717be4fce 63 int main(){
Etudiant_RT9749 0:576717be4fce 64 // Declanchement de la fonction d'échantillonnage
Etudiant_RT9749 0:576717be4fce 65 Acquisition.attach_us(&Echantillonage,125);
Etudiant_RT9749 0:576717be4fce 66
Etudiant_RT9749 0:576717be4fce 67 // Boucle infini
Etudiant_RT9749 0:576717be4fce 68 while (true) {
Etudiant_RT9749 0:576717be4fce 69 if (Echant_Ok == 1) {
Etudiant_RT9749 0:576717be4fce 70 // Quantification
Etudiant_RT9749 0:576717be4fce 71 int entree_uni = In.read_u16();
Etudiant_RT9749 0:576717be4fce 72 int entree_log = CAN_log_func(entree_uni - C_continu);
Etudiant_RT9749 0:576717be4fce 73
Etudiant_RT9749 0:576717be4fce 74 En[1] = En[0];
Etudiant_RT9749 0:576717be4fce 75 En[0] = entree_log;
Etudiant_RT9749 0:576717be4fce 76
Etudiant_RT9749 0:576717be4fce 77 Sn[2] = Sn[1];
Etudiant_RT9749 0:576717be4fce 78 Sn[1] = Sn[0];
Etudiant_RT9749 0:576717be4fce 79 Sn[0] = Filtrage(En[0]);
Etudiant_RT9749 0:576717be4fce 80
Etudiant_RT9749 0:576717be4fce 81 sprintf(buffer_in, "Valeur : %d | %d", entree_uni, (entree_uni - C_continu));
Etudiant_RT9749 0:576717be4fce 82 sprintf(buffer_can_logarithmique, "Quantification : %d", entree_log);
Etudiant_RT9749 0:576717be4fce 83 sprintf(buffer_filtre, "En=%d | Sn=%f", entree_log, Filtrage(entree_log));
Etudiant_RT9749 0:576717be4fce 84
Etudiant_RT9749 0:576717be4fce 85 lcd.locate(0,3);
Etudiant_RT9749 0:576717be4fce 86 lcd.printf(buffer_in);
Etudiant_RT9749 0:576717be4fce 87
Etudiant_RT9749 0:576717be4fce 88 lcd.locate(0,11);
Etudiant_RT9749 0:576717be4fce 89 lcd.printf(buffer_can_logarithmique);
Etudiant_RT9749 0:576717be4fce 90
Etudiant_RT9749 0:576717be4fce 91 lcd.locate(0,19);
Etudiant_RT9749 0:576717be4fce 92 lcd.printf(buffer_filtre);
Etudiant_RT9749 0:576717be4fce 93
Etudiant_RT9749 0:576717be4fce 94 }
Etudiant_RT9749 0:576717be4fce 95 Echant_Ok = 0;
Etudiant_RT9749 0:576717be4fce 96 }
Etudiant_RT9749 0:576717be4fce 97 }