شفت انکودر ها دارای سه سیگنال مربعی در خروجی هستند

مشخصه اصلی شفت انکودر ها تعداد پالس بر دور است

اختلاف فاز دو سیگنال a و b جهت چرخش را تعیین میکند

پالس z هم با هر دور یک پالس تولید میکند که از ان برای تعیین دور یا صفر کردن پالسهای یک دور استفاده میشود


استفاده از اینتراپت

 

$regfile = “m8515.dat”
$crystal = 4000000

‘——————————————-

Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.4 , Db6 = Porta.5 , _
Db7 = Porta.6 , E = Porta.2 , Rs = Porta.0

Config Timer1 = Timer , Prescale = 64 , Clear Timer = 1 , _
Compare A = Disconnect

Compare1a = &HF424

Enable Interrupts

Config Int0 = Falling
Enable Int0
On Int0 Rpm Nosave

Config Int1 = Falling
Enable Int1
On Int1 Pulsm Nosave

Enable Oc1a
On Oc1a 1_sec
Start Timer1

‘=========================================
Config Portb = Input

‘=========================================
Config Portc = Input

‘=========================================
Config Portd = Input

Rp_z Alias Pind.2
Rp_a Alias Pind.3
Rp_b Alias Pind.4

‘=========================================

Dim Rpm_c As Word
Dim Rpm_c_out As Word
Dim Rp As Word

‘=========================================

Ini:

Initlcd
Display On
Cursor Off / No Blink
Cls

‘================================
Main:

nop
nop

Goto Main
End
‘——————————-
Rpm:

Rpm_c = Rpm_c + 1
Rpm_c_out = Rp
Rp = 0

Return
Return
‘——————————-
Pulsm:

If Rp_b = 1 Then
Incr Rp
Else
Decr Rp
End If

Return
Return
‘——————————-
1_sec:

Cls
Lcd “  Rotary Pulser”
Lowerline
Lcd “Rotate : ” ; Rpm_c
THIRDLINE
Lcd “Pulse : ” ; Rp
FOURTHLINE
Lcd “P/R : ” ; Rpm_c_out

Return
Return
‘——————————-

 

 

 

روش غیر وقفه ای

 

$regfile = “m8515.dat”
$crystal = 4000000

‘——————————————-

Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.4 , Db6 = Porta.5 , _
Db7 = Porta.6 , E = Porta.2 , Rs = Porta.0

Config Timer1 = Timer , Prescale = 64 , Clear Timer = 1 , _
Compare A = Disconnect

Compare1a = &HF424

Enable Interrupts

Enable Oc1a
On Oc1a 1_sec
Start Timer1

‘=========================================
Config Portb = Input

‘=========================================
Config Portc = Input

‘=========================================
Config Portd = Input

Rp_z Alias Pind.2
Rp_a Alias Pind.3
Rp_b Alias Pind.4

‘=========================================

Dim Zold As Bit
Dim Aold As Bit

Dim Rpm_c As Word
Dim Rpm_c_out As Word
Dim Rp As Word

‘=========================================

Ini:

Initlcd
Display On
Cursor Off / No Blink
Cls

‘================================
Main:

‘zero
If Rp_z = 1 Then
If Zold = 0 Then
Rpm_c = Rpm_c + 1
Rpm_c_out = Rp
Rp = 0
Zold = 1
End If
Goto Main
End If

‘count
Zold = 0
If Rp_a = 0 Then
Aold = 0
Goto Main
End If
If Aold = 1 Then Goto Main
Aold = 1
If Rp_b = 1 Then
Rp = Rp + 1
Else
Rp = Rp – 1
End If

Goto Main
End

‘——————————-
1_sec:

Cls
Lcd “  Rotary Pulser”
Lowerline
Lcd “Rotate : ” ; Rpm_c
THIRDLINE
Lcd “Pulse : ” ; Rp
FOURTHLINE
Lcd “P/R : ” ; Rpm_c_out

Return
Return
‘——————————-

منبع: کیت برد