border
topbkg
americanflag2_z
Orders
Email Us
Contact Info
Return Policy
mc ivsa

Diverse Electronic Services

Home

Motor Controllers

Battery Chargers

Interface Circuits

Radio Controlled Devices

My Robot Page

'-----------------------------pwm1mc7.f84-----------------------------

' written by Carl A. Kollar

'Purpose: To demonstrate the control by 16F84 of the MC7 motor

' controller described on this web site. 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-------------------------

DEFINE OSC 4

enable_port con 0: low enable_port 'disable MC7 while initializing

pwm_out_port con 1

fwd_port con 2

rev_port con 3

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 = 25

'------------------------Initialize----------------------------------------

low fwd_port 'Put MC7 in "neutral" by making both direction ports low

low rev_port

high enable_port 'enable the 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

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_port,x,cycles

pause pause_time 'wait specified time

next x

for x = 1 to max_speed_time 'stay at max. speed for awhile

pwm pwm_out_port,max_speed,cycles

next x

return

'-------------------------------------------------------------------------

'Bring motor speed gradually to a stop from full speed

max_to_min:

for x = max_speed to min_speed step -1 'gradually decrease speed

pwm pwm_out_port,x,cycles

pause pause_time 'wait specified time

next x

return

'------------------------------------------------------------------------

set_forward_direction:

low rev_port 'reverse not enabled

high fwd_port 'enable forward

return

'-------------------------------------------------------------------------

set_reverse_direction:

low fwd_port 'forward not enabled

high rev_port 'enable reverse

return

Download this sample 16F84 program in PicBasic, assembler, hex & machine language.

Home

Motor Controllers

Battery Chargers

Interface Circuits

Radio Controlled Devices

My Robot Page