منتدى التحكم الآلي والإلكترونيات
مرحبا بك عزيزي الزائر يشرفنا أن تقوم بالدخول إذا كنت من الأعضاء أو التسجيل إذا كنت زائرا ويمكنك إنشاء حسابك ببساطة ويمكنك التفعيل عن طريق البريد أو الانتظار قليلا حتى تقوم الإدارة بالتفعيل
منتدى التحكم الآلي والإلكترونيات

Automatic control , PLC , Electronics , HMI , Machine technology development , Arabic & Islamic topics , Management studies and more
 
الرئيسيةالبوابة*مكتبة الصوراليوميةس .و .جبحـثالتسجيلقائمة الاعضاءالمجموعاتدخول

شاطر | 
 

 اريد المساعده في تحويل هذا البرنامج من .asmbالى .c

استعرض الموضوع السابق استعرض الموضوع التالي اذهب الى الأسفل 
كاتب الموضوعرسالة
marwanbs
جندي
جندي


عدد الرسائل : 1
العمر : 30
تاريخ التسجيل : 14/06/2012

مُساهمةموضوع: اريد المساعده في تحويل هذا البرنامج من .asmbالى .c   الخميس 14 يونيو 2012 - 6:58

سلام عليكم

اريد المساعده في تحويل هذا البرنامج من .asmbالى .c
;**************************************************************************************
;PROGRAM : VF CONTROL OF 3-PHASE INDUCTION MOTOR (MAIN ROUTINE)
;MICROCONTROLLER : PIC16F777
;CRYSTAL FREQUENCY : 20MHZ
;**************************************************************************************
;AUTHOR : RAKESH PAREKH, MICROCHIP TECHNOLOGY INC.
;DATE : 15-DEC-2003
;VERSION : V1.0
;APPLICATION NOTE : AN889
;**************************************************************************************
;*
;* Software License Agreement
;*
;* The software supplied herewith by Microchip Technology Incorporated
;* (the “Company”) for its PICmicro® Microcontroller is intended and
;* supplied to you, the Company’s customer, for use solely and
;* exclusively on Microchip PICmicro Microcontroller products. The
;* software is owned by the Company and/or its supplier, and is
;* protected under applicable copyright laws. All rights are reserved.
;* Any use in violation of the foregoing restrictions may subject the
;* user to criminal sanctions under applicable laws, as well as to
;* civil liability for the breach of the terms and conditions of this
;* license.
;*
;* THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
;* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
;* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
;* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
;* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
;* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
;**************************************************************************************
;DESCRIPTION
;**************************************************************************************
;THIS SOFTWARE IMPLEMENTS VF CONTROL OF AC INDUCTION MOTOR IN OPEN LOOP USING PIC16F777.
;THE MOTOR FREQUENCY IS CHANGED BY VARYING THE POTENTIOMETER, INTERFACED AT RA1 PIN.
;VOLTAGE TO FREQUENCY RATIO IS MAINTAINED CONSTANT THROUGHOUT THE OPERATING RANGE.
;**************************************************************************************
;FEATURES
;**************************************************************************************
;3 PHASE AC INDUCTION MOTOR RUN USING OPEN LOOP VF CONTROL
;START/STOP SWITCH INTERFACE (SWICTH AT RB1)
;ROTATION DIRECTION REVERSAL SWITCH INTERFACE (SWITCH AT RB0)
;MOTOR FREQUENCY SET BY POTENTIOMETER (POT AT RA1)
;MOTOR FREQUENCY IS LIMITED BETWEEN 5Hz AND 60Hz.
;LED INDICATION OF RUN/STOP AND FWD/REV STATUS OF MOTOR
;RUN/STOP LED AT RD1 AND FWD/REV LED AT RD0
;UV AND OV LIMIT
;UV_LED AT RD2 AND OV_LED AT RD3
;ACCELERATION AND DEACCELERATION TIME SETTING
;**************************************************************************************
;FLAGE MOTOR_DIRECTION = (0 FOR REVERSE) OR (1 FOR FORWARD)
;FLAGE MOTOR_RUNNING = (0 FOR STOP) OR (1 FOR RUN)
;RUN_STOP_LED = (ON FOR RUN) OR (OFF FOR STOP)
;FWD_REV_LED = (ON FOR FORWARD) OR (OFF FOR REVERSE)
;V_F_FLAG = (0 FOR ADC CHANNEL FOR F) OR (1 FOR ADC CHANNEL FOR V)
;UV_LED = (ON FOR UV LIMIT ACTIVATION) OR (OFF FOR VOLTAGE > UV LIMIT)
;OV_LED = (ON FOR OV LIMIT ACTIVATION) OR (OFF FOR VOLTAGE < OV LIMIT)
;**************************************************************************************
;NOTE
;USER CAN CHANGE THE MOTOR FREQUENCY LIMIT IN AD_CONV_COMPLETE ROUTINE
;IF ACCELERATION AND DECELERATION FEATURE IS NOT REQUIRED, COMMENT '#DEFINE RAMP' IN PARAMETERS.INC
;**************************************************************************************
LIST P = P16F777
__CONFIG H'2007',H'3FAA'
__CONFIG H'2008',H'3FBC'
INCLUDE
INCLUDE
;**************************************************************************************
UDATA_SHR
W_TEMP RES 1 ;LOCATION FOR SAVING 'WREG' DURING INTERRUPT
STATUS_TEMP RES 1 ;LOCATION FOR SAVING 'STATUS' DURING INTERRUPT
FLAGS RES 1 ;FLAGS REGISTERS USED TO INDICATE DIFFERENT STATUS
FREQ_REF_H RES 1 ;REFERANCE FREQUENCY INPUT(MSB) IN TIME COUNTS
FREQ_REF_L RES 1 ;REFERANCE FREQUENCY INPUT(LSB) IN TIME COUNTS
SET_FREQ RES 1 ;REFERANCE FREQUENCY INPUT IN COUNTS
TEMP_LOC RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_1 RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_2 RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
NO_1_LSB RES 1 ;NUMERATOR(LSB) AND QUOTIENT(LSB) OR MULTIPLIER(LSB)
NO_1_MSB RES 1 ;NUMERATOR(MSB) AND QUOTIENT(MSB) OR MULTIPLIER(MSB)
NO_2_LSB RES 1 ;DENOMINATOR(LSB) OR MULTIPLICAND(LSB)
NO_2_MSB RES 1 ;DENOMINATOR(MSB) OR MULTIPLICAND(MSB)
RESULT_LSB RES 1 ;RESULT OF MULTIPLICATION(LSB)/REMAINDER(LSB)
RESULT_MSB RES 1 ;RESULT OF MULTIPLICATION(MSB)/REMAINDER(MSB)
VDC_COUNT RES 1 ;DIGITAL COUNT OF DC BUS VOLTAGE

