Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/19/03 10:53
Read: times


 
#36784 - sample code
hi all

I had control some motors use Timer 0 interrupt.i found my progam can control some servos with a bit modify.
However this resolution is 0,1 ms
there is a bit difficult to understand.
we can change value of angle1 or angle2 in
main program to control servo rotate at new angle
You will find it useful to control motor
or servo.
*******************
servo1 equ p3.1
servo2 equ P3.2
angle1 data 30h
angle2 data 31h
org 0h
ljmp main
org 0bh
ljmp t0_isr
org 30h
main:
mov tmod,#2 ; t0 mode 2 auto reload
setb ea
setb et0
mov Th0,#-100
setb tr0
mov r0,#0
mov angle1,#10 (10*100us=1ms)
mov angle2,#20 (20*200us=2ms)
sjmp $
;---------------------
;this interrupt happens every 100us
t0_isr:
inc r0
cjne r0,#200,servo1_pwm ;(200*100us=20ms)
mov r0,#1
servo1_pwm:
mov a,angle1
cjne a,0h,$+3
cpl c
mov servo1,c
servo2_pwm:
mov a,angle2
cjne a,0h,$+3
cpl c
mov servo2,c
reti
end

List of 18 messages in thread
TopicAuthorDate
controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo / CCA <--> PCA ??            01/01/70 00:00      
RE: controlling servo / CCA <--> PCA ??            01/01/70 00:00      
RE: controlling servo / CCA <--> PCA ??            01/01/70 00:00      
RE: controlling servo / CCA <--> PCA ??            01/01/70 00:00      
RE: controlling servo / CCA <--> PCA ??            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo            01/01/70 00:00      
RE: controlling servo ! ops!!!            01/01/70 00:00      
RE: controlling servo - diagram here            01/01/70 00:00      
sample code            01/01/70 00:00      

Back to Subject List