Table des matières

bvdp.inetdoc.net_files_iut_tp_pic_warning.jpeg A FAIRE A LA FIN DE CHAQUE SEANCE POUR COPIER VOS FICHIERS SUR UN DISQUE PARTAGE (ET PERMETTRE LA RECUPERATION DES FICHIERS SI UN MEMBRE DU BINOME EST ABSENT) copier coller dans une console:

rsync -av --delete ~/workspace_ac6 /mnt/etu/s4

et completer la ligne en appuyant 3 fois sur la touche Tabulation, puis entrée.

Objectifs du TP

Les informations nécessaires au lancement de l'outil SystemWorkbench utilisé pour ce tp sont disponibles sur Mise en place du projet architecture pour le TNS sur plateforme Nucléo. Ce tp est la suite de tns_nucleo_tp1


Exercice 1: Mise en place d'un filtre simple de recopie

Une fois le DAC et l'ADC mis en place, nous pouvons à présent utiliser la classe Filtre déjà codée sour Qt. Pour cela, il vous faut copier les fichiers du projet Qt vers le projet Eclipse : filtre.h et filtre.cpp donnés dans la suite. Pour cela, copier coller dans une console:

cp ~/TP_ARCHI_TNS_ETU/filtre.cpp  ~/workspace_ac6/nucleo_tns/Src/
cp ~/TP_ARCHI_TNS_ETU/filtre.h  ~/workspace_ac6/nucleo_tns/Inc/

ensuite dans eclipse, cliquer sur l'onglet Project Explorer, ouvrir nucleo_tns, puis Src et taper sur la touche F5. Faire de même pour le dossier Inc. Normalement, les fichiers filtre.cpp et filtre.h doivent être ajoutés au projet et doivent apparaître dans les dossiers respectifs.

La classe Filtre sous Qt utilisait des types double pour les échantillons et les coefficients du filtre. Elle utilise sous Eclipse le type float car le microcontrôleur STM32 de la carte nucleo ne sait pas gérer nativement le type double.

Ajout des fichiers du filtre à l'outils de gestion de version pour le projet Eclipse

Mettre à jour le suivi de version en saisissant dans une console:

echo commence
cd ~/workspace_ac6/nucleo_tns/
git add Src/filtre.cpp
git add Inc/filtre.h
commit -a -m'ajout classe Filtre'
gitk &
echo fini

Initialisation et utilisation du filtre

Inclure la définition de la classe filtre et des types au début du fichier main.cpp entre les commentaires /* USER CODE BEGIN Includes */ et /* USER CODE END Includes */.

/* USER CODE BEGIN Includes */
#include "filtre.h"
/* USER CODE END Includes */

Entre les commentaires /* USER CODE BEGIN 0 */ et /* USER CODE END 0 */, copier/coller le code suivant:

filtred.cpp
//choix du filtre à utiliser
#define FILTRE0
 
//Déclaration de différents paramètres de filtres
#ifdef FILTRE0
//Filtre recopie
#define NB_COEFF_B 1
coefficient_t coeffB[NB_COEFF_B] = {1};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1};
#endif
 
//Déclaration de l'objet filtre avec allocation de memoireVk dans le constructeur de filtre
Filtre filtre(NB_COEFF_B,coeffB,NB_COEFF_A,coeffA,0,NULL, 2048,2048,2047,-2048); //pour ADC et DAC 12 bits

Enfin, il vous faut invoquer la méthode TraiteUnEchantillon de l'objet filtre dans la fonction d'interruption sur l'échantillon capturé.

Le code de la fonction d'interruption doit maintenant exécuter :

Une fois le code du filtre mis en place il vous faut le tester. Pour ce test, la carte Nucléo est associée à deux cartes : LINE_IN, LINE_OUT pour adapter les niveaux et protéger l'entrée ADC du microcontrôleur. L'adaptation en entrée applique un gain de 4.54 sur le signal mis en entrée et le centre sur 1.65v.

La procédure de test est la suivante :

  1. configurer le canal génération de signal de l'oscilloscope pour une sinusoide à 400Hz centrée sur 0 avec une amplitude réglée pour ne pas saturer l'amplificateur de la carte LINE_IN (vcc=3.3v).
  2. vérifiez les caractéristiques du signal avec l'oscilloscope
  3. brancher la sortie du générateur de signaux sur l'entrée A0 de la carte d'adaptation LINE_IN
  4. brancher l'entrée du scope sur la sortie A1 de la carte d'adaptation LINE_OUT

