Problem with PIC basic code *.bas


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    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.

  2. #2
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Hi Mister_e
    Your right !!! on base of transister need to add R 1k .

    I will explan for my problem
    1. If we used code #1 (show as below) only the function of software will ok no problem
    if push sw_l ,sw_r motor backword and forword ...ok

    2. If we add code #2 (show as below) the function not ok
    a. the motor forword only not
    b. No repond if we push sw_l and sw_r

    I think may some error druing pic runing and may hung due to time over .....but i cannot find the problem
    ...I more exprien for pic (first study)

    thank you for advise


    My problem :

    we used microcode studio for careted code basic code and complier with PBP2.45 .

    #1
    '================================================= ==
    @ DEVICE PIC16F84a, WDT_OFF,PWRT_ON, PROTECT_OFF

    OPTION_REG.7=0 ' turn on internal Pull-up.
    TRISA = %00001111
    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
    right var PORTA.1
    fwd var PORTA.2
    bkd var PORTA.3

    n var Byte
    n = 0
    pause 150

    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
    goto start





    '===========================
    #2
    '==========================
    @ DEVICE PIC16F84a, WDT_OFF,PWRT_ON, PROTECT_OFF

    OPTION_REG.7=0 ' turn on internal Pull-up.
    TRISA = %00001111
    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
    right var PORTA.1
    fwd var PORTA.2
    bkd var PORTA.3

    n var Byte
    n = 0
    pause 150

    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 decode

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

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

    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

    iF COMMAND = 13 THEN
    high left
    PAUSE 800

    ENDIF

    goto start

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


    Did you find this post helpful? Yes | No

    Default

    Many times you use something like:
    IRpulse_length(0)

    I never see that kind of variable use so the question is...What should it do??? OR what do you want to do. I guess you want to store your results in an array so.. you'll have to declare your variable as an array
    something like

    IRpulse_length var word [20]

    and when you want to store/read from, use
    IRpulse_length[ArrayLocation]


    The reason why your switches don't work is because of those pulsin. look into your manual section 5.59 DEFINE PULSIN_MAX. This can help but not as efficient as you need to decode IR signal.

    In your case i'll prefer measuring incoming pulses by using Timer in an interrupt routine. Interrupt will be given by your IR receiver.. DUH!
    Steve

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

  4. #4
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    thank you for your advise
    i will try it again.

Similar Threads

  1. Indexer not indexing...a basic PBP problem??
    By jellis00 in forum General
    Replies: 8
    Last Post: - 24th March 2009, 17:53
  2. I want to buy PIC BASIC PRO...
    By simransingh in forum General
    Replies: 2
    Last Post: - 30th October 2007, 18:13
  3. Electrical noise problem with PIC 16f84
    By Snap in forum General
    Replies: 11
    Last Post: - 26th September 2007, 10:36
  4. Replies: 5
    Last Post: - 20th March 2006, 02: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, 05: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