UDATA
TABLE_OFFSET1 RES 1 ;PHASE1 OFFSET TO THE SINE TABLE(0)
TABLE_OFFSET2 RES 1 ;PHASE2 OFFSET TO THE SINE TABLE(120)
TABLE_OFFSET3 RES 1 ;PHASE3 OFFSET TO THE SINE TABLE(240)
TMR2_INT_COUNT RES 1 ;COUNTER TO MEASURE 4MS USING TMR2 OV INT
SINE_TABLE_RAM RES 0X14 ;SINE TABLE

EXTERN SET_ADC_GO
EXTERN NEW_FREQ
EXTERN FLAG_FREQ
EXTERN DEC_COUNTER_LSB
EXTERN DEC_COUNTER_MSB
EXTERN ACC_COUNTER_LSB
EXTERN ACC_COUNTER_MSB
EXTERN TEMP_COUNTER_LSB
EXTERN TEMP_COUNTER_MSB
EXTERN TEMP_FREQ

GLOBAL SET_FREQ
GLOBAL FLAGS
GLOBAL NO_1_LSB
GLOBAL NO_1_MSB
GLOBAL NO_2_LSB
GLOBAL NO_2_MSB
GLOBAL SET_FREQ
GLOBAL FREQ_REF_L
GLOBAL FREQ_REF_H
GLOBAL TEMP_LOC
GLOBAL TEMP_LOC_1
GLOBAL TEMP_LOC_2
GLOBAL RESULT_MSB
GLOBAL RESULT_LSB
;**************************************************************************************
;MACRO FOR MULTIPLICATION - 8X8 UNSIGNED
;**************************************************************************************
MULT MACRO BIT ;MACRO FOR UNSIGNEDMULTIPLICATION
BTFSC NO_1_LSB,BIT
ADDWF RESULT_MSB,F
RRF RESULT_MSB,F
RRF RESULT_LSB,F
ENDM ;END OF MACRO FOR MULTIPLICATION

;**************************************************************************************
;POWER ON RESET VECTOR LOCATION
;**************************************************************************************
STARTUP CODE 0X00 ;RESET VECTOR ADDRESS
GOTO START

CODE 0X04 ;INTERRUPT VECTOR LOCATION
GOTO ISR_INT ;GOTO INTERRUPT SERVICE ROUTINE

;**************************************************************************************
PROG0 CODE
START
;**************************************************************************************
;INITIALIZATION OF THE PORTS AND TIMERS
BANKSEL WDTCON
CLRF WDTCON
CLRF FLAGS ;CLEAR ALL FLAGS
BANKSEL FLAG_FREQ
CLRF FLAG_FREQ ;CLEAR ALL FLAGS
BCF STATUS,RP1
BSF STATUS,RP0
MOVLW 0X1F
MOVWF TRISB ;RB0-4 AND RB5-RB7 CONFIGURED AS INPUT AND OUTPUT RESPECTIVELY
MOVLW 0XF9
MOVWF TRISC ;RC1-RC2 CONFIGURED AS OUTPUT RESPECTIVELY
MOVLW 0XF0
MOVWF TRISD ;RD0-3 AND RD4-RD7 CONFIGURED AS OUTPUT AND INPUT RESPECTIVELY
BCF TRISE,4
BCF STATUS,RP0
MOVF PORTB,W
MOVLW 0XF0 ;TURN OFF ALL LEDS
MOVWF PORTD

MOVLW 0X0C
MOVWF CCP1CON ;CCP1,CCP2 AND CCP3 CONFIGURED TO PWM
MOVWF CCP2CON
BSF STATUS,RP0
MOVWF CCP3CON

CALL STOP_MOTOR ;STOP MOTOR
BANKSEL PR2
MOVLW PR2_VALUE ;LOAD PR2 VALUE TO PR2 REGISTER
MOVWF PR2
BCF STATUS,RP0
BSF T2CON,TMR2ON ;TIMER2 ON
CALL COPY_TABLE_TO_RAM ;COPY SINE TABLE FROM PROGRAM MEMORY TO RAM FOR FASTER ACCESS