bvdp.inetdoc.net_files_iut_tp_tns_line_in_out.jpg

Le filtre de base est un filtre de recopie. A partir des caractéristiques du signal d'entrée, vérifiez la validité du signal de sortie. Il vous faut maintenant mesurer :

En déduire le temps de calcul associé à un filtre FIR à un coefficient.

Une fois le fonctionnement validé par un enseignant, mettre à jour le suivi de version en saisissant dans une console:

echo commence
cd ~/workspace_ac6/nucleo_tns/
git commit -a -m'filtre simple'
gitk &
echo fini

Exercice 2: Mise en place des filtres simples passe bas

Si vous avez validé le code du filtre RII:

Sinon passez à la section suivante (filtre RIF).

Modifier le tableau de coefficients du filtre 0 pour réaliser le filtre de l'exercice 3 du tp tptns2018

Si vous avez validé que le code du filtre RIF:

Modifier le tableau de coefficients du filtre 0 pour réaliser le filtre de l'exercice 2 du tp tptns2018

Dans tous les cas

On souhaite visualiser la réponse impulsionnelle du filtre sur la maquette. Pour cela, réglez le Générateur Basse Fréquence afin d'obtenir une impulsion de largeur $T_{ech}$ toute les millisecondes. Relever sur les deux voies de l'oscilloscope l'impulsion et la réponse impulsionnelle et la comparer avec celle attendue pour le filtre.

Une fois le fonctionnement validé par un enseignant, mettre à jour le suivi de version en saisissant dans une console:

echo commence
cd ~/workspace_ac6/nucleo_tns/
git commit -a -m'second filtre'
gitk &
echo fini

Exercice 3: Mise en place d'un second filtre

Entre les commentaires /* USER CODE BEGIN 0 */ et /* USER CODE END 0 */, après le #define FILTRE0 mais avant l'instanciation de l'objet filtre, copier/coller le code suivant:

filtred2.cpp
//Déclaration de différents paramètres de filtres
 #ifdef FILTRE1 
