START
BCF STATUS,RP1 ;BANK 2. bit delete
BSF STATUS,RP0 ;switching to BANK1: 01
;PORTA I/O bit's to be Digital
MOVLW 0x06
MOVWF ADCON1 ;every bit of PORTA are digital
;TRIS's
MOVLW B'00011111'
MOVWF TRISA ;setup PORTA for input
MOVLW B'00000000'
MOVWF TRISD ;setup PORTD for output
BCF STATUS,RP0 ;switching to BANK0
;LED init
MOVLW B'00000001' ;switch on 1. LED
MOVWF PORTD ;switch off other LED's
CLRC ;cleare C bit
MAIN
; BTFSS PORTA,0 ;run the next command if push button1 is down
; RLF PORTD,F ;bit rotate left (F is for PORTDl)
; BTFSS PORTA,1 ;run the next command if push button2 is down
; RRF PORTD,F ;bit rotate right
BTFSC PORTA,2 ;detecting optical slotted switch
BSF PORTD,3 ;set 3. bit on PORTD
KESLELTETO ;Delay label
MOVLW d'25'
MOVWF T1 ;25 in to T1
DEL
MOVLW d'25'
MOVWF T2 ;25 in to T2
DEL1
MOVLW d'10'
MOVWF T3 ;10 in to T3
DEL2
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ T3,f ;decrease T3-at until zero
GOTO DEL2 ;go to DEL2-re
DECFSZ T2,f ;if T3 zero, then decrease T2
GOTO DEL1
DECFSZ T1,f ;the same for T1
GOTO DEL
RETURN ;return from DELAY subrutin
END
-------<
I can't se any changes on LED's here when I put a paper in the slot of
the optical swith.
Why can't I use this way the Optical Slotted Switch?
Ignored. Formatting a mess and lots of stuff clearly in column 1 that
shouldn't be. This mess couldn't have assembled without massive warnings at
best.
> I can't se any changes on LED's here when I put a paper in the slot of
> the optical swith.
Paper is not likely opaque enough. Try aluminum foil.
> Hi,
>
> I'm trying to use TCST1030 Optical Slotted Switch with PIC16F877A.
> The circuit can be seen here:
> http://csanyi-pal.info/album/index.php/album/section/2#1
>
> The assembly program is bellow.
> ...
>
> I can't se any changes on LED's here when I put a paper in the slot of
> the optical swith.
>
> Why can't I use this way the Optical Slotted Switch?
>
>
> --
> Regards, Paul Chany
> http://csanyi-pal.info
The changed assembly program is bellow.
--------->
LIST P=16F877A
#INCLUDE "P16F877A.INC"
__CONFIG _XT_OSC&_CP_OFF&_WDT_OFF&_LVP_OFF
ORG 0
START
;switching to BANK1: 00
BCF STATUS,RP1 ;Bit Clear file, RP1=0
BSF STATUS,RP0 ;Bit Set file, RP0=1
MOVLW 0x06 ;6 to Work register
MOVWF ADCON1 ;PORTA digital
MOVLW B'00011111'
MOVWF TRISA ;PORTA as input
MOVLW B'00000000'
MOVWF TRISD ;PORTD as output
BCF STATUS,RP0 ;switching to BANK0: 00
MOVLW B'00000000' ;switch off the LEDs
MOVWF PORTD
MAIN
BTFSC PORTA,2 ;skip the next command if the
;Optical Slotted Switch connected to RA2 pin
;(PORTA) with Collector of the PhotoTransistor
;give to us logical 0, because there isn't
;anything in the slot
BSF PORTD,1 ;switch on the 1. LED of PORTD
BSF PORTD,0 ;switch on the 0. LED of PORTD
GOTO MAIN
END
---------<
>> I can't se any changes on LED's here when I put a paper in the slot
>> of the optical swith.
>
> Paper is not likely opaque enough. Try aluminum foil.
I try with cardboard (pasteboard). No changes seen.
Actually, I can see the 0. (PORTD,0) and 1. (PORTD,1) LED's to light
permanently.
Useless comment. Anybody can see you are putting 6 into W, but what's it
for? Why 6, not 13 or 211?
> MAIN
> BTFSC PORTA,2 ;skip the next command if the
> ;Optical Slotted Switch connected to RA2 pin
> ;(PORTA) with Collector of the PhotoTransistor
> ;give to us logical 0, because there isn't
> ;anything in the slot
> BSF PORTD,1 ;switch on the 1. LED of PORTD
> BSF PORTD,0 ;switch on the 0. LED of PORTD
> GOTO MAIN
This will light the LED when RA2 is high, but not turn it off when RA2 goes
back to low.
>>> I can't se any changes on LED's here when I put a paper in the slot
>>> of the optical swith.
You need to break your testing process up into 2 parts.
1. Do the levels at the pins change when you put paper in the slot,
and what are the voltages before and after.
2. WHEN the voltages at the pins DO change, does the program react correctly.
At present either of these two points could be the problem (or both)
and you are not able to tell which is which.
So
1. Enable power to optos.
Measure voltages at pins (= Vno_paper)
Insert paper.
Measure voltages at pins = Vwithpaper.
Are the voltage swings what you expect?
Are the voltages above and below the PIC logic threshold levels for
the pins used?
2. Apply voltage to the circuit.
Short opto pin 1's to ground OR remove 5V supply to R14 and R15.
Measure voltages at PIV pin4 and pin5.
These SHOULD be high /y close to 5V.
Observe PIC program driven output.
Now ground PIC pins 4 and 5 and observe PIC program driven output.
Output should change as you intend.
_______________
If test in 1 fail you have a hardware problem (less likely).
If tests in 2. fail you have a software problem.
There is a small chance that wiring is not as you intend.
If not, then voltages in above test will not be as expected at some
stage and/or magic smoke will appear at some stage.
eg shorting PIC pins 4 or 5 to ground will challenge power supply if
5V is connected to wrong end of R12 or R13. (which is unlikely).
>>
>> Paper is not likely opaque enough. Try aluminum foil.
>
> I try with cardboard (pasteboard). No changes seen.
> Actually, I can see the 0. (PORTD,0) and 1. (PORTD,1) LED's to light
> permanently.
>
> --
> Regards, Paul Chany
> http://csanyi-pal.info
>
> Paul Chany wrote:
> So it appears you have two opto interrupters connected to RA2 and
> RA3. They should go high when something is in the slot.
Yes. Actually there is only one opto interrupter.
When and if I solve this problem then should go there the second one
too.
> Yucc. Use BANKSEL.
> Useless comment. Anybody can see you are putting 6 into W, but
> what's it for? Why 6, not 13 or 211?
BANKSEL ADCON1 ;switching to BANK1: 01
MOVLW 0x06 ;to set ADCON1 bit's 3-0 (PCFG <3:0> 011x
MOVWF ADCON1 ;configure ADCON1 eight bit's (AN7-AN0) to be
;digital I/O
> This will light the LED when RA2 is high, but not turn it off when
> RA2 goes back to low.
------->
MAIN
BTFSC PORTA,2 ;skip the next command if the
;Optical Slotted Switch connected to RA2 pin
;(PORTA) with Collector of the PhotoTransistor
;give to us logical 0, because the slot is
;open
BSF PORTD,1 ;switch on the 1. LED of PORTD
BTFSS PORTA,2 ;skip the next command if the
;Optical Slotted Switch connected to RA2 pin
;(PORTA) with Collector of the PhotoTransistor
;give to us logical 1, because the slot is
;blocked
BCF PORTD,1 ;switch off the 1. LED of PORTD
GOTO MAIN
-------<
So now the 1. LED of eight connected to PORTD light permanently, even
if I block the TCST1030 optical slotted switch.
Paul Chany wrote:
> Yes. Actually there is only one opto interrupter.
So the schematic you posted doesn't correspond to your actual circuit. I
feel like an idiot for having wasted time looking at it. That, and the
initial unreadable schematic and code formatted to oblivion decrease the
chance request from you will be taken seriously.
There shouldn't be voltage "permanently" at the PIC input pin. As you interrupt the beam in the slot of the optical switch, the voltage at the PIC input pin should swing either from full voltage to almost 0 voltage, or from almost 0 voltage to almost full supply voltage. If that doesn't happen then there will be no response as the input pin will alway be at the same level. Of course if I am mis-understanding the meaning of permanent 4.8V then overlook what I am saying. Are you using any type of interface between the optical switch and the PIC input pin, such as a simple bi-polar transistor?
Randy Abernathy
CNC and Industrial Machinery
service, repair, installation and
design
Is the type of optical switch actually used, exactly like the one in the posted schematic? If so when you interrupt the "beam" inside the switch, then the input to the PIC pin (if you have pull up resistors as shown in the schematic) would go HIGH and when there is no obstruction of the IR beam then the input to that pin would remain LOW since the NPN transistor in the IR switch would be conducting to ground.
I must agree with Olin though, you won't be taken very seriously if you don't provide accurate information from which to work.
Good luck
Randy Abernathy
CNC and Industrial Machinery
service, repair, installation and
design
Paul Chany wrote:
> Yes. Actually there is only one opto interrupter.
So the schematic you posted doesn't correspond to your actual circuit. I
feel like an idiot for having wasted time looking at it. That, and the
initial unreadable schematic and code formatted to oblivion decrease the
chance request from you will be taken seriously.
> Paul Chany wrote:
> So the schematic you posted doesn't correspond to your actual
> circuit.
My circuit is on the solderless protoboard. However, I think, it's not
so substantial if I have one optical interrupter instead of two,
because thy are in the same way connected to the PIC on the schematic.
> the initial unreadable schematic
The initial unreadable schematic? If one open the link:
csanyi-pal.info/album/index.php/album/section/2#1
then there can see the link bellow: [View original]
It is just a matter of click on this link to get the readable
schematic.
So I think it wasn't unreadable. The second schematic is the same as
the first, but after one clicked on the link [View original].
> and code formatted to oblivion
I changed the code because I want to get the simplest code as I can to
do the job.
> decrease the chance request from you will be taken seriously.
The schematics corresponds now with the circuit on my solderless
protoboard totally.
> You need to break your testing process up into 2 parts.
> 1. Enable power to optos.
> Measure voltages at pins (= Vno_paper)
I measure here 0.09 V.
> Insert paper.
> Measure voltages at pins = Vwithpaper.
I measure here 4.56 V.
> Are the voltage swings what you expect?
Yes it swings as I expect.
But here I must to write down that that datasheet of optical
interrupters are very bad in that how represents the detector and
emitter side of the optical interrupter. For me it was difficult to
figure out which side is IR LED? Finally I know which side is IR LED
(emitter).
> Are the voltages above and below the PIC logic threshold levels for
> the pins used?
Accordingly to the datasheet PIC16F87XA.pdf the RA2 and RA3 when setup
for digital I/O has TTL input buffer with following logic threshold
levels:
Input Low Voltage: Min Vss, Max 0.8 V
Input High Voltage: Min 2 V, Max Vdd (4.5V <= Vdd <= 5.5V)
> 2. Apply voltage to the circuit.
> Short opto pin 1's to ground OR remove 5V supply to R14 and R15.
>
> Measure voltages at PIV pin4 and pin5.
> These SHOULD be high /y close to 5V.
They are 4.97V.
> Observe PIC program driven output.
> Now ground PIC pins 4 and 5 and observe PIC program driven output.
>
> Output should change as you intend.