Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Infra red sensor based control of Stepper motor.

Status
Not open for further replies.

Prosenjit101

Newbie level 5
Joined
Apr 18, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dhaka, Bangladesh
Activity points
1,349
The purpose is to open or close a faucet by the application
of a stepper motor.
The stepper motor will work by receiving signals from a PIC16F877A microntroller.
This microntroller will be connected to a heat sensor.
Most probabbly a IR detector.
So i have outlined the code below.
However, the code isnt working.
And i am unable to debug.
A little guidance will be greatly appreciated.
Code:
	list		p=16f877
 	include		<p16f877.inc>
	__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF

	c1 equ 0x21;  Timer counter
	c2 equ 0x22;

	ANTI equ 0x23;
	CLCK equ 0x24;

	org   0x00;
    goto  start; // skip over interrupt vector
    org   0x04;
    goto  serviceinterrupts;

start
	call	clearall;
	call	initport;
	call	inittimer;
	call	ini_adc;
	bsf		INTCON, GIE;
	bsf		INTCON, T0IE;

Get_Input
	call 	ADC;
	call	stay_stuck;
	goto 	Get_Input;

ADC
	bsf ADCON0, 0; ADON: A/D On bit. 1 = 0n, 0 = OFF
	bsf ADCON0, 2; GO/DONE: A/D Conversion Status bit. 1 = conversion in progress, 0 = conversion not in progress

	; CHS2:CHS0: Analog Channel Select bits [111 = Channel 7 (AN7)]
	bsf ADCON0, 3; CHS0 = 1
	bsf ADCON0, 4; CHS1 = 1
;	bsf ADCON0, 5; CHS2 = 1

polling 
	btfsc ADCON0,2; Checking for A/D Conversion Status bit. If ADCON0 = 1, loop continues. If ADCON0 = 0, skips "goto polling"
goto polling;
	
	movf ADRESH,0;
	movwf c2;
	return;

clearall
	clrf	c1;
	clrf	c2;
	clrf	ANTI;
	clrf	CLCK;
	return;

initport
	bsf     STATUS, RP0;
	movlw   b'00000000'; Make all pins of port B as output
	movwf   TRISB;
	bcf     STATUS, RP0;
	return;

inittimer
 	clrf    TMR0;
   	bsf     STATUS, RP0;
   	movlw	b'00000011';
	movwf	OPTION_REG;
    bcf     STATUS, RP0;
	return;

ini_adc;
	bsf STATUS,RP0;
	movlw 0x00;
	movwf ADCON1;
	bcf STATUS,RP0;
    return;

serviceinterrupts
	bcf 	INTCON, T0IF;
	movlw	.5;
	movwf	TMR0;
	incf	c1,1;
	retfie;

rotate_antclck	
		   		;dcba
    movlw  b'00000010';  b'00000001';
	movwf  PORTB;
;	call   delay;
	movlw  b'00000001';  b'00000010'
	movwf  PORTB
;	call   delay;
	movlw  b'00001000';   b'00000100'
	movwf  PORTB
;	call   delay;
	movlw  b'00000100';   b'00001000'
	movwf  PORTB
;	call   delay;
	movlw  b'00000010';   b'00001000'
	movwf  PORTB
;	call   delay;

	movlw .1;
	movwf ANTI;

	movlw .0;
	movwf CLCK;

	call Get_Input;
	return;

rotate_clck	
		   	;dcba
	movlw  b'00000100'; b'00001000'
	movwf  PORTB
;	call   delay;
	movlw  b'00001000'; b'00000100'
	movwf  PORTB
;	call   delay;
	movlw  b'00000001'; b'00000010'
	movwf  PORTB
;	call   delay;
	movlw  b'00000010'; b'00000001';
	movwf  PORTB;
;	call   delay;
	movlw  b'00000100'; b'00001000'
	movwf  PORTB
;	call   delay;

	movlw .0;
	movwf ANTI;

	movlw .1;
	movwf CLCK;

	call Get_Input;
	return;

stay_stuck
	call delay;
	call Checking_for_IR;
	goto stay_stuck;

Checking_for_IR
	movlw c2;
	sublw .5; 	//Giving the ON value, if both are same
	btfss STATUS, C;	BTFSS f,b ...testing for IR.If bit ‘b’ in register ‘f’ is ‘0’, the next
									;instruction is executed.If bit ‘b’ is ‘1’, then the next instruction
									;is discarded and a NOP is executed instead.

	call IR_1;			if IR = 1, then C = 0, this line is executed.
	call IR_0;			if IR = 0, then C = 1, this line is executed.			
	return;

IR_1
	movlw ANTI;
	xorlw .0; 
	btfss STATUS, Z;

	call rotate_antclck;	As IR = 1, if Z = 0, this line is executed.
	call delay;				As IR = 1, if Z = 1, this line is executed.
	return;
IR_0
	movlw CLCK;
	xorlw .0; 
	btfss STATUS, Z; if CLCK = 0, then Z = 0
					;if CLCK = 1, then Z = 1
					;BTFSS f,b ...testing for IR.If bit ‘b’ in register ‘f’ is ‘0’, the next
									;instruction is executed.If bit ‘b’ is ‘1’, then the next instruction
									;is discarded and a NOP is executed instead.

	call rotate_clck;	As IR = 0, if Z = 0, this line is executed.
	call delay;			As IR = 0, if Z = 1, this line is executed.
	return;
	

delay		;delay after light off is 2-times(repeat1+repeat2)
	clrf    c1;

repeat		;delay 1sec
	movf	c1,0;
	xorlw	.250; 
	btfss	STATUS,Z;
	goto	repeat;
    return;


    end

The Proteus version of the circuit.
Untitled.png
 

I wish you luck with your project but would like to just suggest you should be careful to
design a "fail-safe" one - especially if using IR.
(I'd hate you to come home to a flooded house because the sun came out.... ;-) )
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top