PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   PIC12F675 tại sao lúc chạy lúc không (http://www.picvietnam.com/forum/showthread.php?t=2704)

comando 14-08-2008 08:27 PM

PIC12F675 tại sao lúc chạy lúc không
 
1 Attachment(s)
chào các bạn trong diễn đàn!!! mình khi sử dụng PIC12F675 thiết kế mạch điều khiển động cơ bước như sơ đồ bên dưới. không hiểu sao mạch lúc chạy lúc không khi tắt nguồn cấp lại thì có khi mạch chạy( khoảng 10 lần thì có 1 lần mạch chạy) đúng có khi mạch không chạy và có khi mạch chạy sai (chân GPIO,5 không phát xung). kiểm tra nguồn thì đúng 5v mình sử dụng dao động nội.
Không biết là do sai sót phần cứng hay phần mềm mong các cao thủ trong diễn đàn giúp đỡ!
Mình đã mô phỏng bằng proteus và đã chạy tốt!!! không lẽ là do phần cứng???????? :((
dưới đây là code asm

Code:

list      p=12f675  ;list directive to define processor
#include "p12f675.inc"  ;processor specific variable definitions
__CONFIG _CPD_ON & _CP_ON & _BODEN_OFF  &_PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
;-----------------------------------------------------------------
;-----------------------------------------------------------------
;variables
;-----------------------------------------------------------------
  cblock  0x20
ADC_value_lo
ADC_value_hi
CounterA
CounterB
storeDELAY
storeAD
sobuoc,sobuoc_H,sobuoc_L
offset0,offset1,PRODHI,PRODLO,COUNT,RAMx,RAMy,K                ;1buoc=4step
offsetb
  endc

TRANGTHAI        equ                0x0f                ; 1=thuan , 0=nghich
;----------------------------------------------------------------
REV                        EQU                0
;----------------------------------------------------------------
OUTPUT                EQU                05              ;GPIO
;------------------------------------------------------------------
;initialisation
;------------------------------------------------------------------
        org  0
        GOTO MAIN
        ORG                0X05
MAIN

          banksel        ANSEL                ;CHON THANH GHI ANSEL
          movlw            11h        ;AN0 as analog input,conversion clock Fosc/8
          movwf            ANSEL
          bankseL          CMCON                ;TAT BO SS
          movlw            07h        ;comparators off
          movwf            CMCON               
          movlw          0x01              ;ADC on, right justified,ADFM = 0=> adc 8 bit
          movwf            ADCON0                ;THIET LAP ADC


movlw          B'001001'              ;AN0= ANALOG INPUT, GPI3= ENABLE
TRIS          GPIO
CLRF          GPIO                ;to motor driver circuitry
;--------------------------------------
;test
;--------------------------------------
MOVLW  D'4'       
MOVWF  storeDELAY

;--------------------------------------
        MOVLW          B'0'                        ;offsetb cua buoc dau tien
        MOVWF          offsetb
        MOVWF          offset0
        bsf GPIO,1
        bsf GPIO,2

lap
BTFSC        GPIO,3
GOTO        lap

call        read_ADC
MOVF        storeAD,w
MOVWF        offset1                        ;ket qua AD cat vao offset1
                                                ;
                                                ;tinh ra so buoc va chieu quay

MOVF          offset0,w                ;lay offset1-offset0=sobuoc               
SUBWF        offset1, 0                ;ket qua cat vao sobuoc
MOVWF  sobuoc
BSF    TRANGTHAI,REV        ;quay thuan rev=1 ko can dao dau so bit

BTFSC        STATUS,C                ;neu ket qua am c=0 thi dao dau so buoc
goto        next_main
BCF                TRANGTHAI,REV        ;quay nghich rev=0
COMF    sobuoc                    ;REG = two's-complement of REG.
INCF    sobuoc   
next_main
                                ;so am c=0

;--------------------------------------------------
MOVLW  D'4'                                ;kiem tra sobuoc <= 4 thi thoat
SUBWF sobuoc, 0                                ;so buoc >= w thi        c=1
BTFSS STATUS, C                                ;so buoc < w thi        c=0
GOTO  exit
MOVF        offset1,w                ;lay lai offset0
MOVWF        offset0

call        DK_MOTOR
exit
goto lap
;-------------------------------------------------------------------------------
;chuong trinh dieu khien dong co buoc
;2 tham so nhap vao la chieu quay rev va sobuoc
;-------------------------------------------------------------------------------
DK_MOTOR:

BTFSS            TRANGTHAI,REV
goto    net

INCF    offsetb,1
movlw        b'00000011'                ;lay ma stepper
ANDWF        offsetb,0
zia
call        Table_THUAN


MOVWF  OUTPUT
call        DELAY
DECFSZ        sobuoc,1
goto        DK_MOTOR

movlw        b'00000011'                ;lay ma stepper
ANDWF        offsetb,1
return


net
DECF    offsetb,1
movlw        b'00000011'                ;lay ma stepper
ANDWF        offsetb,0
goto        zia
;---------------------------------------------------------------------
;read_ADC
;function to read ADC
;returns high and low bytes (10 bits) in ADC_value_hi
;and ADC_value_lo variables. Value is right-justified.
;CHUONG TRINH DOC ADC 10BIT KET QUA CAT VAO
;---------------------------------------------------------------------
read_ADC:
          banksel ADCON0                        ;
          bsf    ADCON0,1                  ;start conversion
WaitADC:
          btfss    PIR1,ADIF                ;The PIR1 register contains the interrupt flag bits
          goto    WaitADC              ;wait for ADC to finish; ADIF: A/D Converter Interrupt Flag bit
GetADC1:
          movf    ADRESH, W                  ;get high byte
        movwf    storeAD
          movwf    ADC_value_hi
          banksel  PIR1
          bcf    PIR1,ADIF                  ;clear conversion flag

          return
;----------------------------------------------------------------------

DELAY       
        movf        storeDELAY,w
        movwf        CounterB
        movwf        CounterA
loop_d        nop
        decfsz        CounterA,f
        goto        loop_d
        decfsz        CounterB,f
        goto        loop_d
return 
;----------------------------------------------------------------------- 
ORG 0x80
Table_THUAN
          ADDWF  PCL, F
          RETLW          B'11001111'        ;xx00x11x                03
          RETLW          B'11011101'        ;xx01x10x                06
          RETLW          B'11111001'        ;xx11x00x                0C
        RETLW        B'11101011'        ;xx10x01x                09
return       
end


namqn 14-08-2008 10:59 PM

Sơ đồ của bạn đã post lên thể hiện một mạch điều khiển dùng PIC16F506 (14 chân). Vậy chính xác thì bạn thực hiện mạch với PIC12F675 ra sao?

Thân,


Múi giờ GMT. Hiện tại là 05:03 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam