Pozdrav,
jučer sam imao nekih problema sa porukama na forumu, te mi je admin to riješio. Kako sam obrisao određene poruke, evo kod koji sada djelomično radi. Na ulazu (RB0 i RB1) su PULL-down otpornici 10K. Kod povećava broj okretaje za jedan, ali kada krenem u kontra smjeru, kod počinje smanjivati za jedan, a onda nenadano poveća broj za jedan, pa opet oduzima (ne postoji pravilo u njegovom ponašanju). Imam osjećaj kao da interrupt rutina ne stigne obraditi bitove i da zakasni.
program Dva_senzora_1703
' PIC18F4550 - 8 MHZ
' EasyPic5 MicroBasic PRO
dim hall_sensor_0 as sbit at RB0_bit
dim hall_sensor_1 as sbit at RB1_bit
dim hall_sensor_direction as sbit at TRISB0_bit
dim hall_sensor_direction_1 as sbit at TRISB1_bit
dim count as word
dim count_str as string [5]
dim broj as byte
dim LCD_RS as sbit at RD4_bit
LCD_EN as sbit at RD5_bit
LCD_D4 as sbit at RD0_bit
LCD_D5 as sbit at RD1_bit
LCD_D6 as sbit at RD2_bit
LCD_D7 as sbit at RD3_bit
LCD_RS_Direction as sbit at TRISD4_bit
LCD_EN_Direction as sbit at TRISD5_bit
LCD_D4_Direction as sbit at TRISD0_bit
LCD_D5_Direction as sbit at TRISD1_bit
LCD_D6_Direction as sbit at TRISD2_bit
LCD_D7_Direction as sbit at TRISD3_bit
sub procedure interrupt
If Testbit (INTCON2,INTEDG0=1) and (INT0IF_BIT = 1) then
if TestBit (Intcon2,INTEDG1=0) and (INT1IF_bit=1) then
GIE_bit=0
inc(count)
INT0IF_bit = 0
INT1IF_bit=0
GIE_bit=1
end if
else
If Testbit (INTCON2,INTEDG1=1) and (INT1IF_BIT = 1) then
if TestBit (Intcon2,INTEDG0=0) and (INT0IF_bit=1) then
GIE_bit=0
dec(count)
INT1IF_bit = 0
INT0IF_bit=0
GIE_bit=1
end if
end if
end if
End sub
main:
ADCON1 = 0x0F
trisa=0 trisb=1
porta=0 portb=0
Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF)
hall_sensor_direction=1
hall_sensor_direction_1=1
count=50
'--------INTERRUPT Setup----------
RCON.IPEN=1 ' kada je ipen=1
INTCON.GIE=1 'global int on
INTCON.PEIE=0 'all int on
INTCON2.RBIP=1 'možda ne treba jer se odnosi na b4-b7
INTCON3.INT1IP=1 ' visoki prioritet
INT0IE_bit = 1 'int0 on
INT1IE_bit = 1 'int1 on
INTCON.RBIE=0
INTCON.RBIF=0
INTCON.INT0IE=1
while true
wordtostr (count, count_str)
LCD_Out (1,10, count_str)
LCD_Out (1,1, "Broj")
PORTA.broj=$FF
delay_ms (100)
porta.broj=0
inc (broj)
if broj>4 then
broj =0
end if
wend
end.
Pokušao sam sve prebaciti na RB4 i RB5 koristeći Interrupt on change. Nešto se opet s nečime sukobljuje. PIC je na momente blokiran (pinovi su "čisti"), a kada nešto radi samo zbraja ali čudna zbrajanja, kao da se u rutini zadržava dovoljno dugo i povećava varijablu count. O oduzimanju niti jednog minusa.
sub procedure interrupt
iF tESTbIT (INTCON, RBIF=1) THEN
IF (portb.4=1) and (portb.5=0) THEN
inc (COUNT)
temp = PORTB
PORTB = temp
INTCON.RBIF=0
INTCON.GIE=1 'global int on
INTCON.RBIE=1
ELSE
IF (portb.5=1) AND (portb.4=0) THEN
DEC (COUNT)
temp = PORTB
PORTB = temp
INTCON.RBIF=0
INTCON.GIE=1 'global int on
INTCON.RBIE=1
END IF
END IF
END IF
End sub
main:
ADCON1 = 0x0F
TRISA=0
trisb.4=1
trisb.5=1
TRISD=0
Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF)
hall_sensor_direction=1
hall_sensor_direction_1=1
count=0
TEMP=0
'--------INTERRUPT Setup----------
RCON.IPEN=1 ' kada je ipen=1
INTCON.GIE=1 'global int on
INTCON.PEIE=0 'all int on
INTCON2.RBIP=1 'možda ne treba jer se odnosi na b4-b7
INTCON.RBIE=1
INTCON.RBIF=0
INTCON2.RBPU=1
BROJ=0
PORTB=0
program Hall_1503_INT
' PIC18F4550 - 8 MHZ
' EasyPic5 MicroBasic PRO
dim hall_sensor_0 as sbit at RB0_bit
dim hall_sensor_1 as sbit at RB1_bit
dim hall_sensor_direction as sbit at TRISB0_bit
dim hall_sensor_direction_1 as sbit at TRISB1_bit
dim count as word
dim Broj as word
dim count_str as string [5]
dim Smjer_str as string [4]
dim LCD_RS as sbit at RD4_bit
LCD_EN as sbit at RD5_bit
LCD_D4 as sbit at RD0_bit
LCD_D5 as sbit at RD1_bit
LCD_D6 as sbit at RD2_bit
LCD_D7 as sbit at RD3_bit
LCD_RS_Direction as sbit at TRISD4_bit
LCD_EN_Direction as sbit at TRISD5_bit
LCD_D4_Direction as sbit at TRISD0_bit
LCD_D5_Direction as sbit at TRISD1_bit
LCD_D6_Direction as sbit at TRISD2_bit
LCD_D7_Direction as sbit at TRISD3_bit
sub procedure interrupt
If INT0IF_BIT then
if portb.1 then
dec(count)
Smjer_str="Dole"
end if
INT0IF_bit = 0
end if
If INT1IF_BIT then
if portb.0 then
inc(count)
Smjer_str="Gore"
end if
INT1IF_bit = 0
end if
End sub
main:
ADCON1 = 0x0F
trisa=0 trisb=1
porta=0 portb=0
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
Lcd_Cmd(_LCD_CLEAR) ' Clear display
hall_sensor_direction=1
hall_sensor_direction_1=1
count=0
broj=0
'--------INTERRUPT Setup----------
'RCON.IPEN=1 ' kada je ipen=1
INTCON.GIE=1 'global int on
INTCON.PEIE=0 'all int on
INTCON.INT0IE=1 ' Enables the INT0 external interrupt
intcon.INT0IF=0 ' Clear IF
INTCON.RBIE=0 ' Disables the RB port change interrupt
intcon.RBIF=0 ' Clear IF
INTCON2.INTEDG0=0 ' Interrupt on falling edge
INTCON2.INTEDG1=0 ' Interrupt on falling edge
INTCON3.INT1IE=1 ' Enables the INT1 external interrupt
intcon3.INT1IF=0 ' Clear IF
while true
wordtostr (count, count_str)
LCD_Out (1,1, "Smjer ")
LCD_Out (1,7, Smjer_str)
LCD_Out (1,11, count_str)
PORTA.broj=$FF
delay_ms (100)
porta.broj=0
inc (broj)
if broj>4 then
broj =0
end if
wend
end.
Da sad ne crtam nešto novo s onim "otvorenim optocouplerima" (senzorima) možeš izvesti nešto ovako ali tebi ne treba niz rupica već samo jedan otvor dovoljno velik da istovremeno oba senzora budu prosvijetljena.
program HALL
' PIC18F4680 - 8 MHZ
' EasyPIC v7 MicroBasic PRO
dim hall_sensor_0 as sbit at RB4_bit
dim hall_sensor_1 as sbit at RB5_bit
dim hall_sensor_direction as sbit at TRISB4_bit
dim hall_sensor_direction_1 as sbit at TRISB5_bit
dim count as word
dim count_str as string [5]
dim broj as byte
dim old_hall_sensor_0 as bit
dim LCD_RS as sbit at RC4_bit
LCD_EN as sbit at RC5_bit
LCD_D4 as sbit at RC0_bit
LCD_D5 as sbit at RC1_bit
LCD_D6 as sbit at RC2_bit
LCD_D7 as sbit at RC3_bit
LCD_RS_Direction as sbit at TRISC4_bit
LCD_EN_Direction as sbit at TRISC5_bit
LCD_D4_Direction as sbit at TRISC0_bit
LCD_D5_Direction as sbit at TRISC1_bit
LCD_D6_Direction as sbit at TRISC2_bit
LCD_D7_Direction as sbit at TRISC3_bit
sub procedure interrupt
INTCON.GIE=0 'global int off
If TestBit (INTCON, RBIF=1) THEN 'ako se dogodio int. on ch.
IF (hall_sensor_0<>old_hall_sensor_0) and (hall_sensor_1=0) then 'provjeri je li se promijenilo stanje na senzoru A i je li senzor B=0
IF (hall_sensor_0=1) THEN 'alo je A=1
inc (COUNT) 'zbroji
else 'ako nije (A je dakle 0
dec (COUNT) 'oduzmi
END IF
END IF
END IF
old_hall_sensor_0=hall_sensor_0 'postavi stanje sen. A u flag za detekciju promjene
INTCON.GIE=1 'global int on
INTCON.RBIF=0 'obrisati RBIF
INTCON.RBIE=1 'dopusti Int. on change
End sub
main:
ADCON1 = 0x0F
TRISA=0
TRISC=0
Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF)
hall_sensor_direction=1
hall_sensor_direction_1=1
count=0
'--------INTERRUPT Setup----------
INTCON.GIE=1 'global int on
INTCON.RBIE=1
BROJ=0
while true
wordtostr (count, count_str)
LCD_Cmd(_LCD_CLEAR)
LCD_Out (1,10, count_str)
LCD_Out (1,1, "Broj")
PORTA.broj=1
delay_ms (100)
porta.broj=0
inc (broj)
if broj>4 then
broj =0
end if
wend
end.
Nešto me zezao displej na portu D, pa sam ga prebacio na port C, nije mi se dalo istraživati. Senzore sam stavio na RB4 i RB5, a kako nisam imao tvoj kontroler, stavio sam nešto slično PIC18F4680. Meni na ploči radi odlično, ne gubi korake i ide brrrrrzo. Nadam se da sam barem malo pomogao
Cezare, star sam i nemoćan, ali poslušaj moj savjet ....
Pozdrav,
danas napokon isprobano na stroju i na moju žalost, brzina čitanja senzora nije dobra. Na 300 okreta moji senzori pogriješe do 35 okretaja.
U Inerrupt rutini je samo dio koji je Kukinjos predložio. Što bi mogao biti problem sporog očitavanja senzora?
Ima li tko kakvu ideju.
Pokušao bih sa hall senzorom, ali neznam koji da upotrijebim. Na osovini imam jedan magnet (okrugli oko 1 cm u promjeru). Možda bi sa njima to bilo bolje?
Pozdrav,
BNY 37, optički. Analizirajućislučaj, ustvrdio sam kako dođe do određenog "preskakanja" po jedan okretaj. Nema pravila kada se to dešava. Provjerit ću još jednom shemu spojeva, otpornike i sl.
Da, moja greška to je CNY37.
Mislim da sam pronašao razlog. Drugi tjedan provjeravam na stroju pa ću napisati rezultat.
Na mom modelu stroja namotao sam 586 namotaja u 15-tak sekundi, a ručno sam odmotavao i brojao. Sve je bilo u redu. To je veća brzina okretanja nego na stroju gdje sam radio. Mislim da je problem u veličini otvora na disku (na osovini). Povećat ću dužinu otvora.
Pozdrav,
veći prorez (dužina kao tri senzora smještena jedan do drugog)i problem je riješen. Broji i pri najvećim brzinama. Još jednom hvala svima na pomoći.