#define NB_COEFF_B 41
coefficient_t coeffB[NB_COEFF_B] = {-0.0259808358043697,-0.0275743606628094,-0.0283587041820195,-0.0282731131441959,-0.0272864868932718,-0.0253995007109912,-0.0226455146133406,-0.0190902027824487,-0.0148298919292662,-0.0099886513209803,-0.0047142306108997,0.0008270083968369,0.0064559755765054,0.0119873247646200,0.0172362600510304,0.0220254049667473,0.0261914582575037,0.0295913665059487,0.0321077620015535,0.0336534432271378,0.0341747139200087,0.0336534432271378,0.0321077620015535,0.0295913665059487,0.0261914582575037,0.0220254049667473,0.0172362600510304,0.0119873247646200,0.0064559755765054,0.0008270083968369,-0.0047142306108997,-0.0099886513209803,-0.0148298919292662,-0.0190902027824487,-0.0226455146133406,-0.0253995007109912,-0.0272864868932718,-0.0282731131441959,-0.0283587041820195,-0.0275743606628094,-0.0259808358043697};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
#ifdef FILTRE2
#define NB_COEFF_B 41
coefficient_t  coeffB[NB_COEFF_B]={ 0.016244657856333,-0.018864421488768,-0.012238782422342,-0.005085409431928,0.003969691594410, 0.012267146479049, 0.015030618183398, 0.008966346831124, -0.004682203645285,-0.019357735197421,-0.025875762043837,-0.017435787337996, 0.005471034822059, 0.033037851847265, 0.049218355348873, 0.038520192602532, -0.006112347636894,-0.078041093847378,-0.157847718052422,-0.220135476387537,0.756344281504610,-0.220135476387537,-0.157847718052422,-0.078041093847378, -0.006112347636894, 0.038520192602532, 0.049218355348873, 0.033037851847265,0.005471034822059,-0.017435787337996,-0.025875762043837,-0.019357735197421, -0.004682203645285, 0.008966346831124, 0.015030618183398, 0.012267146479049,0.003969691594410,-0.005085409431928,-0.012238782422342,-0.018864421488768, 0.016244657856333};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
#ifdef FILTRE3
#define NB_COEFF_B 11
coefficient_t  coeffB[NB_COEFF_B]={-0.0349249458233189,-0.0370641891927234,0.0209236117413746,0.1368055347416942,0.2562279031324722,0.3071029997932009,0.2562279031324722,0.1368055347416942,0.0209236117413746,-0.0370641891927234,-0.0349249458233189};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
#ifdef FILTRE4
#define NB_COEFF_B 6
coefficient_t coeffB[NB_COEFF_B]={0.3,0,0,0,0,0.3};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
#ifdef FILTRE5 
#define NB_COEFF_B 81
coefficient_t coeffB[NB_COEFF_B]={0.0103685348409740,0.0120337510292104,0.0134517630694984,0.0145371408895773,0.0152117480511064,0.0154086861413454,0.0150759534930825,0.0141796407140643,0.0127064996643426,0.0106657446017543,0.0080899734327553,0.0050351322179019,0.0015794858432056,-0.0021783996091716,-0.0061226136352335,-0.0101237053991003,-0.0140432035318806,-0.0177386850093223,-0.0210691978883431,-0.0239008219480017,-0.0261121394946973,-0.0275993864642809,-0.0282810617728671,-0.0281017904788701,-0.0270352631248233,-0.0250861086114917,-0.0222905997205700,-0.0187161372253949,-0.0144595084424439,-0.0096439669481062,-0.0044152298150032,0.0010634650604258,0.0066170582050158,0.0120649075715544,0.0172273257883530,0.0219321593965966,0.0260211497206493,0.0293558218281927,0.0318226655320655,0.0333373998707541,0.0338481488461604,0.0333373998707541,0.0318226655320655,0.0293558218281927,0.0260211497206493,0.0219321593965966,0.0172273257883530,0.0120649075715544,0.0066170582050158,0.0010634650604258,-0.0044152298150032,-0.0096439669481062,-0.0144595084424439,-0.0187161372253949,-0.0222905997205700,-0.0250861086114917,-0.0270352631248233,-0.0281017904788701,-0.0282810617728671,-0.0275993864642809,-0.0261121394946973,-0.0239008219480017,-0.0210691978883431,-0.0177386850093223,-0.0140432035318806,-0.0101237053991003,-0.0061226136352335,-0.0021783996091716,0.0015794858432056,0.0050351322179019,0.0080899734327553,0.0106657446017543,0.0127064996643426,0.0141796407140643,0.0150759534930825,0.0154086861413454,0.0152117480511064,0.0145371408895773,0.0134517630694984,0.0120337510292104,0.0103685348409740};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
 
#ifdef FILTRE6 
#define NB_COEFF_B 81
coefficient_t coeffB[NB_COEFF_B]={-0.0002036794491437,0.0000773730295986,0.0004064541816283,-0.0000126671995260,-0.0006781599552638,-0.0001856505322954,0.0009861669012660,0.0005746480394470,-0.0012660789594856,-0.0011995869733259,0.0014201689562419,0.0020785891889214,-0.0013215520275562,-0.0031868111640084,0.0008247562176837,0.0044425745408644,0.0002177263588559,-0.0056978048742279,-0.0019344973260901,0.0067344104625940,0.0044125638052519,-0.0072667830130195,-0.0076762705705793,0.0069482480493326,0.0116714318602412,-0.0053755151844091,-0.0162578518306691,0.0020782859334763,0.0212124403482326,0.0035343990815242,-0.0262436789826141,-0.0123436015564130,0.0310164889347273,0.0260338798321606,-0.0351848768073122,-0.0488947877029271,0.0384283756377584,0.0968713641464774,-0.0404875054856158,-0.3151686934827526,0.5411934085887211,-0.3151686934827526,-0.0404875054856158,0.0968713641464774,0.0384283756377584,-0.0488947877029271,-0.0351848768073122,0.0260338798321606,0.0310164889347273,-0.0123436015564130,-0.0262436789826141,0.0035343990815242,0.0212124403482326,0.0020782859334763,-0.0162578518306691,-0.0053755151844091,0.0116714318602412,0.0069482480493326,-0.0076762705705793,-0.0072667830130195,0.0044125638052519,0.0067344104625940,-0.0019344973260901,-0.0056978048742279,0.0002177263588559,0.0044425745408644,0.0008247562176837,-0.0031868111640084,-0.0013215520275562,0.0020785891889214,0.0014201689562419,-0.0011995869733259,-0.0012660789594856,0.0005746480394470,0.0009861669012660,-0.0001856505322954,-0.0006781599552638,-0.0000126671995260,0.0004064541816283,0.0000773730295986,-0.0002036794491437};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
 