;**************************************************************************************
;INITIALIZE ADC REGISTERS
;**************************************************************************************
BANKSEL ADCON0
MOVLW 0X91
MOVWF ADCON0 ;CONFIGURE FOR 32TOSC AND CHANNEL FOR CONVERSION - RA2 (DC BS VOLTAGE)
BSF STATUS,RP0
MOVLW 0x0B ;CONFIGURE RA0-RA3 AS ANALOG INPUT
MOVWF ADCON1
MOVLW 0X31 ;SETTING OF ACQUISITION TIME FOR ADC (~25usec)
MOVWF ADCON2
MOVLW 0X0F ;RA0-RA3 INPUT and RA4-RA7 OUTPUT
MOVWF TRISA
BCF STATUS,RP0
BCF PORTA,DRIVER_ENABLE ;ENABLE INVERTER DRIVERS - IR2109

;**************************************************************************************
;TIMRE1 INITIALIZATION WITH PRESCALER - USED FOR SETTING OF MOTOR FREQ.
;**************************************************************************************
MOVLW 0X31 ;LOAD THE T1CON WITH CONTROL WORD
MOVWF T1CON ;FOR TMR1 ON AND PRESCALAR IS 1:8, INTERNAL CLOCK

;**************************************************************************************
;TIMRE0 INITIALIZATION WITH PRESCALER - USED FOR ACCELERATION,DECELERATION
;AND ADC TRIGGER FOR FREQ. CONV.
;**************************************************************************************
BCF STATUS,RP0
CLRF INTCON ;DISABLE ALL INTERRUPTS AND FLAGS ASSOCIATED WITH
CLRF PIR1 ;DISABLE ALL INTERRUPT FLAGS
CLRF PIR2 ;DISABLE ALL INTERRUPT FLAGS
BSF STATUS,RP0
CLRF PIE1 ;DISABLE ALL INTERRUPTS
CLRF PIE2 ;DISABLE ALL INTERRUPTS

MOVLW 0X03 ;SET #POR AND #BOR FLAGS
MOVWF PCON
BCF STATUS,RP0
BSF INTCON,RBIE ;ENABLE RB PORT CHANGE INTERRUPT FOR RB4
BSF INTCON,PEIE ;PERIPHERAL INTERRUPTS ENABLE
BSF INTCON,GIE ;GLOBAL INTERRUPT ENABLE

;**************************************************************************************
;INFINITE LOOP
;**************************************************************************************
LOOP
BTFSS FLAGS,TIMER1_OV_FLAG ;IS TMR1 OV FLAG SET?
GOTO BYPASS ;NO
BCF FLAGS,TIMER1_OV_FLAG ;CLEAR TMR1 OV FLAG
CALL UPDATE_PWM_DUTYCYCLES ;YES, UPDATE THE PWM DUTY CYCLE WITH NEW VALUE
CALL UPDATE_TABLE_OFFSET ;UPDATE 3 OFFSETS
BYPASS
CALL SET_ADC_GO ;START AD CONVERSION AND CALCULATE TMR1 RELOAD VALUES BASED ON POT SETTING
CALL KEY_CHECK ;CHECK KEYS CHANGE
GOTO LOOP ;GO BACK TO MAIN LOOP
;******************************************************************
;INTERRUPT SERVICE ROUTINE
;******************************************************************
ISR_INT
MOVWF W_TEMP ;COPY W TO A TEMPORARY REGISTER
SWAPF STATUS,W ;SWAP STATUS NIBBLES AND PLACE INTO W REGISTER
MOVWF STATUS_TEMP ;SAVE STATUS TO A TEMPORARY REGISTER IN BANK0

BANKSEL PIR1
BTFSC INTCON,RBIF ;RB INTERRUPT?
GOTO CHECK_FAULT ;YES - OVER CURRENT FAULT
BTFSC PIR1,TMR1IF ;TIMER1 OVERFLOW INTERRUPT?
GOTO TIMER1_OVERFLOW ;YES - INTERRUPT FOR UPDATING TMR1 REGISTERS BASED ON POT SETTING
BTFSC PIR1,ADIF ;ADC CONVERSION COMPLETE INTERRUPT?
GOTO AD_CONV_COMPLETE ;YES - CONVERSON RESULT 'F - MOTOR FREQUENCY' OR 'V - DC BUS VOLTAGE'
BTFSC PIR1,TMR2IF
GOTO TMR2_ISR

POPUP ;RETRIEVE SAVED WREG AND STAUS REGISTER VALUES
SWAPF STATUS_TEMP,W ;SWAP ORIGINAL STATUS REGISTER VALUE INTO W (RESTORES ORIGINAL BANK)
MOVWF STATUS ;RESTORE STATUS REGISTER FROM W REGISTER
SWAPF W_TEMP,F ;SWAP W_TEMP NIBBLES AND RETURN VALUE TO W_TEMP
SWAPF W_TEMP,W ;SWAP W_TEMP TO W TO RESTORE ORIGINAL W VALUE WITHOUT AFFECTING STATUS
RETFIE ;RETURN FROM INTERRUPT
;******************************************************************
TIMER1_OVERFLOW ;TMR1 OVERFLOW ISR
MOVF FREQ_REF_H,W
MOVWF TMR1H ;LOAD THE HIGHER BYTE OF SPEEDCOMMAND TO TMR1H
MOVF FREQ_REF_L,W
MOVWF TMR1L ;LOAD THE LOWER BYTE OF SPEEDCOMMAND TO TMR1L
BSF FLAGS,TIMER1_OV_FLAG
BCF PIR1,TMR1IF ;CLEAR TMR1IF
GOTO POPUP
;******************************************************************
CHECK_FAULT
MOVF PORTB,F ;READ PORTB TO ITSELF TO END MISMATCH CONDITION
BTFSS FLAGS,MOTOR_RUNNING
GOTO NO_ACTION
BTFSS PORTB,FAULT_BIT ;CHECK FOR FAULT BIT
GOTO THERE_IS_FAULT ;YES, FAULT OCCURRED, STOP MOTOR
CALL RUN_MOTOR_AGAIN ;FAULT CLEARED?
NO_ACTION
BCF INTCON,RBIF ;RUN MOTOR AGAIN
GOTO POPUP

THERE_IS_FAULT ;YES,FAULT IS THERE
CALL STOP_MOTOR ;STOP MOTOR
BCF INTCON,RBIF
GOTO POPUP

;*****************************************************************
AD_CONV_COMPLETE ;ADC INTERRUPT
BCF PIR1,ADIF ;ADIF FLAG IS CLEARED FOR NEXT INTERRUPT
BTFSS FLAGS,V_F_FLAG ;DOES CONVERSION RESULT REFLECT DC BUS VOLTAGE?
GOTO CONV_IS_FREQ ;NO - READ RESULT AS POT SETTING OF FREQ.
GOTO CONV_IS_BUS_VOLTAGE ;YES - READ RESULT AS DC BUS VOLTAGE

CONV_IS_FREQ
BANKSEL NEW_FREQ
MOVF ADRESH,W ;READ AD CONVERSION RESULT
MOVWF NEW_FREQ ;CHECK FOR LOWER AND UPPER ALLOWED LIMIT OF FREQ.
SUBLW 0X13 ;MINIMUM FREQUENCY SET TO 5HZ (SCALING FACTOR X4)
BTFSS STATUS,C ;IS POT SETTING FOR FREQ, MORE THAT LOWER SET LIMIT?
GOTO CHECK_UPPER_LIMIT_FREQUENCY ;YES - NOW CHECK UPPER LIMIT
MOVLW 0X14 ;NO - SET FREQ. TO LOWER ALLOWED LIMIT - 5HZ (X4)
MOVWF NEW_FREQ
GOTO POPUP

CHECK_UPPER_LIMIT_FREQUENCY
MOVLW 0XF1
SUBWF NEW_FREQ,W
BTFSS STATUS,C ;IS POT SETTING MORE THAN ALLOWED UPPER LIMIT OF FREQ?
GOTO POPUP ;NO - RETURN FROM INTERRUPT
MOVLW 0XF0 ;YES - SET FREQ TO UPPER ALLOWED LIMIT - 60HZ (X4)
MOVWF NEW_FREQ
GOTO POPUP

CONV_IS_BUS_VOLTAGE
MOVF ADRESH,W
MOVWF VDC_COUNT
SUBLW LIMIT_V_LOW ;UV LIMIT SET TO 20% OF 115VAC = 92VAC
BTFSS STATUS,C ;IS DC BUS VOLTAGE LESS THAN LOWER LIMIT?
GOTO CHECK_UPPER_LIMIT_VOLTAGE ;NO - NOW CHECK UPPER LIMIT
BSF LED_PORT,UV_LED ;YES - TURN ON LED TO INDICATE SAME
CALL STOP_MOTOR ;STOP MOTOR
BCF FLAGS,MOTOR_RUNNING ;CLEAR MOTOR_RUNNING FLAG
GOTO POPUP ;RETURN FROM INTERRUPT

CHECK_UPPER_LIMIT_VOLTAGE
MOVLW LIMIT_V_HIGH ;OV LIMIT SET TO 20% OF 115VAC = 138VAC
SUBWF VDC_COUNT,W
BTFSS STATUS,C ;IS DC BUS VOLTAGE MORE THAN UPPER LIMIT?
GOTO VOLTAGE_WITHIN_LIMIT ;NO
BSF LED_PORT,OV_LED ;YES - TURN ON LED TO INDICATE SAME
CALL STOP_MOTOR ;STOP MOTOR
BCF FLAGS,MOTOR_RUNNING ;CLEAR MOTOR_RUNNING FLAG
GOTO POPUP ;RETURN FROM INTERRUPT

VOLTAGE_WITHIN_LIMIT
BCF LED_PORT,UV_LED ;DC BUS VOLTAGE WITHIN SPECIFIED LIMIT
BCF LED_PORT,OV_LED ;TURN OFF UV_LED AND OV_LED
GOTO POPUP ;RETURN FROM INTERRUPT

;******************************************************************
TMR2_ISR
BCF PIR1,TMR2IF
BANKSEL TMR2_INT_COUNT
DECFSZ TMR2_INT_COUNT,F
GOTO POPUP

MOVLW 0X50
MOVWF TMR2_INT_COUNT

BANKSEL FLAG_FREQ
BSF FLAG_FREQ,DELAY_4MS ;SET 4MS DELAY FLAG
#IFNDEF RAMP
GOTO POPUP
#ELSE
BTFSS FLAG_FREQ,CHANGE_FREQ ;IS CHANGE IN FREQ REQUIRED?
GOTO POPUP ;NO - RETURN TO MAIN ROUTINE

BTFSC FLAG_FREQ,DEC_ACC_F ;IS DECELEARTION REQUIRED?
GOTO ACC_FREQ ;NO - ACCELERATION IS REQUIRED

DEC_FREQ
BANKSEL TEMP_COUNTER_LSB
DECFSZ TEMP_COUNTER_LSB,F ;IS DEC_COUNTER_LSB ZERO AFTER DECREMENT?
GOTO POPUP ;NO - COME OUT OF INTERRUPT

BANKSEL TEMP_COUNTER_MSB
MOVF TEMP_COUNTER_MSB,F
BTFSS STATUS,Z ;IS DEC_COUNTER_MSB ZERO?
GOTO DECREASE_TEMP_DEC_COUNTER_MSB ;NO

DECF SET_FREQ,F ;DECREASE SET_FREQ COUNT BY 1

BANKSEL DEC_COUNTER_LSB ;RELOAD DEC_COUNTER TO TEMP_COUNTER
MOVF DEC_COUNTER_LSB,W
BANKSEL TEMP_COUNTER_LSB
MOVWF TEMP_COUNTER_LSB

BANKSEL DEC_COUNTER_MSB
MOVF DEC_COUNTER_MSB,W
BANKSEL TEMP_COUNTER_MSB
MOVWF TEMP_COUNTER_MSB

GOTO POPUP

DECREASE_TEMP_DEC_COUNTER_MSB
DECF TEMP_COUNTER_MSB,F ;DECREASE DEC_COUNTER_MSB BY 1
GOTO POPUP

ACC_FREQ
BANKSEL TEMP_COUNTER_LSB
DECFSZ TEMP_COUNTER_LSB,F ;IS ACC_COUNTER_LSB ZERO AFTER DECREMENT?
GOTO POPUP ;NO - COME OUT OF INTERRUPT

BANKSEL TEMP_COUNTER_MSB
MOVF TEMP_COUNTER_MSB,F
BTFSS STATUS,Z ;IS ACC_COUNTER_MSB ZERO?
GOTO DECREASE_TEMP_ACC_COUNTER_MSB ;NO

INCF SET_FREQ,F ;INCREASE SET_FREQ COUNT BY 1

BANKSEL ACC_COUNTER_LSB ;RELOAD ACC_COUNTER TO TEMP_COUNTER
MOVF ACC_COUNTER_LSB,W
BANKSEL TEMP_COUNTER_LSB
MOVWF TEMP_COUNTER_LSB

BANKSEL ACC_COUNTER_MSB
MOVF ACC_COUNTER_MSB,W
BANKSEL TEMP_COUNTER_MSB
MOVWF TEMP_COUNTER_MSB

GOTO POPUP

DECREASE_TEMP_ACC_COUNTER_MSB
DECF TEMP_COUNTER_MSB,F ;DECREASE ACC_COUNTER_MSB BY 1
GOTO POPUP
#ENDIF
;*************************************************************************
;THIS ROUTINE WILL UPDATE THE PWM DUTY CYCLE ON CCPX ACCORDING TO THE
;OFFSET TO THE TABLE WITH 0-120-240 DEGREES.
;THIS ROUTINE SCALES THE PWM VALUE FROM THE TABLE BASED ON THE FREQUENCY TO KEEP V/F
;CONSTANT AND LOADS THEM IN APPROPRIATE CCPX REGISTER DEPENDING ON SETTING OF FWD/REV FLAG
;*************************************************************************
UPDATE_PWM_DUTYCYCLES
MOVLW LOW(SINE_TABLE_RAM)
MOVWF FSR ;BASE ADDRESS OF SINE TABLE IN RAM IS LOADED TO FSR
BANKSEL TABLE_OFFSET1
MOVF TABLE_OFFSET1,W ;TABLE_OFFSET1 IS COPIED TO WREG
ADDWF FSR,F ;ADRESS TO BE READ=SINE TABLE BASE ADRESS + TABLE_OFFSET1
BANKISEL SINE_TABLE_RAM
MOVF INDF,W ;COPY SINE TABLE VALUE, POINTED BY FSR, TO WREG
BTFSC STATUS,Z ;CHECK IS VALUE READ ZERO?
GOTO PWM1_IS_0 ;YES, GOTO PWM1_IS_0
MOVWF NO_1_LSB ;NO, SINE TABEL VALUE X SET_FREQ TO SCALE TABLE VALUE BASED ON FREQUENCY SETTING
CALL MUL_8X8 ;CALL ROUTINE FOR UNSIGNED 8x8 BIT MULTIPLICATION
MOVF RESULT_MSB,W ;8 MSB OF 16 BIT RESULT IS STORED
MOVWF TEMP_LOC ;AT TEMP_LOC - THIS REPRESENT PWM DUTY CYCLE VALUE FOR PHASE 1
GOTO UPDATE_PWM2 ;GO FOR UPDATING PWM DUTY CYCLE FOR 2ND PHASE
PWM1_IS_0
CLRF TEMP_LOC ;CLEAR PWM DUTY CYCLE VALUE FOR PHASE 1

UPDATE_PWM2
MOVLW LOW(SINE_TABLE_RAM)
MOVWF FSR ;BASE ADDRESS OF SINE TABLE IN RAM IS LOADED TO FSR
BANKSEL TABLE_OFFSET2
MOVF TABLE_OFFSET2,W ;TABLE_OFFSET2 IS COPIED TO WREG
ADDWF FSR,F ;ADRESS TO BE READ=SINE TABLE BASE ADRESS + TABLE_OFFSET2
BANKISEL SINE_TABLE_RAM
MOVF INDF,W ;COPY SINE TABLE VALUE, POINTED BY FSR, TO WREG
BTFSC STATUS,Z ;CHECK IS VALUE READ ZERO?
GOTO PWM2_IS_0 ;YES, GOTO PWM2_IS_0
MOVWF NO_1_LSB ;NO, SINE TABEL VALUE X SET_FREQ TO SCALE TABLE VALUE BASED ON FREQUENCY SETTING
CALL MUL_8X8 ;CALL ROUTINE FOR UNSIGNED 8x8 BIT MULTIPLICATION
MOVF RESULT_MSB,W ;8 MSB OF 16 BIT RESULT IS STORED
MOVWF TEMP_LOC_1 ;AT TEMP_LOC_1 - THIS REPRESENT PWM DUTY CYCLE VALUE FOR PHASE 2
GOTO UPDATE_PWM3 ;GO FOR UPDATING PWM DUTY CYCLE FOR 3RD PHASE

PWM2_IS_0
CLRF TEMP_LOC_1 ;CLEAR PWM DUTY CYCLE VALUE FOR PHASE 2

UPDATE_PWM3
MOVLW LOW(SINE_TABLE_RAM)
MOVWF FSR ;BASE ADDRESS OF SINE TABLE IN RAM IS LOADED TO FSR
BANKSEL TABLE_OFFSET3
MOVF TABLE_OFFSET3,W ;TABLE_OFFSET3 IS COPIED TO WREG
ADDWF FSR,F ;ADRESS TO BE READ=SINE TABLE BASE ADRESS + TABLE_OFFSET3
BANKISEL SINE_TABLE_RAM
MOVF INDF,W ;COPY SINE TABLE VALUE, POINTED BY FSR, TO WREG
BTFSC STATUS,Z ;CHECK IS VALUE READ ZERO?
GOTO PWM3_IS_0 ;YES, GOTO PWM3_IS_0
MOVWF NO_1_LSB ;NO, SINE TABEL VALUE X SET_FREQ TO SCALE TABLE VALUE BASED ON FREQUENCY SETTING
CALL MUL_8X8 ;CALL ROUTINE FOR UNSIGNED 8x8 BIT MULTIPLICATION
MOVF RESULT_MSB,W ;8 MSB OF 16 BIT RESULT IS STORED
MOVWF TEMP_LOC_2 ;AT TEMP_LOC_2 - THIS REPRESENT PWM DUTY CYCLE VALUE FOR PHASE 3
GOTO SET_PWM12 ;GO FOR CHECKING DIRECTION OF MOTOR ROTATION REEQUIRED

PWM3_IS_0
CLRF TEMP_LOC_2 ;CLEAR PWM DUTY CYCLE VALUE FOR PHASE 3

SET_PWM12
BANKSEL CCPR1L
BTFSS FLAGS,MOTOR_DIRECTION ;IS MOTOR_DIRECTION FLAG SET FOR FORWARD ROTATION?
GOTO ROTATE_REVERSE ;NO - GO FOR REVERSE ROTATION
MOVF TEMP_LOC,W
MOVWF CCPR1L ;COPY TEMP_LOC AND TEMP_LOC_1 VALUES TO
MOVF TEMP_LOC_1,W ;CCPR1L AND CCPR2L RESPECTIVELY FOR
MOVWF CCPR2L ;FOR FORWARD ROTATION OF MOTOR
BSF STATUS,RP0
MOVF TEMP_LOC_2,W
MOVWF CCPR3L ;COPY TEMP_LOC_2 TO CCPR3L
BCF STATUS,RP0
BSF LED_PORT,FWD_REV_LED ;TURN ON FWD_REV_LED TO INDICATE FORWARD ROTATION OF MOTOR
RETURN

ROTATE_REVERSE
MOVF TEMP_LOC_1,W ;COPY TEMP_LOC_1 AND TEMP_LOC VALUES TO
MOVWF CCPR1L ;CCPR1L AND CCPR2L RESPECTIVELY FOR
MOVF TEMP_LOC,W ;FOR REVERSE ROTATION OF MOTOR
MOVWF CCPR2L
BSF STATUS,RP0
MOVF TEMP_LOC_2,W
MOVWF CCPR3L ;COPY TEMP_LOC_2 TO CCPR3L
BCF STATUS,RP0
BCF LED_PORT,FWD_REV_LED ;TURN OFF FWD_REV_LED TO INDICATE REVERSE ROTATION OF MOTOR
RETURN

;*******************************************************************************
;THIS ROUTINE UPDATES THE OFFSET POINTERS TO THE TABLE AFTER EVERY ACCESS
;*******************************************************************************
UPDATE_TABLE_OFFSET
BANKSEL TABLE_OFFSET1
BTFSS FLAGS,OFFSET1_FLAG ;IF SET INCR. ON TABLE
GOTO DECREMENT_OFFSET1
MOVLW (SINE_TABLE_ENTRIES-1) ;CHECK FOR THE LAST VALUE ON THE TABLE
SUBWF TABLE_OFFSET1,W
BTFSC STATUS,C
GOTO CLEAR_OFFSET1_FLAG
INCF TABLE_OFFSET1,F ;INCREMENT OFFSET1
GOTO UPDATE_OFFSET2
CLEAR_OFFSET1_FLAG
BCF FLAGS,OFFSET1_FLAG
DECREMENT_OFFSET1
DECFSZ TABLE_OFFSET1,F ;DECREMENT OFFSET1
GOTO UPDATE_OFFSET2
BSF FLAGS,OFFSET1_FLAG

UPDATE_OFFSET2
BANKSEL TABLE_OFFSET2
BTFSS FLAGS,OFFSET2_FLAG ;IF SET INCR. ON TABLE
GOTO DECREMENT_OFFSET2
MOVLW (SINE_TABLE_ENTRIES-1) ;CHECK FOR THE LAST VALUE ON THE TABLE
SUBWF TABLE_OFFSET2,W
BTFSC STATUS,C
GOTO CLEAR_OFFSET2_FLAG
INCF TABLE_OFFSET2,F ;INCREMENT OFFSET2
GOTO UPDATE_OFFSET3
CLEAR_OFFSET2_FLAG
BCF FLAGS,OFFSET2_FLAG
DECREMENT_OFFSET2
DECFSZ TABLE_OFFSET2,F ;DECREMENT OFFSET2
GOTO UPDATE_OFFSET3
BSF FLAGS,OFFSET2_FLAG

UPDATE_OFFSET3
BANKSEL TABLE_OFFSET3
BTFSS FLAGS,OFFSET3_FLAG ;IF SET INCR. ON TABLE
GOTO DECREMENT_OFFSET3
MOVLW (SINE_TABLE_ENTRIES-1) ;CHECK FOR THE LAST VALUE ON THE TABLE
SUBWF TABLE_OFFSET3,W
BTFSC STATUS,C
GOTO CLEAR_OFFSET3_FLAG
INCF TABLE_OFFSET3,F ;INCREMENT OFFSET3
RETURN
CLEAR_OFFSET3_FLAG
BCF FLAGS,OFFSET3_FLAG
DECREMENT_OFFSET3
DECFSZ TABLE_OFFSET3,F ;DECREMENT OFFSET3
RETURN
BSF FLAGS,OFFSET3_FLAG
RETURN

;*******************************************************************************
;THIS ROUTINE CHECKS FOR THE KEYS STATUS. 2 KEYS ARE CHECKED, RUN/STOP AND
;FORWARD(FWD)/REVERSE(REV)
;*******************************************************************************
KEY_CHECK
BANKSEL PORTB
BTFSS PORTB,RUN_STOP_KEY ;IS RUN_STOP_KEY PRESSED?
GOTO RUN_STOP_KEY_PRESSED ;YES
BTFSC FLAGS,MOTOR_RUNNING ;IS MOTOR RUNNING?
GOTO FWD_REV_CHECK ;YES
RETURN

RUN_STOP_KEY_PRESSED
BTFSS FLAGS,MOTOR_RUNNING ;IS MOTOR ALREADY RUNNING?
GOTO RUN_MOTOR ;MO

CALL STOP_MOTOR ;STOP MOTOR
BANKSEL LED_PORT
BCF LED_PORT,RUN_STOP_LED
BCF FLAGS,MOTOR_RUNNING ;CLEAR FLAG TO INDICATE THE SAME
WAIT_1
BTFSS PORTB,RUN_STOP_KEY ;INFINITE LOOP TILL THE TIME PRESSED SWITCH IS RELEASED
GOTO WAIT_1
RETURN

RUN_MOTOR
CALL RUN_MOTOR_AGAIN
BANKSEL LED_PORT
BSF LED_PORT,RUN_STOP_LED
BSF FLAGS,MOTOR_RUNNING
WAIT_2
BTFSS PORTB,RUN_STOP_KEY ;INFINITE LOOP TILL THE TIME PRESSED SWITCH IS RELEASED
GOTO WAIT_2

FWD_REV_CHECK
BANKSEL PORTB
BTFSC PORTB,FWD_REV_KEY ;FWD/REV KEY PRESSED?
RETURN ;NO
CALL STOP_MOTOR

MOVLW 0X64 ;ADJUST THIS PARAMETER TO SET TIME BETWEEN CHANGE OF DIRECTION OF ROTOATION OF MOTOR
MOVWF TEMP_LOC_2
WAIT_FOR_MOTOR_TO_STOP
CALL DELAY
DECFSZ TEMP_LOC_2,F
GOTO WAIT_FOR_MOTOR_TO_STOP

CALL RUN_MOTOR_AGAIN
BANKSEL PORTB
MOVF FLAGS,W
ANDLW 0X01
BTFSS STATUS,Z
GOTO SET_REV_DIRECTION

SET_FWD_DIRECTION
BSF FLAGS,MOTOR_DIRECTION
WAIT_3
BTFSS PORTB,FWD_REV_KEY ;INFINITE LOOP TILL THE TIME PRESSED SWITCH IS RELEASED
GOTO WAIT_3
RETURN

SET_REV_DIRECTION
BCF FLAGS,MOTOR_DIRECTION
WAIT_4
BTFSS PORTB,FWD_REV_KEY ;INFINITE LOOP TILL THE TIME PRESSED SWITCH IS RELEASED
GOTO WAIT_4
RETURN

;*******************************************************************************
;THIS ROUTINE STOPS THE MOTOR BY DRIVING THE PWMS TO 0% DUTY CYCLE. ALSO DISABLE
;SELECT INTERRUPT TO MAINTAIN STOP CONDITION OF MOTOR
;*******************************************************************************
STOP_MOTOR
BANKSEL PIE1
BCF PIE1,TMR1IE
BCF PIE1,TMR2IE
BCF PIE1,ADIE
BCF FLAGS,TIMER1_OV_FLAG
CLRF CCPR3L
BCF STATUS,RP0
BCF PORTA,DRIVER_ENABLE
CLRF CCPR1L
CLRF CCPR2L
BANKSEL TABLE_OFFSET1
CLRF TABLE_OFFSET1
BANKSEL TABLE_OFFSET2
CLRF TABLE_OFFSET2
BANKSEL TABLE_OFFSET3
CLRF TABLE_OFFSET3
MOVLW 0X14
MOVWF SET_FREQ ;RESET MOTO FREQUENCY TO 5Hz
BANKSEL NEW_FREQ
MOVWF NEW_FREQ
BANKSEL TEMP_FREQ
MOVWF TEMP_FREQ
RETURN
;*******************************************************************************
;THIS ROUTINE STARTS MOTOR FROM PREVIOUS STOP WITH MOTOR PARAMETERS INITIALIZED
;*******************************************************************************
RUN_MOTOR_AGAIN
CALL INIT_MOTOR_PARAMETERS
BANKSEL PIE1
BSF PIE1,TMR1IE
BSF PIE1,ADIE
BSF PIE1,TMR2IE
BANKSEL TMR2_INT_COUNT
MOVLW 0X50
MOVWF TMR2_INT_COUNT
RETURN

