Sensor reading Program Help Required


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Posts
    29

    Lightbulb Sensor reading Program Help Required

    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!

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I made a lot of assumptions since you don't mention the PIC type, osc speed, etc, but something like this should work.
    Code:
        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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Exclamation theres a bit change now

    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!
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Review some of the Microchip DC motor control application notes here:
    http://www.microchip.com/stellent/id...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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  3. Compile and Program help using PICKit2
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th March 2009, 14:51
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30

Members who have read this thread : 0

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