1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
|
// déclaration des variables
unsigned long int temp_res, temp_res1;
unsigned char var1, code_defaut;
// Textes à afficher
/* "1234567890123456" */ //16
const char *text1 ="Banc de tests"; //13
const char *text2 ="Circuit M"; //9
const char *text3 ="Initialisation"; //14
const char *text4 ="En cours..."; //11
const char *text5 ="Selectionner"; //12
const char *text6 ="le mode de cde"; //14
const char *text7 ="mode PWM -> +"; //14
const char *text8 ="mode Volt -> -"; //14
const char *text9 ="Banc de tests OK"; //16
const char *text10="Test low conso"; //14
const char *text11="En cours"; //8
const char *text12="Test transf+diag"; //16
const char *text13="Test courant lim"; //16
const char *text14="Test surtension"; //15
const char *text15="Tests termine"; //13
const char *text16="Module OK"; //9
const char *text17="Module defaut"; //13
const char *text18="Poursuivre?"; //11
const char *text19="Autre test?"; //11
const char *text20="Appuyer sur +"; //13
const char *text21="Appuyer sur -"; //13
const char *text22="Appuyer sur TEST"; //16
const char *text23="Resume du test?"; //15
const char *text24="Oui:+ Non:-"; //11
const char *text25="Banc pret"; //9
const char *text26="Connecter module"; //16
const char *text27="Mode PWM OK"; //11
const char *text28="Echec!"; //6
const char *text29="Low conso OK"; //12
const char *text30="Echec trans 5%"; //14
const char *text31="Echec trans 50%"; //15
const char *text32="Echec trans 100%"; //16
const char *text33="Echec diag 5%"; //13
const char *text34="Echec diag 50%"; //14
const char *text35="Echec diag 100%"; //15
const char *text36="OK -> 5%"; //8
const char *text37="OK -> 50%"; //9
const char *text38="OK -> 100%"; //10
const char *text39="Trans/diag OK"; //13
const char *text40="Trans/diag echec"; //16
// affectation des ports
// port A
#define VN610_cde PORTA.F4 // Commande du VN610SP
// port C
#define Cde_KR4_diag PORTC.F0 // Commande relais "diag"
#define PWM PORTC.F1 // Sortie PWM
#define Cde_KR1_Vmot100ohms PORTC.F5 // Cde du relais de cde 100 Ohms sur Vmot-
#define Cde_KR2_Vmot100ohms PORTC.F6 // Cde du relais de cde 100 Ohms sur Vmot+
#define Cde_KR3_DC_DC PORTC.F7 // Cde du relais de cde du DC/DC
// port D
#define BP_TEST PORTD.F0 // B.P "Test"
#define BP_PLUS PORTD.F1 // B.P "+"
#define BP_MOINS PORTD.F2 // B.P "-"
#define Led_secteur PORTD.F3 // Led "230V" secteur present
#define Led_OK PORTD.F4 // Led "OK" resultat: ->test reussi
#define Led_NOK PORTD.F5 // Led "defaut" resultat: ->test echec
#define Cde_KR0_Relais_alimP PORTD.F6 // Relais de commande +ALIM
#define Cde_KR00_Relais_alimN PORTD.F7 // Relais de commande -ALIM
// port E
#define Cde_KR7_pwm_linear PORTE.F1 // Cde du relais mode PWM ou Voltage
/***************************************************/
/* Initialisation du banc de tests */
/***************************************************/
// on affiche l'écran d'acceuil
void init_banc_tests(void)
{
ADCON1 = 9; // D-D-A-A-A-A-A-A-VDD-VSS
VN610_cde = 1; // RA4 activé (VN610SP=on)
TRISA = 0xDF; // Port RA4 en sortie le reste en entrée
PORTB = 0;
TRISB = 0; // Port B en sortie
Cde_KR4_diag = 0; // Commande relais "diag"
PWM = 0; // Sortie PWM
Cde_KR1_Vmot100ohms = 0; // Cde du relais de cde 100 Ohms sur Vmot-
Cde_KR2_Vmot100ohms = 0; // Cde du relais de cde 100 Ohms sur Vmot+
Cde_KR3_DC_DC = 0; // Cde du relais de cde du DC/DC
TRISC = 0; // Port C en sortie (Control Port)
Led_secteur = 0 ; // Led "230V" secteur present
Led_OK = 0 ; // Led "OK" resultat: test reussi
Led_NOK = 0 ; // Led "defaut" resultat: test echec
Cde_KR0_Relais_alimP = 0; // Relais de commande +ALIM
Cde_KR00_Relais_alimN = 0; // Relais de commande -ALIM
TRISD = 0x07; // RD0-RD2 en entrée (BP) RD3-RD7 en sortie (leds)
PORTE = 0;
TRISE = 0x01;
}
/******************************************************************************/
/* fonction permettant de transférer en RAM les chaines de caractères stockées*/
/* en ROM */
/******************************************************************************/
void StrConstCpy(char row, char col, const char *source) // no need of length parameter
{
char *dest ;
char buf[17] ; // for exemple ! it must be at least the maximum size of source string + 1
dest = buf ;
while(*source)
*dest++=*source++;
*dest=0; // put string terminator before using the string
lcd8_Out(row,col,buf); // print from the start of the string, not from the dest position !
}
/****************** Affichage d'acceuil ******************/
void affichage_accueil()
{
Lcd8_Config(&PORTC,&PORTB,2,4,3,7,6,5,4,3,2,1,0);
Lcd8_Cmd(LCD_CURSOR_OFF); // curseur désactivé
StrConstCpy(1,2,text1);
Delay_ms(1000);
StrConstCpy(2,4,text2);
}
void affichage_init()
{
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,2,text3);
Delay_ms(500);
StrConstCpy(2,3,text4);
}
/****************************************************************
PWM init
****************************************************************/
void Init_Pwm(void)
{
CCP2CON = 0x00 ; // module off
TMR2 = 0 ; // raz timer2 value
PR2 = 0x9B ; // PR2 = 155 --> f = 400 Hz 0b10011011
CCPR2L = 0 ; // Duty cycle = 0 à l'init 0b01001101
T2CON = 0x07; // 0b00000111
CCPR2L = 0x4D ; // 0b01001101 (0x4D)
CCP2CON = 0x3C ; // Mode PWM 10 bits + init two LSBs of PWM duty cycle at 0
//PR2 = 0b10011011 ; // valeurs donnée par l'utilitaire de brunog
//T2CON = 0b00000111 ;
//CCPR1L = 0b01001101 ;
//CCP1CON = 0b00111100 ;
}
/****************************************************************
PWM stop
****************************************************************/
void Stop_Pwm(void)
{
PWM = 0 ;
CCP2CON = 0x00 ;
}
/****************************************************************
chargement du duty cycle
****************************************************************/
void Rapport_cyclique_PWM(int iRapport_cyclique_PWM)
{
if(iRapport_cyclique_PWM < 256) iRapport_cyclique_PWM <<=2;
CCP2CON &=0b11001111;
CCP2CON |=(iRapport_cyclique_PWM & 3) << 4; // mise en place des 2 bits de poids faible, DCxB1 et DCxB0
CCPR2L=iRapport_cyclique_PWM >> 2; // mise en place des 8 bits de poids fort, CCPR1L
}
/**************************************************/
/* Fonction_1 -> test consommation */
/**************************************************/
void Test_conso()
{
PWM = 1; // On force la sortie de RC1 à 1 pour avoir PWM à 0% sur la Cde
Lcd8_Cmd(LCD_CLEAR); // on efface l'affichage
StrConstCpy(1,1,text10); // test low conso
Delay_ms(300);
StrConstCpy(2,4,text11); // en cours
temp_res = 0; // on initialise la variable qui va contenir la mesure de Adc_Read()
// On commande le relais alimentant le circuit à tester.
Cde_KR0_Relais_alimP = 1; // Relais de commande +ALIM on
Cde_KR00_Relais_alimN = 0; // Relais de commande -ALIM off (pour mettre la resistance de 10K en circuit;
// On met la 100 Ohms/10W au bornes du moteur pour simuler la charge moteur.
Cde_KR1_Vmot100ohms = 1; // Cde du relais de cde 100 Ohms sur Vmot- on
Cde_KR2_Vmot100ohms = 1; // Cde du relais de cde 100 Ohms sur Vmot+ on
Delay_ms(1000); // On laisse un peu de temps aux signaux de s'établir.
temp_res = Adc_Read(5); // on transmet le résultat du A/D dans temp_res
//temp_res=220; // essai d'une valeur pour tester une valeur d'echec
Delay_ms(500);
/************************************************/
/* mesure low conso: temp_res(min)=10K*5µA=50mV */
/* temp_res(max)=10K*100µA=1V */
/* si temp_res> 205 (1V) =>test defaut */
/************************************************/
if (temp_res >= 205) // soit une tension mesurée>1V
{
Lcd8_Cmd(LCD_CLEAR); // effacement affichage
StrConstCpy(1,5,text28); // "test conso echec"
Delay_ms(4000);
}
if (temp_res < 205) // soit une tension mesurée<1V
{
Lcd8_Cmd(LCD_CLEAR); // curseur désactivé
StrConstCpy(2,2,text29); // "test conso OK"
Delay_ms(4000);
}
}
/*******************************************************/
/* Fonction 2 -> test transfert et diagnostics */
/*******************************************************/
void transf_diag()
{
code_defaut = 0; // initialisation de la variable défaut
PWM = 0;
Lcd8_Cmd(LCD_CLEAR); // effacement affichage
StrConstCpy(1,1,text12); // "test transfert+diag"
Delay_ms(300);
StrConstCpy(2,4,text11); // "en cours"
temp_res = 0; // on prévoit
temp_res1 = 0; // 2 variables puisque 2 mesures à faire
Cde_KR4_diag = 1; // on connecte la sortie "diag" du circuit
Cde_KR0_Relais_alimP = 1; // Relais de commande +ALIM on
Cde_KR00_Relais_alimN = 1; // Relais de commande -ALIM on
Cde_KR1_Vmot100ohms = 1; // Cde du relais de cde 100 Ohms sur Vmot- on
Cde_KR2_Vmot100ohms = 1; // Cde du relais de cde 100 Ohms sur Vmot+ on
Delay_ms(1000);
Init_Pwm();
/******* test à PWM=5% *******/
Rapport_cyclique_PWM(148); // sortie PWM à 5% (on est inversé par rapport à RC1)
Delay_ms(3000);
temp_res = Adc_Read(3); // mesure du canal 3 (Vmot)
Delay_ms(3000);
temp_res1 = Adc_Read(1); // mesure du canal 1 (Vdiag)
Delay_ms(3000);
/*** test de Vmot ***/
if ((temp_res >= 40) && (temp_res < 82)) // dans le gabarit?
{
/** test de Vdiag **/
if ((temp_res1 >= 545) && (temp_res1 < 565)) // dans le gabarit?
{
code_defaut = 0; // pas de défaut
}
}
if ((temp_res < 40) || (temp_res > 82))
{
code_defaut = 1;
}
if ((temp_res1 < 545) || (temp_res1 > 565))
{
code_defaut = 1;
}
if (code_defaut ==1) // on affiche un texte indiquant qu'il y a eu au moins 1 défaut
{
Lcd8_Cmd(LCD_CLEAR); // curseur désactivé
StrConstCpy(2,4,text28); // "test à 5% defaut!"
}
if (code_defaut == 0)
{
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,4,text16); // "test à 5% OK"
}
temp_res = 0; // on termine en réinitialisant
temp_res1 = 0; // les variables de mesures.
/****** test à PWM=50% ********/
Rapport_cyclique_PWM(79); // sortie PWM à 50%
Delay_ms(3000);
temp_res = Adc_Read(3); // mesure du canal 3 (Vmot)
Delay_ms(3000);
temp_res1 = Adc_Read(1); // mesure du canal 1 (Vdiag)
Delay_ms(3000);
if ((temp_res >= 477) && (temp_res < 498))
{
if ((temp_res1 >= 272) && (temp_res1 < 340))
{
code_defaut = 0; // pas de défaut
}
}
if ((temp_res < 477) || (temp_res > 498))
{
code_defaut = 1;
}
if ((temp_res1 < 272) || (temp_res1 > 340))
{
code_defaut = 1;
}
if (code_defaut ==1) // on affiche un texte indiquant qu'il y a eu au moins 1 défaut
{
Lcd8_Cmd(LCD_CLEAR); // curseur désactivé
StrConstCpy(2,4,text28); // "test à 50% defaut!"
Delay_ms(3000);
}
if (code_defaut == 0)
{
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,4,text16); // "test à 50% OK"
Delay_ms(3000);
}
temp_res = 0; // on termine en réinitialisant
temp_res1 = 0; // les variables de mesures.
// ****** test à PWM=100%
Rapport_cyclique_PWM(1);
Delay_ms(3000);
temp_res = Adc_Read(3); // mesure du canal 3 (Vmot)
Delay_ms(3000);
temp_res1 = Adc_Read(1); // mesure du canal 1 (Vdiag)
Delay_ms(3000);
// mesure de Vmot si <Vmot
if ((temp_res >= 901) && (temp_res < 954))
{
if ((temp_res1 >= 61) && (temp_res1 < 102))
{
code_defaut = 0; // pas de défaut
}
}
if ((temp_res < 901) || (temp_res > 954))
{
code_defaut = 1;
}
if ((temp_res1 < 61) || (temp_res1 > 102))
{
code_defaut = 1;
}
if (code_defaut ==1)
{
Lcd8_Cmd(LCD_CLEAR); // curseur désactivé
StrConstCpy(2,1,text28); // "test à 100% defaut"
Delay_ms(4000);
}
if (code_defaut == 0)
{
Lcd8_Cmd(LCD_CLEAR); // curseur désactivé
StrConstCpy(2,1,text16); // "test à 100% OK"
Delay_ms(4000);
}
}
/**************************************************/
/* Fonction_3 -> test protection en courant */
/**************************************************/
void bloc3()
{
}
/**************************************************/
/* Bloc4 -> test surtension */
/**************************************************/
void bloc4()
{
}
// Programme principal
void main()
{
init_banc_tests();
affichage_accueil();
Delay_ms(1000);
affichage_init();
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,1,text9);
Delay_ms(500);
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,3,text5);
Delay_ms(300);
StrConstCpy(2,2,text6);
Delay_ms(500);
Lcd8_Cmd(LCD_CLEAR); // effacement LCD
StrConstCpy(1,2,text7);
Delay_ms(300);
StrConstCpy(2,2,text8);
Delay_ms(1000);
while(1)
{
if (BP_PLUS == 0) // Choix du mode PWM
{
var1 = 1;
Lcd8_Cmd(LCD_CLEAR); // effacement
StrConstCpy(1,3,text27); // mode PWM OK
Delay_ms(2000);
Lcd8_Cmd(LCD_CLEAR); // effacement
StrConstCpy(1,1,text26); // connecter module
Delay_ms(2000);
Lcd8_Cmd(LCD_CLEAR); // effacement
while (BP_TEST > 0)
{
StrConstCpy(2,1,text22); // appuyer sur test
if (BP_TEST == 0)
{
test_conso(); // Test low conso
transf_diag(); // Test transfert+diag
for(;;)
{
Lcd8_Cmd(LCD_CLEAR); // effacement
StrConstCpy(1,2,text15); // appuyer sur test
Delay_ms(1000);
}
Delay_ms(500);
}
}
}
if ((BP_MOINS==0) && (var1 == 0)) // Choix du mode commande en tension
{
Stop_Pwm();
}
} // end while()
} // end main() |
Partager