;*******************************************************************************
;THIS ROUTINE INITIALIZES THE PARAMETERS REQUIRED FOR MOTOR INITIALIZATION.
;*******************************************************************************

INIT_MOTOR_PARAMETERS
BANKSEL TABLE_OFFSET1
MOVLW 0X09 ;INITIALIZE THE TABLE OFFSETS TO 3 REGISTERS
MOVWF TABLE_OFFSET1 ;SUCH THAT THEY HAVE 120 DEG. PHASE SHIFT WITH EACH OTHER

BANKSEL TABLE_OFFSET2
MOVLW 0X03
MOVWF TABLE_OFFSET2

BANKSEL TABLE_OFFSET3
MOVLW 0X0F
MOVWF TABLE_OFFSET3

BSF FLAGS,OFFSET1_FLAG ;OFFSET FLAGS INITIALIZATION
BCF FLAGS,OFFSET2_FLAG
BCF FLAGS,OFFSET3_FLAG

BANKSEL TMR1H
MOVLW 0XF9 ;TIMER1 INITIALISATION
MOVWF FREQ_REF_H
MOVWF TMR1H
MOVLW 0X37
MOVWF TMR1L
MOVWF FREQ_REF_L
MOVLW 0XB1
MOVWF TMR0
BSF FLAGS,TIMER1_OV_FLAG
BSF PORTA,DRIVER_ENABLE
RETURN

;*******************************************************************************
;ROUTINE FOR 8*8 BIT MULTIPLICAION
;*******************************************************************************
MUL_8X8
CLRF RESULT_MSB
CLRF RESULT_LSB
MOVF SET_FREQ,W ;MOVE THE MULTIPLICAND TO W REG.
BCF STATUS,C ;CLEAR THE CARRY BIT IN THE STATUS REG.
MULT 0
MULT 1
MULT 2
MULT 3
MULT 4
MULT 5
MULT 6
MULT 7
RETLW 0

;*******************************************************************************
;UPON INITIALIZATION THE SINE TABLE CONTENTS ARE COPIED TO THE RAM FROM
;PROGRAM MEMORY
;*******************************************************************************
COPY_TABLE_TO_RAM
BANKSEL SINE_TABLE_RAM
BANKISEL SINE_TABLE_RAM
MOVLW LOW(SINE_TABLE_RAM)
MOVWF FSR
MOVLW 0X13
MOVWF TEMP_LOC
CLRF TEMP_LOC_1
COPY_AGAIN
MOVLW HIGH(SINE_TABLE)
MOVWF PCLATH
MOVF TEMP_LOC_1,W
CALL SINE_TABLE
MOVWF INDF
INCF TEMP_LOC_1,F
INCF FSR,F
DECFSZ TEMP_LOC,F
GOTO COPY_AGAIN

MOVLW LOW(SINE_TABLE_RAM) ;FSR POINTS TO THE STARTING OF THE TABLE
MOVWF FSR
RETURN

;*******************************************************************************
;GENERAL PURPOSE DELAY ROUTINE - PRESENT DELAY TIME ~38msec
;*******************************************************************************
DELAY
MOVLW DELAY_COUNT1
MOVWF TEMP_LOC
DEC_TEMP_LOC
MOVLW DELAY_COUNT2
MOVWF TEMP_LOC_1
DEC_TEMP_LOC_1
DECFSZ TEMP_LOC_1,F
GOTO DEC_TEMP_LOC_1
DECFSZ TEMP_LOC,F
GOTO DEC_TEMP_LOC
RETURN

;*******************************************************************************
;EQUATION USED FOR CALCULATION OF SINE TABLE ENTRIES = (SIN(ANGLE)+1)*FF/2
;ANGLES ARE FROM 270 DEG. TO 90 DEG. STEP SIZE = 10 DEG.
;*******************************************************************************
TABLE CODE 0X0005
SINE_TABLE
ADDWF PCL,F
RETLW 0X00
RETLW 0X01
RETLW 0X07
RETLW 0X11
RETLW 0X1D
RETLW 0X2D
RETLW 0X3F
RETLW 0X53
RETLW 0X69
RETLW 0X7F
RETLW 0X95
RETLW 0XAB
RETLW 0XBF
RETLW 0XD1
RETLW 0XE1
RETLW 0XED
RETLW 0XF7
RETLW 0XFD
RETLW 0XFF
;*******************************************************************************
;END OF FILE
;*******************************************************************************
END

No @ No
ارجو منكم في اسرع وقت ممكن

مع جزيل الشكر
الرجوع الى أعلى الصفحة اذهب الى الأسفل
معاينة صفحة البيانات الشخصي للعضو
 
اريد المساعده في تحويل هذا البرنامج من .asmbالى .c
استعرض الموضوع السابق استعرض الموضوع التالي الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
منتدى التحكم الآلي والإلكترونيات :: منتديات التحكم الآلي والإلكترونيات :: منتدى الميكروكنترولر Micro Controller-
انتقل الى: