Please explain about this program


Closed Thread
Results 1 to 7 of 7
  1. #1
    wafagenius's Avatar
    wafagenius Guest

    Default Please explain about this program

    I need someone to help me explain about this program and tell me if there is error occur. I will attached the circuit altogether if someone know about the circuit error if any.I am new in picbasic and electronic,I beg all expert out there, please help me......!

    ' PicBasic Pro program
    ' 10-bit A/D conversion
    ' Balancing robot using Sharp GP2D12
    ' Use a 16f876 pic mcu from microchip

    define osc 20
    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result was 10
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS was 50
    define DEBUG_REG PORTB
    define DEBUG_BIT 5
    define DEBUG_BAUD 9600
    define DEBUG_MODE 1
    define DEBUG_PACING 500


    tiltfor var word ' ET Sensor Forward
    tiltbac var word ' ET sensor Back
    lwheel var word ' Left wheel zero speed
    rwheel var word ' Right wheel zero speed
    speed var word ' speed variable
    k con 7 ' k factor
    smax con 500 ' speed limiter

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and right justify result


    'lwheel=747 'zero calibrate left wheel
    'rwheel=747 'zero calibrate right wheel

    speed=0
    start:

    debug "Balbot ET"
    pause 1000
    high portc.2
    pause 1000
    low portc.2

    adcin 1, lwheel 'read trimmer for left wheel zero speed

    adcin 2, rwheel 'read trimmer for right wheel zero speed

    loop:

    adcin 0, tiltfor ' Read channel 0 to adval

    adcin 4, tiltbac

    speed = abs (tiltfor - tiltbac)* k

    if speed > smax then speed = smax

    if tiltbac > tiltfor then back


    forward:

    low portc.0
    pulsout portc.0,(lwheel + speed) 'left wheel
    pause 5
    low portc.1
    pulsout portc.1,(rwheel - speed) 'right wheel
    pause 5

    goto loop

    back:

    low portc.0
    pulsout portc.0,(lwheel - speed) 'left wheel
    pause 5
    low portc.1
    pulsout portc.1,(rwheel + speed) 'right wheel
    pause 5

    goto loop

    End
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You say please explain this program but you need to be more specific. What is it that doesn't work? Does the PIC run? Does it have power? Do you get the debug message? Do you get the reading from the ADC? Does the robot run but will not balance?

    You say that you are new to PBP, and that's OK, we've all been there, but if you need us to explain the whole program you are aiming to high for a beginner. If that's the case start with the standard LED blinking and hello world projects, then go from there.

    If you have specific qestions, don't hesitate.

    /Henrik Olsson.

  3. #3
    wafagenius's Avatar
    wafagenius Guest


    Did you find this post helpful? Yes | No

    Default Its not fully working

    The PIC is running,it have power,there is a reading on ADC,there is no error message while compiling.However after burn it to PIC only one of the motor working.I have no idea what is going on. in configuration bits the setting is "oscillator is HS mode" and "watchdog timer is ON" and other configuration is off.I have attached the circuit,I really need help

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    I looked at the code and it seems that if one wheel is turning the other should too, codewise. I think you have an electrical problem or perhaps a bad servo.

    Try swapping the left and right servo connectors to see if it's the actual servo that doesnt work. If the one that doesn't work now start working when you swap places it's either something in the code or a bad connection on the circuitboard. Do you have 6V and GND on both servo connectors?

    It can also be a bad pin on the PIC, can you try moving the servo control lines from PortC.0 and PortC.1 to PortB.0 and PortB.1 for example. Don't forget to change the code accordingly.

    /Henrik Olsson.

  5. #5
    wafagenius's Avatar
    wafagenius Guest


    Did you find this post helpful? Yes | No

    Default Thanks For Looking

    Thanks anyway MR HenrikOlsson due to your explaination. I really appreciated it. I will look into what you have suggested.

    Regards

    Hasnul Wafa

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Tie up loose ends

    wafagenius,
    Addition to other's suggestions: Tie all unused PIC pins to ground or power, do not allow pins to float, many strange and unwanted things occur with open pins.
    Your schematic shows many unused pins.
    Joe

  7. #7
    wafagenius's Avatar
    wafagenius Guest


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks Bro for the suggestion.

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. Help with DS18B20 program
    By presario1425 in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 22nd August 2012, 00:50
  3. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  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 : 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