Motor Controller MC7 PWM Need Help with code...
Bozook
Posts: 6
Hi all I am having trouble getting 1 motor to go ccw and 1 motor to go cw at the same time
Below is the code that I am using, it works fine otherwise. I have tried making·· high fwd_portleft· and·high rev_portright and the others low but it seems to lock up there.. Please any help would be appreciated.
'
pwm1mc7mtr.bs2px
'· written by Carl A. Kollar modified by FV
'Purpose:· control by BS2px of the MC7 motor Controller
·Can be used with
'·either 12 or 24 volt models.
'
'Motor action: The motor (1) Gradually increases in speed in the forward
'· direction until it reaches full speed. (2) Gradually
'· reduces speed until it stops. (3) Gradually increases speed
'· in the reverse direction until it reaches full rev. speed
'· (4) Gradually decreases speed until it comes to a stop.
'· (5) Does it all over again.
'
Define Constants & Variables
enable_portleft con 0: low enable_portleft 'disable MC7 while initializing
pwm_out_portleft con 1
fwd_portleft con 2
rev_portleft con 3
enable_portright con 4: low enable_portright 'disable MC7 while initializing
pwm_out_portright con 5
fwd_portright con 6
rev_portright con 7
duty var byte
cycles var byte: cycles = 10
min_speed var byte: min_speed = 52 'pwm value for 1.0V out
max_speed var byte: max_speed = 165 'pwm value for 3.2V out
x var byte: x = 0· 'counter variable
pause_time var word: pause_time = 15 'pause between counter increments
max_speed_time var byte: max_speed_time = 150
'
Initialize
low fwd_portleft 'Put MC7 in "neutral" by making both direction ports low
low rev_portleft
high enable_portleft 'enable the left controller
low fwd_portright 'Put MC7 in "neutral" by making both direction ports low
low rev_portright
high enable_portright 'enable the right controller
'
The Main Program
'· (All sub-routine names are self-explanatory)
main:
·gosub set_forward_direction
·gosub min_to_max
·gosub max_to_min
·gosub set_reverse_direction
·gosub min_to_max
·gosub max_to_min
·gosub set_right_direction
·gosub min_to_max
goto main
'***************************Sub-Routines**********************************
'Bring motor speed gradually from a stop to full speed
min_to_max:
·for x = min_speed to max_speed 'gradually increase speed
·pwm pwm_out_portleft,x,cycles
·pwm pwm_out_portright,x,cycles
·pause pause_time 'wait specified time
·next
·for x = 1 to max_speed_time 'stay at max. speed for awhile
·pwm pwm_out_portleft,max_speed,cycles
·pwm pwm_out_portright,max_speed,cycles
·next
·return
'
'Bring motor speed gradually to a stop from full speed
max_to_min:
·for x = max_speed to min_speed 'gradually decrease speed
·pwm pwm_out_portleft,x,cycles
·pwm pwm_out_portright,x,cycles
·pause pause_time 'wait specified time
·next
·return
'
set_forward_direction:
·high fwd_portleft 'enable forward
·high fwd_portright 'enable forward
·low rev_portleft 'reverse not enabled
·low rev_portright 'reverse not enabled
·return
'
set_reverse_direction:
·low fwd_portleft 'forward not enabled
·high rev_portleft 'enable reverse
·low fwd_portright 'forward not enabled
·high rev_portright 'enable reverse
·return
'
set_right_direction:
high·fwd_portleft 'Left motor forward· enabled
low·rev_portleft ' left motor reverse not enabled
low fwd_portright 'Right motor forward not enabled
high rev_portright 'right motor enable reverse
·return
Post Edited (Bozook) : 12/15/2005 12:57:07 PM GMT
Below is the code that I am using, it works fine otherwise. I have tried making·· high fwd_portleft· and·high rev_portright and the others low but it seems to lock up there.. Please any help would be appreciated.
'
pwm1mc7mtr.bs2px
'· written by Carl A. Kollar modified by FV
'Purpose:· control by BS2px of the MC7 motor Controller
·Can be used with
'·either 12 or 24 volt models.
'
'Motor action: The motor (1) Gradually increases in speed in the forward
'· direction until it reaches full speed. (2) Gradually
'· reduces speed until it stops. (3) Gradually increases speed
'· in the reverse direction until it reaches full rev. speed
'· (4) Gradually decreases speed until it comes to a stop.
'· (5) Does it all over again.
'
Define Constants & Variables
enable_portleft con 0: low enable_portleft 'disable MC7 while initializing
pwm_out_portleft con 1
fwd_portleft con 2
rev_portleft con 3
enable_portright con 4: low enable_portright 'disable MC7 while initializing
pwm_out_portright con 5
fwd_portright con 6
rev_portright con 7
duty var byte
cycles var byte: cycles = 10
min_speed var byte: min_speed = 52 'pwm value for 1.0V out
max_speed var byte: max_speed = 165 'pwm value for 3.2V out
x var byte: x = 0· 'counter variable
pause_time var word: pause_time = 15 'pause between counter increments
max_speed_time var byte: max_speed_time = 150
'
Initialize
low fwd_portleft 'Put MC7 in "neutral" by making both direction ports low
low rev_portleft
high enable_portleft 'enable the left controller
low fwd_portright 'Put MC7 in "neutral" by making both direction ports low
low rev_portright
high enable_portright 'enable the right controller
'
The Main Program
'· (All sub-routine names are self-explanatory)
main:
·gosub set_forward_direction
·gosub min_to_max
·gosub max_to_min
·gosub set_reverse_direction
·gosub min_to_max
·gosub max_to_min
·gosub set_right_direction
·gosub min_to_max
goto main
'***************************Sub-Routines**********************************
'Bring motor speed gradually from a stop to full speed
min_to_max:
·for x = min_speed to max_speed 'gradually increase speed
·pwm pwm_out_portleft,x,cycles
·pwm pwm_out_portright,x,cycles
·pause pause_time 'wait specified time
·next
·for x = 1 to max_speed_time 'stay at max. speed for awhile
·pwm pwm_out_portleft,max_speed,cycles
·pwm pwm_out_portright,max_speed,cycles
·next
·return
'
'Bring motor speed gradually to a stop from full speed
max_to_min:
·for x = max_speed to min_speed 'gradually decrease speed
·pwm pwm_out_portleft,x,cycles
·pwm pwm_out_portright,x,cycles
·pause pause_time 'wait specified time
·next
·return
'
set_forward_direction:
·high fwd_portleft 'enable forward
·high fwd_portright 'enable forward
·low rev_portleft 'reverse not enabled
·low rev_portright 'reverse not enabled
·return
'
set_reverse_direction:
·low fwd_portleft 'forward not enabled
·high rev_portleft 'enable reverse
·low fwd_portright 'forward not enabled
·high rev_portright 'enable reverse
·return
'
set_right_direction:
high·fwd_portleft 'Left motor forward· enabled
low·rev_portleft ' left motor reverse not enabled
low fwd_portright 'Right motor forward not enabled
high rev_portright 'right motor enable reverse
·return
Post Edited (Bozook) : 12/15/2005 12:57:07 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Post Edited (Tom Walker) : 12/13/2005 7:17:22 PM GMT
JJ
Post Edited (Bozook) : 12/14/2005 12:40:37 AM GMT
http://bozooka.markv.net/images/IMG_0320.JPG
and the·schematic NOTE! The schematic only shows one controller
http://bozooka.markv.net/images/mc7schematic.gif
Post Edited (Bozook) : 12/14/2005 1:55:29 AM GMT
Looking at the code for your set_left_direction should look something like this.
set_left_direction:
' Set left motor MC7 to reverse
low fwd_portleft 'forward not enabled
high rev_portleft 'enable reverse
' Set right motor MC7 to forward
high fwd_portright 'enable forward
low rev_portright 'reverse not enabled
return
If you set high rev_portleft and high fwd_portright should make it turn to the left. Your code posted above looks like it would turn to the right.
When it reaches the set_left_direction sub, what does it do?
When it gets to that gosub it stops or freez's and don't do noting. Thats my problem. I have changed the ports around and all and it just freez's at that point.
kelvin
Post Edited (Bozook) : 12/15/2005 1:10:34 PM GMT
kelvin