Monday, July 11, 2005

Servo Motor Pulse-Width var, POT



'set servoMotor into RC3
'set pot into AN0

' OSC=Oscirator 4mhz
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
'ADCvar VAR byte
'ADCvar VAR byte
'ADCvar VAR byte

' Create variable to store result
TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result
pulseWidth var byte
' set up constants with the minimum and maximum pulsewidths
'constant
minPulse CON 50
'minPulse CON 50
'minPulse CON 0
'minPulse CON 50

maxPulse CON 250
'maxPulse CON 250
'maxPulse CON 255
'maxPulse CON 250


' set up a constant with the time between pulses:
refreshPeriod CON 20

' set an initial pulsewidth:
pulseWidth = minPulse

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 / 4 )
'ADCVar = ADCvar + 50

'------ (nothing about ADCVar definition)

'------ (nothing about ADCVar definition)


'take the output pin low so we can pulse it high
Low PORTC.3
' pulse the pin
PulsOut PORTC.3, ADCVAr
' pause for as long as needed:
Pause refreshPeriod
' change the angle for the next time around:
' IF pulseWidth > maxPulse Then
' pulseWidth = minPulse
' Else
' pulseWidth = pulseWidth + 1
' Endif
GoTo main

0 Comments:

Post a Comment

<< Home