Menu

A servo program that does not work

Help
2008-04-21
2013-05-30
  • Nobody/Anonymous

    My  intencion was to do a step motor controller program with a 16F628 but the result is not working at all,
    I don't see the truoble, for that i recuest from you the answer for the problem, thanks you in advance for your help

    the program is this:

        #chip 16F628A, 4
        #config CP_OFF, DATA_CP_OFF, PWRTE_OFF, WDT_OFF, LVP_OFF, MCLRE_OFF, _INTOSC_OSC_NOCLKOUT
        dir PORTB b'00000000' 'PORTB.3 as output
        dir PORTA b'11111111
    '
        #define DIRECC porta.0
        #define ENABLE porta.1
        'porta.0 = Direccion
        'porta.1 = Enable
        dim CM(8) as byte
        dim PL as byte
        CM(1)=1:CM(2)=3:CM(3)=2:CM(4)=6:CM(5)=4:CM(6)=12:CM(7)=8:CM(8)=9
    seguir:  
        if DIRECC=0 and ENABLE=1 then derecha(PL) 
        if DIRECC=1 and ENABLE=1 then izquierda(PL)
        wait 20 ms
    goto seguir

        sub derecha(PL) ' hace step a la derecha
        Pl=Pl+1
        set portb = CM(PL)
        if PL = 8 then PL = 1
        return

        sub izquierda(PL) ' hace step a la izquierda
        PL=PL-1
        set portb = CM(PL)
        if PL = 1 then PL = 8
        return

        end

     
    • kent_twt4

      kent_twt4 - 2008-04-21

      Think you are really close here.  Just a few things:

      Even though it compiles, enclose the binary with quotes, "dir PortA b'11111111'".

      Dimension the array "dim CM(8)", because that is what you are describing http://gcbasic.sourceforge.net/help/.

      GCBasic automatically dimensions byte size variables so no need for "dim PL as byte".

      To set a port to a binary variable, just use "PortB = CM(PL)".

       
    • Nobody/Anonymous

      Thanks you Kent for your prompt reply, I will modify the program and test again!!

       

Log in to post a comment.