Wednesday, July 20, 2005

DCmotor & its Velocity Controled by Pot dialing


'set pot into AN0'
OSC=Oscirator 4mhz
' It's not necessary but recommended
DEFINE OSC 4
start:
'This is Analog definifition
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

ADCvar VAR word
' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
' this means switch

input portb.0
' This means information for motor rotation.
output portd.0
output portd.1
'how to know where pot is
output portb.7
main:
ADCIN 0, ADCvar
' Read channel 0 to adval
' serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)
ADCVar = ( ADCvar / 17)
'loop
'If the switch is off
'if ADCVar <= 125 then

high portb.7
'make pin 2 high
'These mean for motor
high portd.1
'make pin 1 low
low portd.0
'PWM comment ---duty of square wave , cycle of square wave of frequency
pwm portd.2,ADCVar,100
'else
'low portb.7
'make pin 2 high
'These mean motor stops
'low portd.1
'make pin 1 low
'low portd.0
'endif

'end loop
GoTo main

0 Comments:

Post a Comment

<< Home