;AutoFeed_L298N HighTorque
;Date :03.09.2013
;Auteur:JNG
;**********************************************
#picaxe 14M2
setfreq M16
Input c.2 ;Stop Poussoir
Input c.3 ;Start Poussoir
Input c.4 ;ADC Vitesse d' avance
Symbol MOT = outpinsB ;MOT correspond au portB du 14M2
Symbol Index=b3
Symbol Vitesse = w10 ;Vitesse d'avance
Symbol Steps = w9 ;Nombre de steps
Symbol Mili = w7
Symbol Cent = w4
Symbol LongX = w0 ;Longueur a usiner
Symbol Sdir = w6 ;Direction de l'usinage
Symbol Pot2 = w5 ;Regle la vitesse d'usinage
Symbol Compteur = w8
Symbol Pulse = w11 ;Pour piloter les "Enable" du L298N
Symbol Fast = b16 ;Vitesse pour retour rapide
Symbol Flag1 = b17 ;Drapeau bouton Stop
dirsB= %00111111 ;Affectation B.0 à B.4 vers le L298 et b.5 vers Oled
;**********************************************
;Mémorisation de la sequence de commande pour les moteurs en demi-pas
eeprom 0,(%1010,%1000,%1001, %0001,%0101,%0100,%0110,%0010)
;********************************************** Choix direction usinage
w4 = 0
b16 = 10000
b17 = 0
Mot = Mot & $F0 | %0000 ;Arret moteur hors tension
Prg0:
If Pin2 = 1 Then Prg0
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"Choix direction ") ;Choix direction d'usinage
Serout 5,N600,(254,192," d'usinage ")
Pause 500
Serout 5,N600,(254,128,"---> Start ")
Serout 5,N600,(254,192,"<--- Stop ")
Pause 1000
If Pin2 = 1 Then
SDir = 1
Endif
If Pin3 = 1 Then
SDir = 0
Endif
Cent = 0
Mili = 0
LongX = 0
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"Start = Saisie X ")
Serout 5,N600,(254,192,"Stop+Start=NewDir ")
Pause 1000
If Pin2 = 0 And Pin3 = 0 Then Prg0
;********************************************** Saisie longueur d' usinage
Serout 5,N600,(254,128,"Start => + 100 mm")
Serout 5,N600,(254,192,"Stop => + 10 mm ")
Prg00:
If Pin2 = 1 Then Prg00
If Pin3 = 1 Then Prg00
Prg01:
If Pin2 = 1 Then Prg001
If Pin3 = 0 Then Prg01
If Pin3 = 1 Then
Mili = Mili + 100 ;Saisie des centaines de mm
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"X = ",#Mili,",",#Cent," mm ")
Serout 5,N600,(254,192,"Stop => + 1 mm ")
Endif
Pause 1000
If Pin2 = 0 Then Prg01
Prg001:
Serout 5,N600,(254,128,"Start => + 10 mm ")
Serout 5,N600,(254,192,"Stop => + 1 mm ")
If Pin2 = 1 Then Prg001
Prg02:
If Pin2 = 1 Then Prg002
If Pin3 = 0 Then Prg02
If Pin3 = 1 Then
Mili = Mili + 10 ;Saisie des dizaines de mm
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"X = ",#Mili,",",#Cent,"mm ")
Serout 5,N600,(254,192,"Stop => + 1 mm ")
Endif
Pause 1000
If Pin2 = 0 Then Prg02
Prg002:
Serout 5,N600,(254,128,"Start => + 1 mm ")
Serout 5,N600,(254,192,"Stop => +1/10 mm")
If Pin2 = 1 Then Prg002
Prg03:
If Pin2 = 1 Then Prg003
If Pin3 = 0 Then Prg03
If Pin3 = 1 Then
Mili = Mili + 1 ;Saisie des unités de mm
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"X = ",#Mili,",",#Cent," mm ")
Serout 5,N600,(254,192,"Stop => 1/100 mm")
Endif
Pause 1000
If Pin2 = 0 Then Prg03
Prg003:
Serout 5,N600,(254,128,"Start => + 1/10 mm ")
Serout 5,N600,(254,192,"Stop => + 1/100 mm ")
If Pin2 = 1 Then Prg003
Prg04:
If Pin2 = 1 Then Prg004
If Pin3 = 0 Then Prg04
If Pin3 = 1 Then
Cent = Cent + 10 ;Saisie des dixiemes de mm
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"X = ",#Mili,",",#Cent," mm ")
Serout 5,N600,(254,192,"Stop => + 1/100 mm ")
Endif
Pause 1000
If Pin2 = 0 Then Prg04
Prg004:
Serout 5,N600,(254,128,"Start => + 1/100 mm")
Serout 5,N600,(254,192,"Stop => Usinage ")
If Pin2 = 1 Then Prg004
Prg05:
If Pin2 = 1 Then Prg005
If Pin3 = 0 Then Prg05 ;
If Pin3 = 1 Then
Cent = Cent + 1 ;Saisie des centiemes de mm
Serout 5,N600,(254,1)
If Cent < 10 Then
Serout 5,N600,(254,128,"X = ",#Mili,",0",#Cent," mm ")
Else
Serout 5,N600,(254,128,"X = ",#Mili,",",#Cent," mm ")
Endif
Serout 5,N600,(254,192,"Stop => Usinage ")
Endif
Pause 1000
If Pin2 = 0 Then Prg05
Prg005:
If Pin2 = 1 Then Prg005
;********************************************************* Usinage
Avance0:
LongX = Mili * 100
LongX = LongX + Cent
Steps = LongX * 2 ;*2 => full step & *4 => Half step
Index = 0 ;0=>Mode full step & 1=> Mode single step
Avance:
Serout 5,N600,(254,128,"Start => Usiner ")
Gosub Lcd1
Pause 500
If Pin3 = 0 Then Avance
If w6 = 0 Then
Serout 5,N600,(254,128,"Usinage ---> ")
Gosub Lcd1
Else
Serout 5,N600,(254,128,"Usinage <--- ")
Gosub Lcd1
Endif
Prg1:
If Pin2 = 1 Then Prg1
If pin3 = 0 Then Prg1 ;START pour debuter l'usinage
For Compteur = 1 to steps
Readadc c.4, Pot2 ;Cherche la vitesse de deplacement
Vitesse = Pot2 * 255
Pulse = Pot2 * 150
Index = Index + 2 ;Incrémentation adresse eeprom
Gosub A1A2B1B2
Next Compteur
Pause 1000
Mot = Mot & $F0 | %0010 ;Attente avec un seul bobinage alimenté
;********************************************* Retour rapide
Prg2:
Serout 5,N600,(254,128," Start pour ")
Serout 5,N600,(254,192,"Retour rapide ")
If Pin3 = 0 Then Prg2 ;START pour retour rapide
If w6 = 1 Then
Serout 5,N600,(254,128,"Retour rap. ---> ")
Gosub Lcd1
Else
Serout 5,N600,(254,128,"Retour rap. <--- ")
Gosub Lcd1
Endif
Vitesse = Fast
For Compteur = 1 to Steps
Pulse = Fast / 2
Index = Index - 2
Gosub A1A2B1B2
Next Compteur
Pause 1000
Mot = Mot & $F0 | %0100 ;Attente avec un seul bobinage alimenté
;********************************************************* Resaisie & Usinage
Prg3:
Serout 5,N600,(254,1)
Serout 5,N600,(254,128,"Start = Usinage ")
Serout 5,N600,(254,192,"Stop+Start= New X")
Pause 2000
If Pin2 = 1 And Pin3 = 1 Then Prg0
Goto Avance
;********************************************************* Routine d'affichage
Lcd1:
If Cent < 10 Then
Serout 5,N600,(254,192,"X = ",#Mili,",0",#Cent," mm ")
Else
Serout 5,N600,(254,192,"X = ",#Mili,",",#Cent," mm ")
Endif
Return
;********************************************************* Routine moteur
A1A2B1B2:
Gosub Arret
Index = Index & %00000111
Read index, b4 ;Lecture de la séquence dans l'eeprom.
Mot = Mot & %00000000 | b4 ;Envoi de cette séquence au L298N
Pulsout b.4,Pulse ;Pilote les "Enable" des 2 ponts en H
Pauseus Vitesse ;pause en µs regle la vitesse de translation
Return
;********************************************************* Routine d'arret
Arret:
If Pin2 = 1 Then
Flag1 = 1 ;STOP l' avance
Endif
If Pin3 = 1 Then ;START relance l' avance
Flag1 = 0
Endif
Mot = Mot & $F0 | %0001
If Flag1 = 1 Then Arret
Return