#ifdef FILTRE7 
#define NB_COEFF_B 81
coefficient_t coeffB[NB_COEFF_B]={0.0075824022635949,0.0092234705790705,0.0108626758524260,0.0124725971426981,0.0140250330969121,0.0154914870824027,0.0168436714305958,0.0180540216545603,0.0190962111406914,0.0199456566336605,0.0205800048392448,0.0209795906641366,0.0211278579938452,0.0210117344740764,0.0206219524985219,0.0199533095042682,0.0190048617191466,0.0177800466743589,0.0162867310689886,0.0145371819266522,0.0125479603928332,0.0103397389573694,0.0079370443223467,0.0053679295432915,0.0026635804234235,-0.0001421375899179,-0.0030131845959898,-0.0059118950773456,-0.0087995610628357,-0.0116370395886346,-0.0143853739050788,-0.0170064175489756,-0.0194634502760852,-0.0217217749300807,-0.0237492846117921,-0.0255169900012381,-0.0269994973661640,-0.0281754286520660,-0.0290277760739352,-0.0295441847999183,0.9702828413904150,-0.0295441847999183,-0.0290277760739352,-0.0281754286520660,-0.0269994973661640,-0.0255169900012381,-0.0237492846117921,-0.0217217749300807,-0.0194634502760852,-0.0170064175489756,-0.0143853739050788,-0.0116370395886346,-0.0087995610628357,-0.0059118950773456,-0.0030131845959898,-0.0001421375899179,0.0026635804234235,0.0053679295432915,0.0079370443223467,0.0103397389573694,0.0125479603928332,0.0145371819266522,0.0162867310689886,0.0177800466743589,0.0190048617191466,0.0199533095042682,0.0206219524985219,0.0210117344740764,0.0211278579938452,0.0209795906641366,0.0205800048392448,0.0199456566336605,0.0190962111406914,0.0180540216545603,0.0168436714305958,0.0154914870824027,0.0140250330969121,0.0124725971426981,0.0108626758524260,0.0092234705790705,0.0075824022635949};
#define NB_COEFF_A 1
coefficient_t coeffA[NB_COEFF_A]={1}; 
#endif
 
 
#ifdef FILTRE8 
#define NB_COEFF_B 4
coefficient_t coeffB[NB_COEFF_B]={0.0000887506664687,0.0002662519994061,0.0002662519994061,0.0000887506664687};
#define NB_COEFF_A 4
coefficient_t coeffA[NB_COEFF_A]={1.0000000000000000,-2.8765463103075675,2.7696768953776338,-0.8924205797383166}; 
#endif
 
#ifdef FILTRE9 
#define NB_COEFF_B 7
coefficient_t coeffB[NB_COEFF_B]={0.0243592537384016,-0.1461555224304096,0.3653888060760240,-0.4871850747680320,0.3653888060760240,-0.1461555224304096,0.0243592537384016};
#define NB_COEFF_A 7
coefficient_t coeffA[NB_COEFF_A]={1.0000000000000000,0.4319583148933859,1.4502764147183655,0.8881173529205763,0.8287934168858131,0.3961166412039755,0.1863405399744429}; 
#endif
 
 

Vous devrez ensuite changer le #define FILTRE0 pour utiliser un des filtres de votre choix. Déterminer le temps nécessaire au calcul d'un échantillon pour ce filtre. Caractériser le type de filtre (passe bas…).

Une fois le fonctionnement validé par un enseignant, mettre à jour le suivi de version en saisissant dans une console:

echo commence
cd ~/workspace_ac6/nucleo_tns/
git commit -a -m'troisieme filtre'
gitk &
echo fini