שלום מישהו בבקשה יכול לעזור לי להבין איך אני שולח מהבקר pwm ?
אם תוכלו להביא בבקשה תוכנות לדוגמא...חיפשתי בגוגל ולא מצאתי.
עוד בעיה...
הבקר יכול לשלוח שני pwm ולרובוט יש 3 גלגלים
יש דרך לעקוף את זה?
title "Lab 4 - Question 4;------------------------------\
; This program creates 15.625Khz rectangular pulse with changing
; Duty cycle using PWM- output to PORTC<RC2>.
; INT0 increse the duty cycle by 10%
; When duty cycle reaches 100% it goes back to 10%.
;
list p=18f452
#include p18f452.inc
;
;Program Configuration Registers
;
CONFIG OSCS=ON, OSC=HS ;Oscillator switch enabled; OSC2/RA6 pin - Open
CONFIG BOR=OFF, WDT=OFF ;Brown-OutReset disabled; Watch Dog Timer disabled
CONFIG PWRT=ON, LVP=OFF ;PoWer up Timer enabled; Low Voltage ICSP
;
variables UDATA
; - - - - - - - - -
Sig_Period res 1
DC_1 res 1
DC_BASE res 1
tmp res 1
counter res 1
counter1 res 1
counter2 res 1
;
STARTUP CODE
; - - - - - - - - - - - -
org 0x00 ; reset vector
bra Start
org 0x08 ;high prioriy vector
bra HIGH_PRIORITY
;
CODE
; - - - - - - - - - - - -
Start
bcf INTCON,GIE ;disabling interrupts till preparations are complete
;----------------Initializing I/O--------------------------;
bcf RCON,IPEN ;1 level of interrupts
bcf TRISC,CCP1 ;set as output
bcf PORTC,CCP1 ;clearing PORTC<RC2>
bsf TRISB,INT0 ;set as input for interrupt INT0
bcf PORTB,INT0 ;clearing PORTB<INT0>
;----------------Initializing interrupts--------------------;
bcf INTCON,INT0IF ;clearing INT0 flag
bsf INTCON,INT0IE ;enable INT0
bcf INTCON2,INTEDG0 ;setting edge of INT0
bsf INTCON,GIE ;enable global interrupts
;---------------General initializations---------------------;
movlw .63
movwf Sig_Period ;signal period = (Sig_Period+1)*4*Tosc*prescale -- Tosc=250nsec
movlw .26
movwf DC_1 ;Duty cycle = DC*Tosc*prescale
movwf DC_BASE ;DC_BASE=DC_1
movlw .1
movwf counter ;counts the precentage -- counter=1-->DC_1=10%
;--------------Initializing PWM & TMR2-----------------------;
bsf CCP1CON,CCP1M3 ;setting PWM mode CCP1CON=11xx
bsf CCP1CON,CCP1M2
clrf T2CON ;setting timer2 for 1:1 prescale 1:1 postscale and timer2-->off
;-----------Initializing PWM---------------------------------;
movff Sig_Period,PR2 ;entering signal time period
call Duty_Cycle ;assigning the duty cycle to be DC_1
bsf T2CON,TMR2ON ;starting timer2
bra $
;--------------HIGH_PRIORITY------------------------------------;
HIGH_PRIORITY
bcf INTCON,GIE ;disable global interrupts
incf counter ;counter+1-->counter
movlw .10 ;10-->WREG
cpfsgt counter ;skip if counter>10
bra Less_100 ;if counter is not 10
movlw .26
movwf DC_1 ;Duty cycle = DC_1*Tosc*prescale
movwf DC_BASE ;DC_BASE=DC_1
movlw .1
movwf counter ;counts the precentage -- counter=1-->DC_1=10%
call Duty_Cycle ;assigning the duty cycle to be DC_1
bra Finialization
;-----------------------------
Less_100
movlw .10 ;10-->WREG
cpfseq counter
bra NOT_EQUAL_100
;setting duty cylce 100%
bcf CCP1CON,4
bcf CCP1CON,5
clrf CCPR1L
bsf CCPR1L,6
bra Finialization
NOT_EQUAL_100
movf DC_BASE,0 ;DC_BASE-->WREG
addwf DC_1 ;DC_1=DC_1+DC_BASE
call Duty_Cycle ;assigning the duty cycle to be DC_1
;-----------------------------
Finialization
call Delay_20msec
bcf INTCON,INT0IF ;preparing for another INT0 interrupt
bsf INTCON,GIE ;enable global interrupts
retfie
;------------------------------------------------------;
Duty_Cycle
; The following function assigns the duty cycle in the right order
; 2 LSB go into CCP1CON<4,5> and 8 MSB go into CCPR1L
bcf CCP1CON,4
bcf CCP1CON,5
movff DC_1,tmp
btfsc tmp,0 ;checking bit 0
bsf CCP1CON,4 ;entering D.C. LSB<0>
btfsc tmp,1 ;checking bit 1
bsf CCP1CON,5 ;entering D.C. LSB<1>
bcf tmp,0 ;prepering for rotation
bcf tmp,1
rrncf tmp ;round shiftx2
rrncf tmp
movff tmp,CCPR1L ;entering D.C.MSB
return
;----------Delay_20msec- creating 19994usec delay------;
Delay_20msec ;formula: 2+(counter1*[(counter2*3)+5])
movlw .206
movwf counter1
loop_out_20
movlw .31
movwf counter2
loop_in_20
decfsz counter2
bra loop_in_20
decfsz counter1
bra loop_out_20
return
;------------------------------------------------------;
end
משתמשים הגולשים בפורום זה: Bing [Bot] ו 5 אורחים