Please explain about this program


Results 1 to 7 of 7

Threaded View

  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

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