Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Calcul_dprt by
Revision 1:8cefb1625296, committed 2016-06-08
- Comitter:
- Paolo804
- Date:
- Wed Jun 08 13:59:44 2016 +0000
- Parent:
- 0:93ef99ee20e4
- Commit message:
- Version dev 1 ; -detection mot avec seuil auto sur une trame; -essai distance avec mesure min et max sur une trame
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jun 08 12:03:06 2016 +0000
+++ b/main.cpp Wed Jun 08 13:59:44 2016 +0000
@@ -1,25 +1,24 @@
#include "mbed.h"
-AnalogIn adc(A0);
+AnalogIn adc_demod(A0);
+AnalogIn adc_distance(A1);
+
DigitalOut gpio(D8);
-float tab[330];
int i,j;
#define delay_bit 119
#define DELAY_ZERO 10
-#define SEUIL_MOYEN 0.60
+#define SEUIL_MOYEN 0.48
+#define NB_VALEURS 280
+
+char debug = 1;
-bool wait_zero(void){
- int valeur;
- valeur=0;
- while (adc.read() < SEUIL_MOYEN){
- valeur++;
- wait_us(5);
- }
- return (valeur < SEUIL_MOYEN)?true:false;
-}
+float tab_seuil[NB_VALEURS]; //tableau utilisé pour le calcul du seuil
+float tab_demod[NB_VALEURS]; //tableau pour la démodulation
+float tab_distance[NB_VALEURS]; //tableau pour la mesure de distance
+float seuil_moyen;
char decale_mot(char mot){ //Cette fonction effectue un décalage du mot de 1 cran vers la gauche
mot=((mot&0x7F)<<1)|((mot&0x80)>>7);
@@ -32,26 +31,71 @@
char mot;
float moyenne;
mot=0x00;
- printf("Debut\n");
- while(adc.read() > SEUIL_MOYEN);
- while(adc.read() < SEUIL_MOYEN);
- gpio=1;
- for(i=0; i< 330; i++){
- tab[i]=adc.read();
- }
- for (i=0; i<8; i++){
- moyenne = 0;
- for (j=0;j<36;j++){
- moyenne += tab[i*36 + j];
+ if(debug) printf("Debut\n");
+
+ while(1){
+ gpio=1;
+ //Aquisition pour seuil_moyen
+ for(i=0; i< NB_VALEURS; i++){
+ tab_seuil[i]=adc_demod.read();
+ }
+ seuil_moyen = 0;
+ for(i=0; i< NB_VALEURS; i++){
+ seuil_moyen += tab_seuil[i];
+ }
+ seuil_moyen /= NB_VALEURS;
+ if(debug) printf("Seuil_moyen = %f\n", seuil_moyen);
+
+ //Acquisition pour la démodulation
+ while(adc_demod.read() > seuil_moyen);
+ while(adc_demod.read() < seuil_moyen);
+ for(i=0; i< NB_VALEURS; i++){
+ tab_demod[i]=adc_demod.read();
+ }
+ for (i=0; i<8; i++){
+ moyenne = 0;
+ for (j=0;j<36;j++){
+ moyenne += tab_demod[i*36 + j];
+ }
+ moyenne /= 36.0;
+ mot |= (moyenne > seuil_moyen)?0x01:0x00;
+ if (i == 7) break;
+ mot = mot << 1;
}
- moyenne /= 36.0;
- mot |= (moyenne > SEUIL_MOYEN)?0x01:0x00;
- if (i == 7) break;
- mot = mot << 1;
- }
- gpio=0;
- for (i=0; i<8; i++){
- mot = decale_mot(mot);
- printf("%x\n", mot);
+ gpio=0;
+ //Mesure distance
+ while(adc_demod.read() > seuil_moyen);
+ while(adc_demod.read() < seuil_moyen);
+ for(i=0; i< NB_VALEURS; i++){
+ tab_distance[i]=adc_distance.read();
+ }
+ if(!debug)
+ for(i=0; i< NB_VALEURS; i++){
+ printf("%f\n", tab_distance[i]*1000);
+ }
+ float adc_min_distance = tab_distance[0];
+ float adc_max_distance = tab_distance[0];
+
+ for(i=0; i < NB_VALEURS; i++){
+ if(tab_distance[i] < adc_min_distance)
+ adc_min_distance = tab_distance[i];
+ if(tab_distance[i] > adc_max_distance)
+ adc_max_distance = tab_distance[i];
+ }
+ printf("Min = %f\n", adc_min_distance);
+ printf("Max = %f\n", adc_max_distance);
+ printf("Ecart = %f\n", adc_max_distance-adc_min_distance);
+
+
+ for (i=0; i<8; i++){
+ mot = decale_mot(mot);
+ if(debug)
+ if(mot == 0xAC){
+ printf("Mot present\n");
+ break;
+ }
+ //if(debug) printf("%x\n", mot);
+ }
+ wait(2);
}
}
