Programa de control para un motor de bicicleta con un PIC

Continuacion del articulo del diseño de un  controlador para  motor brushless parta bicicleta

Aunque es factible  implementar la tabla de verdad  del controlador brushless con  circuitos digitales sencillos, lo cierto es que esto es muy foco flexible  y bastante engorroso.

Gracias a   los microcontroladores,  podemos implementar nuestro circuito de una forma comoda, muy sencilla y extraordinariamente flexible ( al poder cambiar y mejorar el programa cauntas veces ncesitemos sin cambiar el hardware)

 

pic16f84a

Usaremos para ello un PIC16F84  con un reloj de 4Mhz   con las siguientes conexiones de entrada y salida:

SALIDAS

BO  ALIMENTACION  POSITIVA PRIMER BOBINADO      
B1   ALIMENTACION  POSITIVA SEGUNDO BOBINADO
B2 ALIMENTACION  POSITIVA TERCER BOBINADO
B3    TIERRA PRIMER BOBINADO
B4 TIERRA SEGUNDO BOBINADO
 B5 TIERRA TERCER BOBINADO

A0  SENSOR HALL A
A1  SENSOR HALL B
A2  SENSOR HALL C

Se muestra uan primera version básica ( pero FUNCAIONAL ) del programa de control del motor de bicicleta:

 

VERSION EN PIC-BASIC

‘****************************************************************
‘*  Name    : control_motor_bicicleta.BAS                                      *
‘*  Author  : Carlos Rodriguez Navarro                    *
‘*  Notice  : Copyright (c) 2009  *
‘*          : All Rights Reserved                               *
‘*  Date    : 27/08/2009                                        *
‘*  Version : 1.0                                               *
‘*  Notes   :                                                   *
‘*          :                                                   *
‘****************************************************************

symbol q1=portb.0     
symbol q2=portb.1
symbol q3=portb.2
symbol q4=portb.3   
symbol q5=portb.4
symbol q6=portb.5
symbol a=porta.0
symbol b=porta.1
symbol c=porta.2

TRISA=255
TRISB=0
loop   :
‘**** primero****
if a and b and (not c)then
 Q1=0
 Q2=0
  q3=1
  Q4=0
  q5=1
  Q6=0
endif
 
‘**segundo
if a and (not b)  and (not c) then
   Q1=0
   q2=0
  q3=1
  q4=1
  q5=0
  q6=0

 endif
 
‘***tercero
if a and (not b) and c then
  q1= 0
  q2=1
  q3=0
  q4=1
  q5=0
  q6=0
endif

‘****cuarto
if (not a) and (not b) and c then
 
  q1= 0
    q2=1
    q3=0
    q4=0
    q5=0
  q6=1

endif
‘**quinto
if (not a) and b and c then
 
  q1=1
  q2=0
  q3=0
  q4=0
  q5=0
 
  q6=1
endif
if not a and b and( not c) then
 
  q1=1
 q2=0
 q3=0
 q4=0
  q5=1
  q6=0

 

endif

 

  if not(a) and not (b) and not(c) then gosub borra
goto loop

borra:
q1=0
q2=0
q3=0
q4=0
q5=0
q6=0
return

 

 VERSION ENSAMBLADOR

 

NOLIST
; PicBasic Pro Compiler 2.43, (c) 1998, 2002 microEngineering Labs, Inc. All Rights Reserved.

LABEL?L macro Label
        RST?RP
    ifdef PM_USED
        LALL
Label
        XALL
    else
Label
    endif
    endm

LAND?BBW macro Bin1, Bin2, Wout
        MOVE?BB Bin1, FSR
        MOVE?BA Bin2
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LAND?BTW macro Bin, Regin, Bitin, Wout
        MOVE?BB Bin, FSR
        MOVE?TA Regin, Bitin
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LAND?TBW macro Regin, Bitin, Bin, Wout
        MOVE?TB Regin, Bitin, FSR
        MOVE?BA Bin
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LAND?TTW macro Regin1, Bitin1, Regin2, Bitin2, Wout
        MOVE?TB Regin1, Bitin1, FSR
        MOVE?TA Regin2, Bitin2
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LAND?WBW macro Win, Bin, Wout
        MOVE?BA Win
        iorwf   Win + 1, W
        movwf   FSR
        MOVE?BA Bin
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LAND?WTW macro Win, Regin, Bitin, Wout
        MOVE?BA Win
        iorwf   Win + 1, W
        movwf   FSR
        MOVE?TA Regin, Bitin
        L?CALL  LAND
        MOVE?AB Wout
        movwf   Wout + 1
    endm
LAND_USED = 1

LNOT?TB macro Regin, Bitin, Bout
        CHK?RP  Regin
        clrw
        btfss   Regin, Bitin
        movlw   -1
        MOVE?AB Bout
    endm

CMPF?WL macro Win, Label
        CLRWDT?
        MOVE?BA Win
        iorwf   Win + 1, W
        BIT?GOTO 1, STATUS, Z, Label
    endm

GOSUB?L macro Label
    local dlabel
    ifdef DEBUG_STACK
        CHK?RP  DEBUG_STACK
      ifdef DEBUG_STACK_ADDR
        bcf     STATUS, C
        rlf     DEBUG_STACK, W
        addlw   DEBUG_STACK_ADDR
        movwf   FSR
        movlw   low (dlabel)
        movwf   INDF
        incf    FSR, F
        movlw   (dlabel) >> 8
        movwf   INDF
      endif
        incf    DEBUG_STACK, F
    endif
        L?CALL  Label
dlabel
    endm

GOTO?L macro Label
        L?GOTO  Label
    endm

RETURN? macro
    ifdef DEBUG_STACK
        CHK?RP  DEBUG_STACK
        decf    DEBUG_STACK, F
    endif
        RST?RP
        return
    endm
 LIST

13 comentarios en “Programa de control para un motor de bicicleta con un PIC

  1. Ricardo Stocker Perez dijo:

    Intentare retomar lo que aprendi a manejar el puerto serie ya hace mucho tiempo .Creo que ahora usb. para hacer el programa directa mente del micro PC
    con la electronica de Potencia correspondiente mostrada aqui

    Un abrazo cordial

    Me gusta

  2. cesar dijo:

    hola amigo. estoy usando mosfets en el puente h para controlar un pequeño motor de cd rom pero calientan hasta romperse. ¿como puedo implementar un control pwm con pic basic pero que funcione? ¿tendras una idea? saludos

    Me gusta

  3. armando dijo:

    hola que tal esta interesante el proyectgo yo estoy inicando a programr en ensamblador por lo que no entiendo del todo su programa bueno eso es otra hisgtoria pero me preguntaba como se conectan los sensores al pic y al motor gracias si me pudierajn ayudar

    Me gusta

Deja un comentario

Este sitio utiliza Akismet para reducir el spam. Conoce cómo se procesan los datos de tus comentarios.