Can anyone help a newcomer?


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Oct 2009
    Posts
    13

    Default Can anyone help a newcomer?

    Hi everyone
    I'm new to the forum and on my first PIC project. I have built my own JDM2 programmer and test board. I have tried searching the forum but so far I haven't found an answer to my problem.

    I am building a telescope drive and I want to interface a Honeywell HOA2001 optical encoder to a 16F84. I want to drive Rb0/INT from the TTL output of the encoder so I can generate an edge triggered interrupt when the path is clear.

    When I connect the two directly RB0 does not rise above 1.6V and the interrupt is neve triggered. If I disconnec the output of the encoder is changing between 0 and 5v

    Does anyone have any experience of doing this or a schematic I could look at?

    Thanks
    Scopit

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Hi scopit

    Welcome to the forum. I can suggest you look at your TRISB settings. Have you set RB0 to input direction? If that doesn't work, don't be afraid to post your code here.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Smile Welcome

    Hi, Scopit

    a small piece of scheme showing , at least, the optobarrier + Pic input connection + supply could be very useful too.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    Hi scopit

    I can suggest you look at your TRISB settings. Have you set RB0 to input direction?
    Hi Jerson,
    Thanks for the welcome and the suggestion. RB0 is set to an input and I can connect the pin to 5V and trigger the interrupt routine manually. I have also tried enabling the internal pull ups via the option register, but no difference.

    Here's my code which is not the complete progam yet. I have been testing step by step to make sure I have configured correctly. Forgive me if it not the best written code, this is my first serious program!


    Any help is gratefully appreciated
    Scopit

    Code:
        list      p=16F84A             ; list directive to define processor
        #include <p16F84a.inc>         ; processor specific variable definitions
    
    ;       Set up constants
    
    TIMER		EQU		0x01			; TMR0 register address
    STATUS		EQU     0x03			; Status register address
    PORTA		EQU     0x05			; Bank0 PORTA register address
    PORTB		EQU     0x06			; Bank0 PORTB register address
    INTREG		EQU		0x0B			; INTCON register address
    OPTREG		EQU		0x81			; OPTION register address
    TRISA		EQU     0x85			; Bank1 PORTA register address
    TRISB		EQU     0x86			; Bank1 PORTB register address
    
    ; Set up constants
    
    TARGET		EQU		0x59			; Target interval ideal value of 89Dec 59Hex
    OLOOP1		EQU		0xE0			; Initial loop value for fine control 128
    ILOOP1		EQU		0xE0			; Initial loop value for coarse control 27H
    
    ; Registers for program varialbles
    
    OUTERL		EQU		0x10			; Fine control delay value register
    INNERL		EQU		0x11			; Coarse control delay value register
    STORE		EQU		0x12			; Temporary register
    OLOOP		EQU		0x13			; Fine control delay count register
    ILOOP		EQU		0x14			; Coarse control delay count register
    WREG		EQU		0x16			; Stores W reg during interrupt
    SREG		EQU		0x17			; Stores STATUS reg during interrupt
    
    ; Reset
    		ORG		0x00			; Power up and reset code start
    		GOTO	Setup			; Skip over interrupt routine
    
    ; Interrupt subroutine
    		ORG		0x04
    ; Store STATUS and W Registers in temporary locations
    		MOVWF	WREG
    		SWAPF	STATUS,W		; Does not affect STATUS bits
    		MOVWF	SREG
    ; Use PORTA bit 1 to signal interrupt
    		BSF		PORTA,1
    ;Display	
    		MOVF	STORE,0			; Move STORE to W
    		MOVWF	PORTB			; Display TMR0 value on PORTB1-7
    ; Clear Interrupts and flags
    		CALL	Intclr			; Clear interrupts and reset prescalar values
    ; Retore STATUS and W Registers from temporary locations
    		SWAPF	SREG,W			; Does not affect STATUS bits
    		MOVWF	STATUS
    		SWAPF	WREG,F
    		SWAPF	WREG,W
    		RETFIE					; Clears GIE bit in INTCON
    
    Setup
    ; 		Set up Ports
    		BSF			STATUS,5	; Switch to BANK1
    		MOVLW	 	0x00		; Move 00000000 to W
    		MOVWF		TRISA		; Set outputs RA0=PWM RA2=TMR0 RA3=Interrupt
    		MOVLW	 	0x01		; Move 00000001 to W
    		MOVWF		TRISB		; Set RB0 input, RB1--8 as outputs
    		BSF			STATUS,5	; Switch to Bank1
    ; Set up option register
    ;		BSF			OPTREG,7	; Enable PORTB pull ups
    		BSF			OPTREG,6	; Enable INTEDG, trigger RBO/INT on rising edge
    		BCF			OPTREG,3	; Assign Prescaler to TMR0
    		BSF			OPTREG,2	; Set prescalar to 1:256
    		BSF			OPTREG,1	; Set prescalar to 1:256
    		BSF			OPTREG,0	; Set prescalar to 1:256
    		BCF			STATUS,5	; Switch to Bank0
    ; Clear ports and flag register
    		CLRF		PORTA
    		CLRF		PORTB
    ;		CLRF		FLAG
    ; Initialise loop values
    		MOVLW		ILOOP1		
    		MOVWF		INNERL		; Initialise inner loop
    		MOVLW		OLOOP1		
    		MOVWF		OUTERL		; Initialise outer loop
    ; Clear interrupts
    		CALL		Intclr
    		BCF			INTREG,5	; Disable TOIE in INTCON
    		BSF			INTREG,4	; Enable INTE in INTCON
    		BSF			INTREG,7	; Enable GIE in INTCON
    
    ;		Main Program
    Main
    		BSF			PORTA,0		; PWM high clcle
    		CALL		Delay		; PWM high clcle
    		BCF			PORTA,0		; PWM low cycle
    		CALL		Delay		; PWM low cycle
    		GOTO		Main		; PWM high until interrupt on RB0
    
    ;		Subroutines
    
    Intclr
    ; Clear and enable interrupts
    ; Set bit 4 to enable INTE RB0/INT, 
    ; Clear all other bits
    		BCF			INTREG,0	; Clear RBO INT flag
    		BCF			INTREG,1	; Clear RBO INT flag
    		BCF			INTREG,2	; Clear TOIF flag
    ;Reset prescalar values in option register
    		BSF			STATUS,5	; Switch to Bank1
    		BSF			OPTREG,6	; Enable INTEDG, trigger RBO/INT on rising edge
    		BCF			OPTREG,3	; Assign Prescaler to TMR0
    		BSF			OPTREG,2	; Set prescalar to 1:256
    		BSF			OPTREG,1	; Set prescalar to 1:256
    		BSF			OPTREG,0	; Set prescalar to 1:256
    		BCF			STATUS,5	; Switch to Bank0
    		RETURN
    		
    Delay
    ; Delay subroutine to keep PWM pulse low
    ; Total number instructions (4+((Outer*5)=1)+(Inner*3)+1))
    		MOVF		OUTERL,0	; Copy Outer loop value to W
    		MOVWF		OLOOP		; Copy Outer loop value to loop count register
    Outer	
    		MOVF		INNERL,0	; Copy Inner loop value to W
    		MOVWF		ILOOP		; Copy Inner loop value to loop count register
    Inner
    		DECFSZ		ILOOP,1
     		GOTO		Inner
    
    		DECFSZ		OLOOP,1
     		GOTO		Outer	
    
    		RETURN
    
    ; End of subroutines
    
            END                       ; directive 'end of program'

  5. #5
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Scopit

    a small piece of scheme showing , at least, the optobarrier + Pic input connection + supply could be very useful too.

    Alain
    Hi Alain
    I don't have a good schematic tool but I hope the attached picture from the HOA2001 datasheet helps. I have added some comments on the connections.
    Thanks.
    Scopit
    Attached Images Attached Images  

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Question

    I note your Tx diode is rated @ 10 mA If ...

    you use 3.4 mA ...

    may be a bit weak ... try 330 Ohms.

    BTW did you verify the pic input ( out of the board ) with an Ohmmeter ???

    Could you describe the supply ??? ( regulator, capacitors value, Pic decoupling ? , Opto decoupling ? - HOA datasheet tells about ...)

    any .1µF between Pic supply Pins ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Alain
    Thanks for the input on the Tx diode. I have checked the output of the opto encoder and the pin is toggling so I am assuming the diode is working.
    I am using screw terminals to wire up the opto coupler and I have tested the connection to RB0 and it's good. I can also put a wire between the screw terminal and 5V and I can trigger the interrupt.

    The power supply is a regulated DC 6V 300mA plug type. On the board have a 7805 regulator with 10uf + 100nF decoupling capacitors. I have 100nF at the opto encoder supply.

    Thanks
    Danny

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Interrupts seem to be Valid ( Why use another name for INTCON reg ???)

    ... I will try the bread board now ...

    Alain
    Last edited by Acetronics2; - 17th October 2009 at 16:55.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Why use another name for INTCON reg ???
    This was because I could not get the interrupts to work at first. I didn't know if there was a problem to use INTCON and so I changed it. I did the same with OPTION....it was just desperation I spent hours on this!
    The problem appeared to be that I was using MOVFW to write to INTCON. Once I change to BCF/BSF everything worked!

  10. #10
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Alain
    I took your advice and increased the TX diode current. At the same time I tried a weak pull up on the output of the optical encoder. This seems to have done the trick and the interrupt is now being triggered.
    Thanks very much to you and Jerson for taking the time to help me.
    I will stay on the forum, it's a very useful resource.
    Danny

  11. #11
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scopit View Post
    I tried a weak pull up on the output of the optical encoder. This seems to have done the trick and the interrupt is now being triggered.
    Seems it wasn't a solution
    It is now in that frustrating state of intermittent

  12. #12
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scopit View Post
    The power supply is a regulated DC 6V 300mA plug type. On the board have a 7805 regulator with 10uf + 100nF decoupling capacitors. I have 100nF at the opto encoder supply.
    That 6v adaptor won't give a lot of headroom to the 5v reg if it is a standard 7805 style one - this might cause inconsistencies if it is borderline on the regulation and cannot supply the current for the opto LED. I always design at least 2 and ideally over 3v more input than the output of the reg.
    Do you have a 9v DC plug pack you could try ?

    Bill.

  13. #13
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bcd View Post
    Do you have a 9v DC plug pack you could try ?
    Bill.
    Hi Bill
    The plug pack is switchable, I'll up it to 7.5 & 9v and see if it makes a difference.
    I suspect the problem is between the receiver and the PIC as the input to RB0 is clamped at 1.65V.
    But at the moment, I'll try anything!
    Thanks for the input and I'll get back to you once I've tested
    Danny

  14. #14
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Here's the latest!

    I have upped the PSU voltage and checked all the connections.With a pull up resistor the optical encoder output switches between 1.3 and 4.4 volts.

    It will trigger the interrupt the first time it goes high. No further interrupts occur.
    If I reset with encoder output low, then the first low low to high transition triggers the interrupt.
    If I reset with encoder output high, then the interrupt is not triggered.

    If I replace the encoder output with a switch to 5volts, I can trigger multiple interrupts so the software looks like it's working.

    Any ideas anyone?
    Thanks
    Danny

  15. #15
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Look at Table 4.3 and Table 9.2 of the 16F84A datasheet. When configured as an External Interrupt, RB0 has a Schmitt Trigger input buffer which needs 0.8*Vdd for a logic high and 0.2*Vdd for logic low. Your voltages appear to be marginal.
    Last edited by dhouston; - 18th October 2009 at 20:36.

  16. #16
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    Look at Table 4.3 and Table 9.2 of the 16F84A datasheet. When configured as an External Interrupt, RB0 has a Schmitt Trigger input buffer which needs 0.8*Vdd for a logic high and 0.2*Vdd for logic low. Your voltages appear to be marginal.
    Thanks Dave, I'll check the voltages again but from your post, the problem may be on the logic low.

  17. #17
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scopit View Post
    Thanks Dave, I'll check the voltages again but from your post, the problem may be on the logic low.
    I agree - after sensing the first high, it never senses a low, so it cannot sense another low-to-high transition.

  18. #18
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scopit View Post
    Thanks Dave, I'll check the voltages again but from your post, the problem may be on the logic low.
    It appears that after sensing the first high, it never senses a low, so it cannot sense another low-to-high transition.

  19. #19
    Join Date
    Oct 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    It appears that after sensing the first high, it never senses a low, so it cannot sense another low-to-high transition.
    Thanks Dave you were right. I removed the pull up and in the process found a dry joint. This may have been the source of the issue in the first place, but was causing the intermittent behaviour.

    Interrupt is working now and I can continue working through the testing.

    Thanks everyone for your help.
    Danny

Similar Threads

  1. Hlp - newcomer getting confused
    By chunk in forum General
    Replies: 1
    Last Post: - 23rd January 2006, 19:47
  2. 12F629 config help for newcomer
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th January 2004, 23:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts