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.

PIC16F877A not detecting signal from the sensor

Status
Not open for further replies.

lloydi12345

Member
I have two PCBs. PCB1 contains PIC, Comparator and hbridge. PCB2 contains the IR LEDs and IR receiver modules. The first sensor is located at front, 2nd at left side of the mobile car and 3rd at the right side. I would like first to try it on flashing LEDs on the PIC before giving it a try on the motors. When an obstacle is detected in front, the 2nd LED will light. If an obstacle is detected on left, the 1st LED will light. If an obstacle is detected on right, the 3rd LED will light. I am having problems in using in the sensor part. The 1st sensor doesn't make the 2nd LED light even if I place an obstacle. Left sensor and right sensor works very well without any problems. The 3 IR receiver modules are different from each other that's why the schematic for each IR receiver module is different.

When I try PCB2 disconnecting from PCB1 and try PCB2 on a breadboard with only LM324 and variable resistor. The output of LM324 is connected to a visible LED to show that there is an obstacle detected. On if there's no obstacle and Off if there's an obstacle. The sensors are not having any problems at all. The 3 sensors function well. Is it possible to have problems with my program code?



Here's my source code:
Code:
	list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF




CBLOCK 0x21
	FIRST
	SECOND
	THIRD
ENDC


	ORG     0x000            
  	goto    main              ; go to beginning of program

	ORG     0x004 
; isr code can go here 


main

BANKSEL TRISC
MOVLW 0x00
MOVWF TRISC
MOVLW 0XFF                ;RB inputs (RB4-RB7 are the only port bits used as input)
MOVWF TRISB
BANKSEL PORTC

FORWARD:
	MOVLW B'00000001'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000010'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000100'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000101'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000110'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000111'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000000'
	MOVWF PORTC
	CALL DELAYY
	MOVLW B'00000111'
	MOVWF PORTC
	CALL DELAYY

MOVE:	
	BTFSS PORTB, 4
	GOTO SENSOR0
	GOTO SENSOR1
	
SENSOR0:
	BTFSS PORTB, 5
	GOTO SENSOR00
	GOTO SENSOR01
	
SENSOR00:
	BTFSS PORTB, 6
	GOTO SENSOR000
	GOTO SENSOR001
	
SENSOR01:
	BTFSS PORTB, 6
	GOTO SENSOR010
	GOTO SENSOR011
	
SENSOR1:
	BTFSS PORTB, 5
	GOTO SENSOR10
	GOTO SENSOR11
	
SENSOR10:
	BTFSS PORTB, 6
	GOTO SENSOR100
	GOTO SENSOR101
	
SENSOR11:
	BTFSS PORTB, 6
	GOTO SENSOR110
	GOTO SENSOR111

SENSOR000:
	MOVLW B'00000111'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR001:
	MOVLW B'00000011'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR010:
	MOVLW B'00000110'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR011:
	MOVLW B'00000010'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR100:
	MOVLW B'00000101'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR101:
	MOVLW B'00000001'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR110:
	MOVLW B'00000100'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE
	
SENSOR111:
	MOVLW B'00000000'
	MOVWF PORTC
	CALL DELAYY
	GOTO MOVE

	
	

DELAY:						;	1 second delay
		MOVLW .2
		MOVWF THIRD
LOOP_1_SEC:
		MOVLW .250
		MOVWF SECOND
LOOP_125_MS:
		MOVLW .250
		MOVWF FIRST
LOOP_.5_MS:
		NOP
		DECFSZ	FIRST,F
		GOTO	LOOP_.5_MS
		
		DECFSZ 	SECOND,F
		GOTO	LOOP_125_MS
		
		DECFSZ	THIRD,F
		GOTO	LOOP_1_SEC
		return

DELAYY:

		MOVLW .2
		MOVWF THIRD
LOOP_1_SECC:
		MOVLW .200
		MOVWF SECOND
LOOP_125_MSS:
		MOVLW .200
		MOVWF FIRST
LOOP_.5_MSS:
		NOP
		DECFSZ	FIRST,F
		GOTO	LOOP_.5_MSS
		
		DECFSZ 	SECOND,F
		GOTO	LOOP_125_MSS
		
		DECFSZ	THIRD,F
		GOTO	LOOP_1_SECC
		return


END
 

Attachments

  • PCB1.JPG
    PCB1.JPG
    83.1 KB · Views: 181
  • PCB2.JPG
    PCB2.JPG
    65.7 KB · Views: 174
Last edited:
hi,
Running your program in Oshonsoft shows that all 3 PORTB pins 4, 5,6 are normally high, as each one is set low a pin on PORTC goes high.

RC2 for B.6,,, RC0 for B.5 and RC1 for B.4
 
hi,
Running your program in Oshonsoft shows that all 3 PORTB pins 4, 5,6 are normally high, as each one is set low a pin on PORTC goes high.

RC2 for B.6,,, RC0 for B.5 and RC1 for B.4

Thank you fro the reply ericgibbs. So there's no problem with my software? Its all about hardware?
 
Do you think its about power problems? What if I'll change the power source of the Sensor's PCB? Will it help?

hi
I have not looked over the circuit diagram, how are you powering the project.??
 
I'm using 1 9v for the PCB and 4 1.5v for the motors.

hi,
Have you tried to measure the outputs of the LM324 directly to see if they are changing.?
This would eliminate any possibility that the program is at fault.
If you dont have a voltmeter, use a led and a 1k series resistor has high/low indicator,,OK.?
 
Status
Not open for further replies.

Latest threads

Back
Top