Problem with PIC basic code *.bas


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    70

    Red face Problem with PIC basic code *.bas

    I have try to make car robot and have problem with my code need all friend to help.

    Pls help to verify why did not work thank


    '************************************************* ***************
    '* Name : IR_car3.BAS *
    '* Author : *
    '* : *
    '* Notice : Copyright (c) 2005 *
    '* : ALL Rights Reserved *
    '* Date : 10/3/2003 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    ''************************************************ ****************

    @ DEVICE PIC16F84a, WDT_OFF,PWRT_ON, PROTECT_OFF

    TRISA = %00011111
    TRISB = %11111111
    DEFINE OSC 4

    IRpulse_length var word
    xx var Byte
    Command Var Byte
    Device Var Byte
    sw_l var PORTB.0
    sw_r var PORTB.1


    left var PORTA.0 'turn left
    right var PORTA.1 'turn right
    fwd var PORTA.2 'go
    bkd var PORTA.3 'back

    n var Byte
    n = 0
    'pause 150

    enable INTERRUPT

    START:
    LOW BKD
    HIGH FWD
    PAUSE 150
    If sw_l = 0 then
    HIGH BKD
    LOW FWD
    PAUSE 800
    LOW BKD
    LOW FWD

    else
    iF SW_r = 0 THEN
    HIGH BKD
    LOW FWD
    PAUSE 800
    LOW BKD
    LOW FWD

    ENDIF
    endif

    'Ir decoder

    PULSIN Portb.2,0,IRpulse_length(0)
    IF IRpulse_length(0) = 0 THEN start

    for xx =1 to 18
    pulsin Portb.2,0,IRpulse_length(xx)
    next xx

    disable INTERRUPT
    displaybits:
    if IRpulse_length(1) < 100 then
    Command.bit0 = 0
    Else
    Command.bit0 = 1
    endif
    if IRpulse_length(2) < 100 then
    Command.bit1 = 0
    Else
    Command.bit1 = 1
    endif
    if IRpulse_length(3) < 100 then
    Command.bit2 = 0
    Else
    Command.bit2 = 1
    endif
    if IRpulse_length(4) < 100 then
    Command.bit3 = 0
    Else
    Command.bit3 = 1
    endif
    if IRpulse_length(5) < 100 then
    Command.bit4 = 0
    Else
    Command.bit4 = 1
    endif

    if IRpulse_length(6) < 100 then
    Command.bit5 = 0
    Else
    Command.bit5 = 1
    endif

    if IRpulse_length(7) < 100 then
    Command.bit6 = 0
    Else
    Command.bit6 = 1
    endif
    Command.bit7 = 0
    Command = Command + 1
    If Command = 10 then
    Command = 0
    Endif

    if IRpulse_length(8) < 100 then
    Device.bit0 = 0
    Else
    Device.bit0 = 1
    endif
    if IRpulse_length(9) < 100 then
    Device.bit1 = 0
    Else
    Device.bit1 = 1
    endif
    if IRpulse_length(10) < 100 then
    Device.bit2 = 0
    Else
    Device.bit2 = 1
    endif
    if IRpulse_length(11) < 100 then
    Device.bit3 = 0
    Else
    Device.bit3 = 1
    endif
    'Device.bit1 = 0

    low portb.7

    'SEROUT Porta.3,sbaud,[#Device," - ",#Command,13,10]
    iF COMMAND = 13 THEN
    high left
    PAUSE 800

    ENDIF
    RESUME
    ENABLE INTERRUPT
    'pause 100
    goto start

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi chai98a

    schematic and a few more details on what you want to do will be appreciated. Tell us what's working and what's not.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Here is circuit of my project
    Attached Images Attached Images  

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.K. few things, there's no Pull-ups attach to yiur switches, but you can use the internal one... it can help

    OPTION_REG.7=0 ' turn on internal Pull-up.


    since you didn't declare any interrupt stuff you don't need to write Enable Interupt and Disable Interupt.

    Your TRISA definition is not right BUT High and Low do the job for you to correct it. I MEAN TRISA%00001111 will set PORTA<3:0> to input and PORTA<7:4> to output.

    what is the actual current needed by you motor? Is there any driver between your PIC and you motors? Are they DC type, Step, Servo?

    That's what i see as now
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Angry

    We use dc motor 3 vdc and driver with Transister (see circuit on attached)
    Let you mark new code sample for me too thank you. Plsssss.
    Attached Images Attached Images  
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    ssssssssssffffff BANG!

    I'm looking to your schematic and few things are wrong. Now all your transistors and/or few PIC i/o could be destroyed. by not using any resistor to your transistor base, you ask to PIC to drive as much current as I=E/R... aboute infinite. AND no clamping diode on Transistor while driving inductive load is for sure going to destroy your transistors really soon.

    can you, before changing everything, remove your transistor and use Leds, mini lamp, multimeter on PIC output to see if there's any signal that goes out.

    you can also use some H-Bridge driver to drive your Motor directly and make your design smaller on the final-Board.

    Do you also know the current needed by your Motor... not suppose to be really high. If you plan to use transistor i can do some schematic for you if you need or if you don't find any all over the net... wich i doubt!

    BUT if i need to drive a motor and i don't have any H-Bridge driver IC or they're current unsufficient, i'll prefer to use mosfet instead of bjt transistor due to the lowest voltage drop across and many more other reason but that's another story.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Indexer not indexing...a basic PBP problem??
    By jellis00 in forum General
    Replies: 8
    Last Post: - 24th March 2009, 16:53
  2. I want to buy PIC BASIC PRO...
    By simransingh in forum General
    Replies: 2
    Last Post: - 30th October 2007, 17:13
  3. Electrical noise problem with PIC 16f84
    By Snap in forum General
    Replies: 11
    Last Post: - 26th September 2007, 09:36
  4. Replies: 5
    Last Post: - 20th March 2006, 01:34
  5. How to use 93C46 Type EEPROM using PIC Basic PRo
    By in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st April 2003, 04:07

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