Can anyone help a newcomer?


Closed Thread
Results 1 to 19 of 19

Hybrid View

  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,614


    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 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  

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


    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 " !!!
    *****************************************

  6. #6
    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

  7. #7
    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'

Similar Threads

  1. Hlp - newcomer getting confused
    By chunk in forum General
    Replies: 1
    Last Post: - 23rd January 2006, 18:47
  2. 12F629 config help for newcomer
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th January 2004, 22: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