Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

optocoupler question

Status
Not open for further replies.
im not sure about the diagram eric no, i just saw this one sitting around the garage and thought i could play with it.

okay eric i will take this path instead since its economical lols (i dont have the 555 yet), looks like i need to make changes first to the code on the part of option_reg, like you said to set to detect either a low or high going edge on the RB0

i will report back thank you

thanks for you patience
 
im not sure about the diagram eric no, i just saw this one sitting around the garage and thought i could play with it.

okay eric i will take this path instead since its economical lols (i dont have the 555 yet), looks like i need to make changes first to the code on the part of option_reg, like you said to set to detect either a low or high going edge on the RB0

i will report back thank you

thanks for you patience

OK,
Whats your location.?

If you need a hand with the code, post what you have.
 
eric im guessing?

bsf INTCON,6

Thats correct, but dont forget to Enable the PIC's interrupts, if you are using an ISR routine.

Post your code when ready.
 
Last edited:
eric, im sorry for the late response im the family cook lols

the 2k2 and 2k3 mean 2.2k and 2.3k or 220k and 230k?


Code:
LIST	p=16F84		                ;tell assembler what chip we are using
	include "P16F84.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC 
                                        ;sets the configuration settings (oscillator type etc.) or RC_OSC if thats what your using


org	0x000


STATUS	     equ	0x03	
PORTA	     equ	0x05	
PORTB	     equ	0x06	
TRISA	     equ	0x85	
TRISB	     equ	0x86	
INTCON       equ        0x0B 

goto         Initialise

;***************INTERRUPT ROUTINE***************

org         0x04           

BSF         PORTA,0x00
bcf         INTCON,1
retfie                               
           
Initialise	


bsf                INTCON,7         
bsf                INTCON,6
bsf                INTCON,4        
bcf                INTCON,1         


BSF     STATUS,5    	
MOVLW   b'00000001' 
MOVWF   PORTB       
BCF     STATUS,5    
MOVLW   b'00000000'
MOVWF   PORTA
            
end

the code is crude i removed the last lesson where theres a blinking LED. thanks in advance more power to you and all the people here, you guys are mint. im falling in love to electronics lol

i understand this is one shot after the LED turned on i need to restart the 16f84
 

Attachments

  • question.JPG
    question.JPG
    25.4 KB · Views: 193
Last edited:
The 2K2 and 3K3 mean 2.2K and 3.3K

The 'K' is often used to replace the decimal point.:)

I have downloaded your program.
 
hi,
I have modified your program a bit.

On every positive going edge on PORTB.0, PORTA.1 pin will go high for 0.5seconds.

You can use this to flash an LED on PORTA.1 to test your B.0 interrupt.


If you download from microchip the free MPLAB IDE V7.xx assembler and use the header section in my program you will not have to redefine the function registers.
 

Attachments

  • coin1.asm
    1 KB · Views: 161
lol i feel sorry for my code.

thanks for all your help eric, i learned a lot from you today.

i am writing it now to the PIC.
 
hello guys it's me again and more 20-questions forgive me.

dear eric, i realised that the signal coming from the mech was not positive, instead negative, sorry about the confusion, this thing is really way over my head obviously but i'll keep trying. i failed miserably to make your resistor-divider solution work, i'll keep the code tho thank you.

i made a drawing, hope it'd answer few questions to be asked or had already been asked about what i'm trying to accomplish here.

the LED will be replaced by a PIC with RBO waiting for the pin to go high.

Code:
	list	p=16F84A	; list directive to define processor
	#include <p16F84A.inc>	; processor specific variable definitions
	errorlevel -302, -207

	__config _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

CounterA	equ 0ch
CounterB	equ 0dh
CounterC	equ 0eh



;***************INTERRUPT ROUTINE***************  
	org	0x000		; processor reset vector
	goto	main		; go to beginning of program


	org	0x004		; interrupt vector location
	bcf	INTCON,1
	
	bsf	PORTA,1
	call	delay1
	bcf 	PORTA,1

	retfie	 
		 

main:
	bsf	INTCON,7         
	bsf	INTCON,6
	bsf	INTCON,4        
	bcf	INTCON,1         


	bsf	STATUS,RP0  
	movlw	b'00000001' 
	movwf	PORTB 
      	movlw	b'00000000'
	movwf	PORTA

	bcf	STATUS,RP0  
	
idle_loop:
	
	nop


	goto idle_loop

delay1:	
;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
		movlw	D'3'
		movwf	CounterC
		movlw	D'138'
		movwf	CounterB
		movlw	D'85'
		movwf	CounterA
loop		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		decfsz	CounterC,1
		goto	loop
		retlw	0	 
	end

thanks for your code eric.


maybe 30ms pulse is very fast, it happens so quick that the optocoupler does not have enough time to saturate the transistor, i don't know.

i found this 6N139, High Speed Optocoupler, 100 kBd, Low Input Current, Photodiode Darlington Output, you think it will help, trigger the 555?

i tried connecting the signal wire directly to RBO with pull up resistor as to what kpatz and eric had taught me in recent posts, but to no avail.

whats next? i seem like i have ran into some wall lol

thanks for your input
 

Attachments

  • question.JPG
    question.JPG
    25.6 KB · Views: 191
attached pic above is wrong heres the right one

hi,
Looking at your circuit the 0V lines of the coin mech and the rest of the circuit are on a common 0V and the fact the coin mech switch is powered from only +12V, where is the negative pulse coming from.??

I think you are misunderstanding coin switch mech output.
If it goes from +12V to 0V, its not a negative pulse, its a low going pulse which can be connected to the PIC PORTB.0 using the resistor divider discussed earlier.

The opto and 555 are not required if the coin switch is switching the +12V high or low [n/c or n/o]

Please measure the actual pulse levels from the coin switch and tell me what you find.:)

BTW: a 30mSec pulse is not fast.
 
Last edited:
the color red line sir is the wire where the pulse was sent.

why i know it should be connected to the cathode part of the opto, because when i measured the coin mech for voltage, it read no volt if positive probe of my multitester was used with it, but when negative probe was i will get a reading of 12v provided sw1 was NC, but when sw1 was set to NO however i get zero volt reading. this is whats going on when the coin mech was plugged but coins were not inserted yet.

i don't know if the pulse was rising edge or falling edge. if this helps, i can see my LED blink once and very fast after coin was inserted and when sw1 was NC (LED was lit already since there's 12v), using the opto and 555 circuit. when sw1 was NO (LED was off state and signal wire was 0v), no blinking going on after coin was inserted, again with the opto and 555 approach. I guess this says the pulse here was falling edge? and i should use BCF rather than BSF in my code? or this is something else?

how about i will eliminate the 555 circuit but leave the opto to send positive voltage to the resistor divider using NC? and change the code from rising edge to falling edge instead?

about directly wiring the signal wire to the RB0 with matching resistor divider, the signal wire is negative? is this still plausible since i gave wrong info earlier about the polarity of the signal wire.

thanks for you input guys
 

Attachments

  • question2.JPG
    question2.JPG
    29.8 KB · Views: 201
  • question.JPG
    question.JPG
    25.4 KB · Views: 195
Last edited:
i also noticed that the pulse was going downwards e.g. when 12v N/C, the multitester needle moved toward zero volts. when N/O, the needle did not move.
 
Last edited:
i also noticed that the pulse was going downwards e.g. when 12v N/C, the multitester needle moved toward zero volts. when N/O, the needle did not move.

hi wejos,
Like we said its a low going pulse,[not negative] switching from +12V to 0V for about 30mSec.

Use the 3.3K and 2.2K resistor divider as before, connect the junction of the divider to PORTB.0 and set the program to Interrupt on a low going edge.

Thats all you need do..
No opto's or 555, the PIC will easily interrupt on a 30mS pulse..:)

I'll check the program you posted.
 
Last edited:
okay eric thank you for all your help. thank you also for your patience. i'm kind of bit slow.

i just posted again your code, it's your code i inserted there.

i'll check again my breadboard i must have screwed up something or somewhere when i tried them.

thank you again
 
okay eric thank you for all your help. thank you also for your patience. i'm kind of bit slow.

i just posted again your code, it's your code i inserted there.

i'll check again my breadboard i must have screwed up something or somewhere when i tried them.

thank you again

hi,
Your code detects the PORTB.0 interrupt OK.
Make sure you select PORTB.0 falling [low going] edge.
 
guys eric, its working now thank you appreciate all your help

i found out my breadboard was causing all the problems, the holes are not any more virgin lol, the wires become lost in space lol

very interesting stuff
 
Hi,

In the name of the Father, the Son, and the Holy Ghost, and the Wholly Resurrected thread... :)

Why use this thread, why not start your own thread?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top