5 ' --- Variateur de vitesse à commande PWM --- 10 const device = 3B 15 lcdinit 20 cls : csroff 25 ' --- Affichage du message d'accueil --- 30 locate 0,0 : print "*Variateur PWM *" : locate 0,1 : print "(c) ELEKTOR 2008" : sound 6,159,2 : delay 5000 : cls 40 ' --- Déclaration des variables utilisées --- 41 dim Unmoteur as byte 42 dim B as integer : dim F as integer : dim N as integer : dim RI as integer : dim NR as integer : dim CHF as integer : dim NI as integer 43 dim UAD0 as integer : dim UAD1 as integer : dim Umoteurmax as integer 44 dim Us as integer : dim Vce as integer : dim Umoteur as integer : dim D as byte : dim RC as byte : dim Vitmoteur as integer : dim Umoy as integer : dim Uconsigne as integer 45 dim BP1 as byte : dim BP2 as byte : dim BP3 as byte 46 dim Vitnom as integer : dim Vitcons as integer : dim grafcet as byte : dim K as integer 47 dim X0 as byte : dim X1 as byte : dim X2 as byte : dim X3 as byte : dim X4 as byte : dim VALEUR as integer : dim TEMPO1 as integer : dim TEMPO2 as integer : dim TEMPO as byte 55 ' --- Saisie de la tension nominale du moteur --- 60 cls : locate 0,0 : print "Saisie Un moteur" : locate 0,1 : print " U nominale = ? " : sound 6,159,2 : delay 2000 61 locate 0,1 : print " <1> : Un = 9 V " 62 sound 6,100,2 63 for F = 1 to 40 64 BP1 = keyin (2,15) : BP2 = keyin (3,15) : BP3 = keyin (4,15) 65 if BP1 = 0 and BP2 = 1 and BP3 = 1 then Unmoteur = 9 : goto 100 66 if BP1 = 1 and BP2 = 0 and BP3 = 1 then Unmoteur = 12 : goto 100 67 if BP1 = 1 and BP2 = 1 and BP3 = 0 then Unmoteur = 15 : goto 100 68 next F 70 locate 0,1 : print " <2> : Un = 12 V " 71 sound 6,100,2 72 for F = 1 to 40 73 BP1 = keyin (2,15) : BP2 = keyin (3,15) : BP3 = keyin (4,15) 74 if BP1 = 0 and BP2 = 1 and BP3 = 1 then Unmoteur = 9 : goto 100 75 if BP1 = 1 and BP2 = 0 and BP3 = 1 then Unmoteur = 12 : goto 100 76 if BP1 = 1 and BP2 = 1 and BP3 = 0 then Unmoteur = 15 : goto 100 77 next F 80 locate 0,1 : print " <3> : Un = 15 V " 81 sound 6,100,2 82 for F = 1 to 40 83 BP1 = keyin (2,15) : BP2 = keyin (3,15) : BP3 = keyin (4,15) 84 if BP1 = 0 and BP2 = 1 and BP3 = 1 then Unmoteur = 9 : goto 100 85 if BP1 = 1 and BP2 = 0 and BP3 = 1 then Unmoteur = 12 : goto 100 86 if BP1 = 1 and BP2 = 1 and BP3 = 0 then Unmoteur = 15 : goto 100 87 next F 88 goto 61 100 ' --- Validation de la tension nominale du moteur --- 105 sound 6,159, 32 : delay 1000 110 cls : locate 9,0 : print dec(Unmoteur);"V ?" : locate 0,0 : print "Un moteur =" 115 locate 0,1 : print "Validation : <3>" 120 for F = 1 to 300 125 BP3 = keyin (4,25) 130 if BP3 = 0 then goto 145 135 next F 140 goto 60 145 BP3 = keyin(4,25) 146 if BP3 = 0 then goto 145 147 sound 6,159,32 150 ' --- Configuration du régulateur de tension --- 151 out 11,0 : out 12,0 : out 13,0 : out 14,0 : out 15,0 155 if Unmoteur = 9 then out 15,1 : out 12,1 : goto 200 160 if Unmoteur = 12 then out 14,1 : out 11,1 : goto 200 165 if Unmoteur = 15 then out 13,1 : goto 200 200 ' --- Saisie de la vitesse nominale du moteur --- 205 cls : locate 0,0 : print "Vitesse Nominale" 210 VALEUR = 10000 211 grafcet = 1 215 gosub 2000 220 ' --- Validation de la vitesse nominale du moteur --- 225 sound 6,159, 32 : delay 1000 230 cls : locate 7,0 : print dec(Vitnom);" ? " : locate 0,0 : print " Nn =" 235 locate 0,1 : print "Validation : <3>" 240 for F = 1 to 300 245 BP3 = keyin (4,25) 250 if BP3 = 0 then goto 270 255 next F 265 goto 200 270 BP3 = keyin(4,25) 271 if BP3 = 0 then goto 270 272 sound 6,159,32 275 K = Vitnom / Unmoteur 276 D = 128 280 ' --- Saisie de la consigne de vitesse --- 281 VALEUR = Vitnom 285 cls : locate 0,0 : print "Vitesse reduite:" 286 Vitcons = VALEUR 290 grafcet = 2 295 gosub 2000 300 ' --- Validation de la consigne de vitesse --- 305 sound 6,159, 32 : delay 1000 310 cls : locate 6,0 : print dec(Vitcons);" ? " : locate 0,0 : print " N =" 315 locate 0,1 : print "Validation : <3>" 320 for F = 1 to 300 325 BP3 = keyin (4,25) 330 if BP3 = 0 then goto 350 340 next F 345 goto 280 350 BP3 = keyin(4,25) 355 if BP3 = 0 then goto 350 356 sound 6,159,32 360 if Vitcons > Vitnom then locate 0,0 : print " Consigne > " : locate 0,1 : print "Vitesse nominale" : sound 6,255,16 : delay 3000 : goto 280 400 ' --- Régulation de la vitesse et gestion des affichages --- 401 Umoteurmax = 0 405 PWM 10,D 410 gosub 3000 415 cls : locate 0,0 : print " Un = ";dec(Unmoteur);" V " 420 locate 0,1 : print "N = ";dec(Vitnom);" tr/min" 430 for F = 1 to 15 435 gosub 3000 440 next F 450 cls : locate 0,0 : print "Consigne : ";dec(Vitcons) 455 locate 0,1 : print "N moteur : ";dec (Vitmoteur) 460 for F = 1 to 15 465 gosub 3000 470 next F 475 cls : locate 0,0 : print "Umoteur moyenne:" 476 locate 0,1 : print "Umoy=" 480 NI = Umoy 485 gosub 1000 490 locate 10,1 : print "," 495 CHF = NR / 10 500 locate 5,1 : print dec (CHF) 510 locate 14,1 : print "V" 550 for F = 1 to 15 560 gosub 3000 565 next F 570 cls : locate 0,0 : print "Rapport cyclique" 575 locate 0,1 : print " D = ";dec(RC);" %" 580 for F = 1 to 15 585 gosub 3000 590 next F 595 goto 415 1000 ' --- SP : Affichage d'un nombre décimal (tensions)--- 1005 N = NI 1010 RI = N / 10 1015 N = RI 1020 RI = N / 10 1025 NR = 10 * RI 1030 CHF = N - NR 1035 if CHF = 0 then locate 12,1 : print "0" 1040 if CHF = 1 then locate 12,1 : print "1" 1045 if CHF = 2 then locate 12,1 : print "2" 1050 if CHF = 3 then locate 12,1 : print "3" 1055 if CHF = 4 then locate 12,1 : print "4" 1060 if CHF = 5 then locate 12,1 : print "5" 1065 if CHF = 6 then locate 12,1 : print "6" 1070 if CHF = 7 then locate 12,1 : print "7" 1075 if CHF = 8 then locate 12,1 : print "8" 1080 if CHF = 9 then locate 12,1 : print "9" 1090 N = RI 1095 RI = N / 10 1100 NR = 10 * RI 1105 CHF = N - NR 1110 if CHF = 0 then locate 11,1 : print "0" 1115 if CHF = 1 then locate 11,1 : print "1" 1120 if CHF = 2 then locate 11,1 : print "2" 1125 if CHF = 3 then locate 11,1 : print "3" 1130 if CHF = 4 then locate 11,1 : print "4" 1135 if CHF = 5 then locate 11,1 : print "5" 1140 if CHF = 6 then locate 11,1 : print "6" 1145 if CHF = 7 then locate 11,1 : print "7" 1150 if CHF = 8 then locate 11,1 : print "8" 1155 if CHF = 9 then locate 11,1 : print "9" 1190 return 2000 ' --- SP Incrémentation / Décrémentation d'une variable (Grafcet de saisie) --- 2005 X0 = 1 : X1 = 0 : X2 = 0 : X3 = 0 : X4 = 0 : TEMPO1 = 0 : TEMPO2 = 0 : TEMPO = 0 2010 ' --- Evolution du Grafcet de saisie --- 2015 BP1 = keyin (2,10) : BP2 = keyin (3,10) : BP3 = keyin (4,10) 2020 if X0 = 1 and BP1 = 0 and BP2 = 1 and BP3 = 1 then X1 = 1 : X0 = 0 2025 if X1 = 1 and BP1 = 0 and TEMPO = 1 then X2 = 1 : X1 = 0 2030 if X2 = 1 and BP1 = 1 then X0 = 1 : X2 = 0 2035 if X1 = 1 and BP1 = 1 then X0 = 1 : X1 = 0 2040 if X0 = 1 and BP1 = 1 and BP2 = 0 and BP3 = 1 then X3 = 1 : X0 = 0 2045 if X3 = 1 and BP2 = 0 and TEMPO = 1 then X4 = 1 : X3 = 0 2050 if X4 = 1 and BP2 = 1 then X0 = 1 : X4 = 0 2055 if X3 = 1 and BP2 = 1 then X0 = 1 : X3 = 0 2060 ' --- Actions associées au Grafcet --- 2065 if X1 = 1 and BP1 = 0 and VALEUR <= 49500 then sound 6,159,2 : VALEUR = VALEUR + 100 2070 if X3 = 1 and BP2 = 0 and VALEUR >= 100 then sound 6,159,2 : VALEUR = VALEUR - 100 2075 if X1 = 1 then TEMPO1 = TEMPO1 + 1 2080 if X3 = 1 then TEMPO2 = TEMPO2 + 1 2085 if TEMPO1 = 10 or TEMPO2 = 10 then TEMPO = 1 2090 if X2 = 1 and BP1 = 0 and VALEUR <= 49000 then sound 6,159,2 : VALEUR = VALEUR + 1000 2095 if X4 = 1 and BP2 = 0 and VALEUR >= 1000 then sound 6,159,2 : VALEUR = VALEUR - 1000 2100 if X0 = 1 then TEMPO1 = 0 : TEMPO2 = 0 : TEMPO = 0 2115 if X0 = 1 and BP3 = 0 then return 2120 if grafcet = 1 then Vitnom = VALEUR 2125 if grafcet = 2 then Vitcons = VALEUR 2130 locate 4,1 : print dec(VALEUR);" tr/min" : locate 0,1 : print "N =" 2135 goto 2015 3000 ' --- SP / Régulation de la vitesse --- 3005 For B = 1 to 10 3010 BP3 = keyin(4,10) 3015 if BP3 = 0 then sound 6,159,2 : delay 1000 : goto 3105 3020 UAD0 = ADIN(0) 3025 UAD1 = ADIN(1) 3030 Us = 21*UAD0 3035 Vce = 21*UAD1 3040 if Us >= Vce then Umoteur = Us - Vce 3045 if Umoteur > Umoteurmax then Umoteurmax = Umoteur 3055 Uconsigne = 100 * ((Vitcons/(K/10))) 3060 RC = (100 * D) / 255 3065 Umoy = (RC*(Umoteurmax/100)) 3070 Vitmoteur = (K/10) 3075 Vitmoteur = Vitmoteur * (Umoy/100) 3080 if Umoy > Uconsigne and D > 0 then D = D - 1 3085 if Umoy < Uconsigne and D < 255 then D = D + 1 3090 PWM 10,D 3095 next B 3100 return 3105 VALEUR = Vitcons 3110 goto 285