Scolioza
Member level 1
- Joined
- Mar 5, 2013
- Messages
- 34
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,561
Define CONFIG = 0x2f42
Define ADC_CLOCK = 3
Define ADC_SAMPLEUS = 20
'LINE FOLLOWER //// PETRESCU CRISTIAN
TRISA = 255
TRISB = %00000001 'PORTB =OUTPUT
Symbol mstg = PORTB.1 'COMANDA MOTOR STANGA
Symbol mdr = PORTB.2 'COMANDA MOTOR DREAPTA
mstg = 0
mdr = 0
Dim val_ref(4) As Word 'VECTORI VALORI DE REFERINTA
Dim val_prg(4) As Word 'VECTORI VALORI CITITE
Dim dif(4) As Byte 'DIFERENTE
Dim semn(4) As Byte 'FLAG DE SEMNE
Dim indice As Byte 'POZITIA SENZORULUI
Dim max As Byte 'VALMAX
Dim contor As Byte
Dim buff As Byte
Dim calibrare As Bit 'CALIBRAREA INITIALA
Dim start As Bit 'INCEPEREA PROGRAMULUI
Dim x As Byte
Hseropen 19200
'SETAREA MODULULUI COMPARATOR
CMCON.CM2 = 1
CMCON.CM1 = 1
CMCON.CM0 = 1
'FIGURA 12.1 CONFIGURATIA 5 COMP off
'SETARE REG. A/D
'ADCON0.ADCS0 = 1
'ADCON0.ADCS1 = 1 'SEATARE OSC RC INTERN
'ADCON1.ADFM = 1 'SETARE RIGHT JUSTIFIED
ADCON1.PCFG3 = 0
ADCON1.PCFG2 = 0
ADCON1.PCFG1 = 0
ADCON1.PCFG0 = 0
'TOATE INTRARI ANALOGICE
'SETARE INTRERUPERI
INTCON.GIE = 1 'INTRERUPERI GLOBALE ACTIVATE
INTCON.PEIE = 1 'INTRRUPERI PERIFERICE ACTIVATE
INTCON.INTE = 1 'INTRERUPERE PE RB.0
'PIE2.CMIE = 1 'INTRERUPERI COMPARATOR ACTIVATE
PWMon 1, 2
PWMduty 1, 550
'########################################################
loop:
If calibrare = 1 Then
For x = 0 To 3
val_ref(x) = analog_read(x)
Hserout "val: ", #val_ref(x), CrLf
Next x
Endif
If start = 1 Then
For x = 0 To 3
val_prg(x) = analog_read(x)
If val_prg(x) > val_ref(x) Then
dif(x) = val_prg(x) - val_ref(x)
semn(x) = 1
Else
semn(x) = 0
Endif
Next x
For x = 0 To 3
If max < dif(x) And semn(x) = 1 Then
max = dif(x)
indice = x
Endif
Next x
If max > 7 Then
Select Case indice
Case 0
mstg = 0
mdr = 1
Case 1
buff = dif(1) - dif(0)
If buff < 7 Then
mstg = 0
mdr = 1
Else
mstg = 1
mdr = 1
Endif
Case 2
buff = dif(2) - dif(3)
If buff < 7 Then
mstg = 1
mdr = 0
Else
mstg = 1
mdr = 1
Endif
Case 3
mstg = 1
mdr = 0
EndSelect
Else
mstg = 0
mdr = 0
Endif
Hserout "####################", CrLf
Hserout "stg1:", #dif(0), CrLf
Hserout "stg2: ", #dif(1), CrLf
Hserout "dr2: ", #dif(2), CrLf
Hserout "dr1: ", #dif(3), CrLf
Hserout "####################", CrLf
For x = 0 To 3
dif(x) = 0
Next x
max = 0
Endif
WaitMs 1000
Goto loop
End
Function analog_read(pas As Byte) As Word
Select Case pas
Case 0
Adcin 3, analog_read
Case 1
Adcin 0, analog_read
Case 2
Adcin 1, analog_read
Case 3
Adcin 2, analog_read
EndSelect
If calibrare = 1 Then calibrare = 0
End Function
On Interrupt
WaitMs 1000
contor = contor + 1
If contor = 1 Then calibrare = 1
If contor = 2 Then start = 1
INTCON.INTF = 0
Hserout "####################", CrLf
Hserout "contor:", #contor, CrLf
Hserout "####################", CrLf
Resume
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?