Stepper motor with L293B and pic16f648A


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Posts
    5

    Default Stepper motor with L293B and pic16f648A

    Hi.
    Im trying to make a stepper motor move right or left with this pic.
    I've connected everything according to examples and the datasheets but still no movement.
    i guess its my code and im missing something. i would really appreciate if someone can please point me in the right direction.

    DEFINE ADC_CLOCK 3
    steps var word
    stepArray var byte(4)

    CMCON = 7
    TRISA = 1
    TRISB = %11110000
    PORTB = %11111111
    input porta.0
    input porta.1
    stepArray[0] = %00001010
    stepArray[1] = %00000110
    stepArray[2] = %00000101
    stepArray[3] = %00001001

    pause 500

    main:
    if porta.1 = 1 then
    steps = steps + 1
    endif

    if porta.0 = 1 then
    steps = steps -1
    endif

    PORTB = stepArray[steps // 4]
    pause 3

    goto main

    the motor is connected on port b - 0-3 and the buttons are on pins a0 and a1
    anyone?

    thanks in advance,
    Shahar

  2. #2
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello, try with this modified code:

    Code:
    DEFINE OSC 4    'Change it for your osc
    DEFINE ADC_CLOCK 3
    steps var word
    stepArray var byte(4)
    x var byte
    
    CMCON = 7
    TRISA = %00000011   'Porta.0 and porta.1 as input
    TRISB = %00000000   'Portb as output, 0=Output, 1=Input
    PORTB = 0
    x=0
    'input porta.0      ' You dont need this, just TRISA command
    'input porta.1
    stepArray[0] = %00001010
    stepArray[1] = %00000110
    stepArray[2] = %00000101
    stepArray[3] = %00001001
    
    pause 500
    
    main:
    if porta.1 = 1 then
         for x=0 to 3
    PORTB = stepArray[x]
    pause 20 'Change it for diferent speed
    next x
    endif
    
    if porta.0 = 1 then
    
    for x=0 to 3
    PORTB = stepArray[3-x]
    pause 20  'Change it for diferent speed
    next x
    endif
    
    
    
    goto main
    Last edited by Raflex; - 31st March 2008 at 01:41.

  3. #3
    Join Date
    Jan 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Not there yet...

    Thanks Raflex but it still doesnt work. when i use this program with the simulator it gets nothing - the stepper motor isnt even getting ready and all PORTB is not an output.
    when i used the original code - i saw the motor getting ready (green) but when i pressed the button - it didnt do anything.

    anyone?

  4. #4
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by manjero View Post
    Thanks Raflex but it still doesnt work. when i use this program with the simulator it gets nothing - the stepper motor isnt even getting ready and all PORTB is not an output.
    when i used the original code - i saw the motor getting ready (green) but when i pressed the button - it didnt do anything.

    anyone?
    Check the configuration fuses, mclr, internal or external osc, etc:

    Code:
    @ DEVICE pic16F648a, INTRC_OSC_NOCLKOUT
    ' System Clock Options (HS_OSC, INTRC_OSC, INTRC_OSC_NOCLKOUT)
    @ DEVICE pic16F648a, WDT_OFF 
    ' Watchdog Timer 
    @ DEVICE pic16F648a, PWRT_OFF 
    ' Power-On Timer 
    @ DEVICE pic16F648a, MCLR_OFF 
    ' Master Clear Options (External) 
    @ DEVICE pic16F648a, BOD_ON 
    ' Brown-Out Detect 
    @ DEVICE pic16F648a, LVP_OFF 
    ' Low-Voltage Programming 
    @ DEVICE pic16F648a, CPD_OFF 
    ' Data Memory Code Protect 
    @ DEVICE pic16F648a, PROTECT_OFF 
    ' Program Code Protection
    Last edited by Raflex; - 31st March 2008 at 07:35.

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