PDA

View Full Version : Sensor reading Program Help Required



shaiqbashir
- 27th April 2006, 16:12
Hi Guys!

well this is my first post on this forum. I hope that you guys will help me as much as possible. Im making a certain robot for which i have used Stepper motors for the drive wheels. Im posting the coding below. this coding will make the motor to run 20 revolutions and then stop. have a look at this:

TrisB=%00000000
y var byte
x var byte
low portB.4
low portB.5
low portB.6
low portB.7
start:
for x= 0 to 20
for y=1 to 50
high portB.1
low portB.0
low portB.2
high portB.3
pauseus 1500
high portB.3
high portB.0
low portB.1
low portB.2
pauseus 1500
high portB.0
low portB.1
high portB.2
low portB.3
pauseus 1500
high portB.2
low portB.0
high portB.1
low portB.3
pauseus 1500
next y
next x
end

according to this program the motor will be running in TWO PHASE MODE. now the problem is this that we have to detect a white reflector tape line to a certain point using two LED-Phototransistor sensors. When both the sensors will signal high output the motor has to stop and move further. Now the thing is that how i should use this statement

if (portB.0=1) and (portB.1=1) then start

start:

some other routine to perform

I want to work in the way im writing below:

The robot should start running straight first. As soon as it detects the white reflector tape on both the sensor pins, it should go to some other routine and discontinued the previous one. and if it has not detect that yet than it should keep moving forward.

How i can put this If condition in the above coding.

I shall be thankful to u for ur quick and effective reply.

Regards

Take carez

Good Bye!

Bruce
- 2nd May 2006, 22:35
I made a lot of assumptions since you don't mention the PIC type, osc speed, etc, but something like this should work.


y var byte
x var byte
Loop VAR BYTE ' used for delay loop
Time CON 25 ' 60 x 25uS = 1500 uS for PAUSEUS loop

Sensor1 VAR PORTB.7 ' sensor 1 input
Sensor2 VAR PORTB.6 ' sensor 2 input

PORTB.4 = 0 ' ununsed output
PORTB.5 = 0 ' unused output
TRISB = %11000000 ' RB6, RB7 sensor inputs, rest outputs

OPTION_REG = 0 ' internal pull-ups off

on Interrupt Goto IntService ' where to go on interrupt
INTCON = %10001000 ' RB port change interrupt enabled

Start:
for x= 0 to 20
for y=1 to 50
PORTB = %00001010
for Loop = 0 TO 59
pauseus Time ' pause 25uS per pass allowing faster interrupt
next Loop ' service time (assumes 4MHz osc)
PORTB = %00001001
for Loop = 0 TO 59
pauseus Time
next Loop
PORTB = %00000101
for Loop = 0 TO 59
pauseus Time
next Loop
PORTB = %00000110
for Loop = 0 TO 59
pauseus Time
next Loop
next y
next x
GOTO Start ' Assumption on my part here?

IntService: ' Object detected by sensors
Disable
while (Sensor1=1) AND (Sensor2=1) ' stay here until both return low

' do something useful here

wend
INTCON.0 = 0 ' clear RB port change interrupt flag bit
resume
Enable ' return after processing object detection

end
Using RB6 & RB7 as sensor inputs you could have the interrupt generated on change.

The Loop with pauseus cuts down on the time it takes for the polled BASIC interrupt to be serviced.

shaiqbashir
- 3rd May 2006, 15:40
Hi Bruce

thanks for that tremendous help. I perhaps forgot to tell u that much detail. here is the detail you wanted:

Im using PIC16F84A with 4MHz crystal oscillator. And one more thing that i wanted to tell you is this that im using the DC motor (PWM control method) now instead of using stepper motors. So please tell me in the perspective of the DC motors. I shall be thankful to u for this.

One more favor that i want from u is this that please tell me any coding through which i can control the revolutions of the DC motor. I mean i want to program my motor in such a way that it takes 3 revoultions with a defined speed and then stops and then take 4 revolutions and then stops again and so on.

I shall be thankful to u for this act of kindness.

Take carez

Good Bye!

Bruce
- 3rd May 2006, 16:05
Review some of the Microchip DC motor control application notes here:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1505&pageId=64

Decide on the components you plan to use, put together a schematic, then
take a shot at putting together your code to make it work.

If you have problems with a particular code segment, motor drive circuit, etc,
then post what you have done so far here.

People here are more than willing to offer assistance, but most prefer to see
that you have made an effort to solve the problem yourself first.

There are several threads on this forum as well on DC motor control. Use the
search button for DC Motor Control.